//
// NZSS MOTION 1.0
// Animation controller for NZ Singing School website
// Written by Blain Hosford
// Copyright 2010, ZenWebware
// www.zenwebware.com
//
// Requires ZenMotion
//

var animation_finished = false;


function play_animation(segment) {
	switch(segment) {
		case "start":
			setTimeout("play_animation('shut_eyes')", 1500);
			break;
		case "shut_eyes":
			motion_hide_node("girls_eyes_open");
			motion_show_node("girls_eyes_shut");
			setTimeout("play_animation('open_eyes')", 100);
			break;
		case "open_eyes":
			motion_hide_node("girls_eyes_shut");
			motion_show_node("girls_eyes_open");
			setTimeout("play_animation('sing')", 1000);
			break;
		case "sing":
			var start_x = 80;
			var start_y = 162;
			var duration = 500;
			motion_hide_node("girls_eyes_open");
			motion_show_node("girls_eyes_shut");
			motion_hide_node("girls_mouth_shut");
			motion_show_node("girls_mouth_open");
			animate_header_element("top_note1", start_x, start_y, duration);
			animate_header_element("top_note2", start_x, start_y, duration);
			animate_header_element("top_note3", start_x, start_y, duration + 50);
			animate_header_element("top_note4", start_x, start_y, duration + 100);
			animate_header_element("top_note5", start_x, start_y, duration + 150);
			animate_header_element("top_note6", start_x, start_y, duration + 200);
			animate_header_element("top_note7", start_x, start_y, duration + 250);
			animate_header_element("speech_bubble", start_x, start_y, duration);
			animate_header_element("the_new_zealand_text", start_x, start_y, duration);
			animate_header_element("singing_school_text", start_x, start_y, duration);
			show_header_elements();
			shake_header_on(true);
			setTimeout("play_animation('end')", 2500);
			break;
		case "end":
			shake_header_off(true);
			animation_finished = true;
			break;
	}
}
				

function animate_header_element(id, start_x, start_y, duration) {
	var element = document.getElementById(id);					
	var target_x = parseInt(element.style.left);
	var target_y = parseInt(element.style.top);
	motion_set_node_position(id, start_x, start_y);
	motion_set_node_scale(id, 0, 0);
	motion_animate_node_position(id, target_x, target_y, duration);
	motion_animate_node_scale(id, 1, 1, duration);
}


function show_header_elements() {
	motion_show_node("top_note1");
	motion_show_node("top_note2");
	motion_show_node("top_note3");
	motion_show_node("top_note4");
	motion_show_node("top_note5");
	motion_show_node("top_note6");
	motion_show_node("top_note7");
	motion_show_node("speech_bubble");
	motion_show_node("the_new_zealand_text");
	motion_show_node("singing_school_text");
}


function shake_header_on(just_do_it) {
	var shake_amount = 2;
	if(animation_finished || just_do_it) {
		motion_set_node_shake("girls_face", 0, 1);
		motion_set_node_shake("girls_eyes_open", 0, 1);
		motion_set_node_shake("girls_eyes_shut", 0, 1);
		motion_set_node_shake("girls_mouth_open", 0, 1);
		motion_set_node_shake("top_note1", shake_amount, shake_amount);
		motion_set_node_shake("top_note2", shake_amount, shake_amount);
		motion_set_node_shake("top_note3", shake_amount, shake_amount);
		motion_set_node_shake("top_note4", shake_amount, shake_amount);
		motion_set_node_shake("top_note5", shake_amount, shake_amount);
		motion_set_node_shake("top_note6", shake_amount, shake_amount);
		motion_set_node_shake("top_note7", shake_amount, shake_amount);
		motion_set_node_shake("speech_bubble", shake_amount, shake_amount);
		motion_set_node_shake("the_new_zealand_text", shake_amount, shake_amount);
		motion_set_node_shake("singing_school_text", shake_amount, shake_amount);
	}
	if(animation_finished) {
		motion_hide_node("girls_eyes_shut");
		motion_show_node("girls_eyes_open");
	}
}


function shake_header_off(just_do_it) {
	if(animation_finished || just_do_it) {
		motion_set_node_shake("girls_face", 0, 0);
		motion_set_node_shake("girls_eyes_open", 0, 0);
		motion_set_node_shake("girls_eyes_shut", 0, 0);
		motion_set_node_shake("girls_mouth_open", 0, 0);
		motion_set_node_shake("top_note1", 0, 0);
		motion_set_node_shake("top_note2", 0, 0);
		motion_set_node_shake("top_note3", 0, 0);
		motion_set_node_shake("top_note4", 0, 0);
		motion_set_node_shake("top_note5", 0, 0);
		motion_set_node_shake("top_note6", 0, 0);
		motion_set_node_shake("top_note7", 0, 0);
		motion_set_node_shake("speech_bubble", 0, 0);
		motion_set_node_shake("the_new_zealand_text", 0, 0);
		motion_set_node_shake("singing_school_text", 0, 0);
	}
	if(animation_finished) {
		motion_hide_node("girls_eyes_open");
		motion_show_node("girls_eyes_shut");
	}
}
