$(document).ready(function() {

	// Superfish dropdown menu init
		  $('ul.sf-menu').superfish({
			delay:       1000,                            // delay on mouseout 
			animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
			autoArrows:  true,                           // disable generation of arrow mark-up 
			dropShadows: false,                            // disable drop shadows
			pathLevels: 2
		  });
	  


	// =======================================
	// Calculate which scene to display based on the time of day
	// - Beach image: 3pm to 7pm (b)
	// - Jazz image: 7pm to 5 am (c)
	// - Bird image: 5am to 10am (d)
	// - Duck image: 10am to 3pm (a) (forest?)
	// =======================================
	
	var splashScene	= "";
	var d			= new Date();
	var tod			= d.getHours();
	var setFlash	= true;
	
	if (tod >= 15 && tod < 19) {
		splashScene = "b";
	} else if ((tod>= 19 && tod < 23) || (tod >= 0 && tod < 5)) {
		splashScene = "c";
	} else if (tod >=5 && tod < 10) {
		splashScene = "d";
	} else {
		splashScene = "a";
	}
	
	if (splashScene != $.cookie('splashScene')) {
		$.cookie('splashScene', splashScene, { expires: 1, path: '/', domain: '', secure: false });
		setFlash = true;
	} else {
		setFlash = false;	
	}
	
	//splashScene = "a";				// test value
	$('body').attr("class", "");		//remove any current class(es)
	$('body').addClass(splashScene);	// set new class
	
	if (setFlash) {

		var flashvars = {};
		var params = {
			'allowscriptaccess': 'always',
			'wmode': 'transparent'
		};
		var attributes = {};
		splashScene = "/assets/flash/" + splashScene + "_header.swf";
		swfobject.embedSWF(splashScene, "flash", "818", "461", "9.0.0","", flashvars, params, attributes);
		$("#offer").fadeIn(12000);
		
	} else {
		
		$("#flash").remove();
		$("#splash").css({"height": "250px"});
		$("#offer").show();
	}



			  $("#contact-close").hide();
			  $("#contact-email").hide();
			  $("#contact-comment").hide();
			  $("#contact-btn").hide();
			  $("#contact-block-thanks").hide();

			  $("#contact-close").click(function () { 
			    $("#contact-close").fadeOut();
				$("#contact-email").slideUp();
				$("#contact-comment").slideUp();
				$("#contact-btn").fadeOut(); 
    		  });
		   
			$("#contact-form input").focus(function() {
				if($(this).val()==$(this).attr("title")) {
					clearMePrevious = $(this).val();
					$(this).val("");
				}
			    $("#contact-close").fadeIn();
				$("#contact-email").slideDown();
				$("#contact-comment").slideDown();
				$("#contact-btn").fadeIn();
				$(this).addClass("current_input");
			});
			
			$("#contact-form input").blur(function() {
				if($(this).val()=="") {
					$(this).val(clearMePrevious);
				}
				$(this).removeClass("current_input");
			});
			
			$("#contact-form textarea").focus(function() {
				if($(this).val()==$(this).attr("title")) {
					clearMePrevious = $(this).val();
					$(this).val("");
				}
				$(this).addClass("current_input");
			});
			
			$("#contact-form textarea").blur(function() {
				if($(this).val()=="") {
					$(this).val(clearMePrevious);
				}
				$(this).removeClass("current_input");
			});
			
			$("#contact-btn").click(function() {
				var send = true;
				
				if ($("#contact-name").val() == "" || $("#contact-name").val() == "Enter your name") {
					$("#contact-name").addClass("error");
					send = false;
				} else {
					$("#contact-name").removeClass("error");
				}
				
				if ($("#contact-email").val() == "" || $("#contact-email").val() == "Enter your email") {
					$("#contact-email").addClass("error");
					send = false;
				} else {
					$("#contact-email").removeClass("error");
				}
									
				if ($("#contact-comment").val() == "" || $("#contact-comment").val() == "Comment") {
					$("#contact-comment").addClass("error");
					send = false;
				} else {
					$("#contact-comment").removeClass("error");
				}

				if (send) {
					$.post("/assets/includes/contact.php", $("#contact-form").serialize(), 
						function(data) {
							$("#contact-block-inner").hide();
							$("#thanks-msg").html(data);
							$("#contact-block-thanks").fadeIn();
						},
						'html'
					);
				}
				
			});
		   
		   $("#send-another").click(function() {
		   		$("#contact-block-thanks").hide();
				$("#contact-comment").val("Comment");
				$("#contact-block-inner").fadeIn();
				return false;
		   });




});

function splashShrink() {
	$("#flash").remove();
	$("#splash").animate({
		height: 250
	}, 1000);
}

