$(function()
{	
	/*Wait - then animate sections in*/
	setTimeout(function(){
		$("#header h1, #slide-image, #thumbnails a.btn_prev, #thumbnails a.btn_next, #thumbnails #slide-sets").fadeIn(2000,function(){
			swfobject.embedSWF("assets/objects/dandelion_animation.swf", "dandelion", "552", "345", "7.0.0","",{},{wmode:"transparent"},{});
			setTimeout(function(){
				$("#content h1").fadeIn(2000,function(){
					$("#header ul, #content p").fadeIn(2000);				
				});	
			},5000);
			
		});
	},500);
		
	/*Set up click handlers for modal windows*/
	$("#header a.btn_heart-soul, #header a.btn_talk-to-us, #content a.modalLink").click(function(){
		$.get($(this).attr("href"),function(data){
			$("#footer").after(data);	
			$("div.modal").fadeIn("normal",addClickHandlers);
		});		
		return false;
	});
	
	$("a.credits").click(function(){
		$.get($(this).attr("href"),function(data){
			$("#thumbnails").after(data);	
			$("div.modal-small").fadeIn("normal",addClickHandlers);
		});		
		return false;
	});
	
	/*Set up click handler for thumbnail strip*/
	$("#slide-sets a").click(function()
	{
		index = $("#slide-sets a").index(this);
		$("#slide-image .slides").cycle("pause");
		$("#slide-image img").fadeOut(800);
		$("#slide-image img:eq(" + index + ")").animate({ opacity: 1 }, 0).fadeIn(800);
		return false;
	});
	
	/*Start image cycle in main photo area*/
	$("#slide-image .slides").cycle(
	{
		fx: "fade",
		speed: 1200
	});
	
	/*Set up horizontal scrolling for thumbnail strip*/
	$("#thumbnails #slide-sets").cycle(
	{
		fx: "scrollHorz",
		timeout: 0,
		next: $("#thumbnails a.btn_next"),
		prev: $("#thumbnails a.btn_prev")
	});
});

function addClickHandlers()
{
	$("div.modal a.btn_close, div.modal-small a.btn_close").click(function(){
		$(this).parent("div.modal, div.modal-small").fadeOut("slow",function(){
			$("div.modal,div.modal-small").remove();
		});
		return false;
	});
		
	$("div.modal .btn_submit").click(function(){		
		var formVals = $("#contact-form form :input").serializeArray();
		$.post($("#contact-form form").attr("action"),formVals,function(data){
			$("div.modal").replaceWith(data);
			$("div.modal").show();
			addClickHandlers();
		});	
		return false;
	});
}
