setTimeout("fadeBackground()",100);

function fadeBackground() {
	$("#background").fadeIn("slow", function() {
		revealPageWrapper();
	});
}

function revealPageWrapper() {
	$("div#wrapper").slideDown("slow", function() {
		$("#headline").fadeIn(1500, function() {
			setTimeout("revealPage()",2000);
		});
	});
}

function revealPage() {
			$("#headline_blurb").fadeIn("slow", function() {
				$("#video_wrapper").css({'background':'#000000'});
				$("#video_wrapper").slideDown(4000, function() {
					$("#banner").fadeOut("slow", function() {
						//var flashvars = {}; 
						//var params = {bgcolor:"#000000"}; 
						//var attributes = {}; 
						//swfobject.embedSWF("video/promo_v3.swf", "video_wrapper", "589", "331", "9.0.0", "video/expressInstall.swf", flashvars, params, attributes);
						loadVideo();
					});
				});
				$("#links").fadeIn("slow");
				$("#col1").slideDown("slow", function() {
					$("#col2").slideDown("slow", function() {
						$("#col3").slideDown("slow", function() {
							$("#footer").fadeIn("slow");
							$("#san_diego").fadeIn("slow");
						});
					});
				});
			});	
}

function loadVideo() {
	$("#video_wrapper").load("video.asp");
}

function auditionSignup() {

		function verify(data) {
				if (data=="1") {
					var msg = "<h2>Thank you!</h2>We've received your audition signup request, and will contact you shortly to confirm.";
					$("div#audition_signup_form").slideUp("slow", function() {
						$("div#audition_signup_form").html(msg);
						$("div#audition_signup_form").slideDown("slow", function() {
							animateContentWrapper();
						});
					});
				}
				else if (data=="2") {
					url('494');
				}
				else {
					// Error
					alert(data);
				}
		}

		$.post("process/audition_signup.asp", $("#frmAuditionSignup").serialize(), function(data){ verify(data) } );

}

function privateLessons() {

		function verify(data) {
				if (data=="1") {
					// success
					var msg = "<h2>Thank you!</h2>We've received your request for information about private teachers, and will contact you shortly!";
					$("div#audition_signup_form").slideUp("slow", function() {
						$("div#audition_signup_form").html(msg);
						$("div#audition_signup_form").slideDown("slow", function() {
							animateContentWrapper();
						});
					});
				}
				else if (data=="2") {
					// haven't auditioned before
					alert ("We're sorry, unfortunately we only provide information about private teachers to students who have auditioned for PYO.");
				}
				else {
					// Error
					alert(data);
				}
		}

		$.post("process/private_lessons.asp", $("#frmPrivateLessons").serialize(), function(data){ verify(data) } );

}

function sendMessage() {

		function verify(data) {
				if (data=="1") {
					// success
					var msg = "<h2>Thank you!</h2>We've received your message and will contact you shortly!";
					$("div#audition_signup_form").slideUp("slow", function() {
						$("div#audition_signup_form").html(msg);
						$("div#audition_signup_form").slideDown("slow", function() {
							animateContentWrapper();
						});
					});
				}
				else {
					// Error
					alert(data);
				}
		}

		$.post("process/send_message.asp", $("#frmContact").serialize(), function(data){ verify(data) } );

}

function url(id) {

				//scroll to top of page
				$('html, body').animate({scrollTop:0}, 'slow'); 

	//get current height of #content
	var h = $("#content").height();

	//set wrapper to h
	$("#content_wrapper").css({'height':h + 'px'});

	//fadeout current page
	$("#content").fadeOut("slow", function() {

		//load new page
		$("#content").load("page.asp?P=" + id, function() {

			//adjust content min-height
			$("#content").css({'min-height':$("#content_wrapper").css('min-height')});

			//fadein new page
			$("#content").fadeIn("slow", function() {

				//if wrapper is larger or smaller than content, adjust it
				animateContentWrapper();

			});
		});
	});

}

function animateContentWrapper() {

	var content_h = $("#content").height();
	var content_wrapper_h = $("#content_wrapper").height();

	if ( (content_h > content_wrapper_h) || (content_h < content_wrapper_h) ) {
		
		//animate wrapper height
		$("#content_wrapper").animate({
			height: content_h
		}, "slow");
	
	}

}

function faq(id) {

	$("div#answer" + id).slideToggle(300, function() {
		animateContentWrapper();		
	});

}
