$(document).ready(function() {
//preload all css images
	$.preloadCssImages();
//set the page up initially
	$("#logo span").css("opacity", "0");
	$("#TEOCmainchanger.home").css("opacity", "0");
	$("#homeright.home > .intro > div").css("opacity", "0");
	$("#homeright.home > .intro > #home").css("opacity", "1");
//swap logo on hover, swap back after
	// on mouse over
	$("#logo").hover(function () {
		// animate opacity to full
		$("#logo span").animate({
			opacity: 1
			}, { queue:false, duration:500 } 
		);
	},
	// on mouse out
	function () {
		// animate opacity to nill
		$("#logo span").stop().animate({
			opacity: 0
			}, { queue:false, duration:500 } 
		);
	});
//swap home grid images
	//on mouse over
	$("#TEOCmain li").hover(function () {
		//work out which panel was rolled over, set the variable
		var section =  $(this).attr("title");
		//remove any existing classes
		$("#TEOCmainchanger").removeClass();
		//add the appropriate class
		$("#TEOCmainchanger").addClass(section);
		//fade into visibility
		$("#TEOCmainchanger").animate({
			opacity: 1
			}, { queue:false, duration:500 } 
		);
		//hide the home logo
		$("#home").animate({
			opacity: 0
			}, { queue:false, duration:500 } 
		);
		//show the relevant text section
		$("#"+section).animate({
			opacity: 1
			}, { queue:false, duration:500 } 
		);
	},
	// on mouse out
	function () {
		//set the panel variable again
		var section =  $(this).attr("title");
		//fade it out
		$("#TEOCmainchanger").animate({
			opacity: 0
			}, { queue:false, duration:500 } 
		);
		//animate back to invisible
		$("#TEOCmainchanger").removeClass();
//		$("#TEOCmainchanger").stop().queue(function () {
//	        $(this).removeClass();
//	        $(this).dequeue();
//	    });
		//hide the text section
		$("#"+section).stop().animate({
			opacity: 0
			}, { queue:false, duration:500 } 
		);		
		//show the home logo
		$("#home").stop().animate({
			opacity: 1
			}, { queue:false, duration:500 } 
		);
	});		
//Set up flash slideshow
	var flashvars = false;
	var params = {
		flashvars: "offsite=true&lang=en-us&page_show_url=%2Fphotos%2Fethicaloccasions%2Fshow%2F&page_show_back_url=%2Fphotos%2Fethicaloccasions%2F&user_id=33872347@N03&jump_to="
	};
	var attributes = false;
	swfobject.embedSWF("http://www.flickr.com/apps/slideshow/show.swf?v=70933", "portfolioflash", "460", "460", "9.0.0", false, flashvars, params, attributes);
//google form hack
	var f = $("#iframeform")[0];
	f.attachEvent ? f.attachEvent("onload", onFrameLoad) :
	f.addEventListener("load", onFrameLoad, false); 
	
	function onFrameLoad() {
		iframeonloadcount++;
	    if (iframeonloadcount>1) {
		    document.getElementById("iframeform").src="/ethical_occasions_contact_form_submission.htm";
		    iframeonloadcount=0;
	    }
  	};
});