// JavaScript Document
// handles page load and unload animations
$(window).bind('load', function() {								
		var k = 500;
		var filename = this.location.href.substring(this.location.href.lastIndexOf('/') + 1);
		if ((document).title == "Mimmo Siviglia - Home" ||
			filename == "shirts.html" || 
			filename == "about.html" ||
			filename == "creations.html" ||
			filename == "fabrics.html" ||
			filename == "press.html" ||
			filename == "contact.html"||
			filename == "riva.html" || 
			filename == "sictess.html"
			 ) {
				$('#background').show("clip",{direction: "vertical"},200);
				setTimeout(showpic,220);
				setTimeout(showelements1,500);
				setTimeout(showsubnavigations,750);
				setTimeout(showgallerybutton,1050);	
			}
			else{
				$(function() {showpic();});
				if ($.browser.msie) {
					$("div.slider-wrap").fadeIn(300);
   				 }
				 else { 
				 	$("div.slider-wrap").css({top:"-60px"});
				 	$("div.slider-wrap").show().animate({top:"0px",opacity:"100%",easing:"easeInExpo"}, {duration:250});	 
				 };
				setTimeout(showelements2,500);
				setTimeout(showgallerybutton,650);
				setTimeout(showbuttonparent,800);
			};			
});		
function showpic() {	
		$("div[class^='theme_pic']").fadeIn(400);//fade-in effect										
}
function showelements1() {
		$('#contentpane_1').fadeIn(300);
		$("div.slider-wrap").fadeIn(300);
		$("div.contentpane_contact").fadeIn(300);
		$('#tabs').fadeIn(300);
		$("#forward_button1").fadeIn(200);
		$("#loadingmessage").css({display:"none"});
}	
function showelements2() {
		$('#contentpane_1').fadeIn(300);
		$("div.contentpane_contact").fadeIn(300);
		$('#tabs').fadeIn(300);
		$("#forward_button1").fadeIn(200);
		$("#loadingmessage").css({display:"none"});
}	
function showsubnavigations() {	
	$("#nav").fadeIn(300);
	$("#gallery_slit").fadeIn(300);
	$("#top_nav_").fadeIn(300);
	$("#side_nav_").fadeIn(300);
	$("a.trigger").fadeIn(300); // for news placeholder on home page
}	
function showgallerybutton() {
	if ($.browser.msie) {
	$(".gallery_button").css({top:"0"});
	$(".gallery_button").fadeIn(200);	
		}
	else{
	$(".gallery_button").show().animate({top:"0",opacity:"100%",easing:"easeInExpo"},{duration:150});
	}
}
function showbuttonparent() {
	$("div[id^='back_button_parent_']").fadeIn(300);
}
$(document).ready(function () {	
	$("#nav a").live("click", unload2);	//click on sub navigations not from fabric swatches								  
	$("#top_nav a").live("click", unload2);	
	$("#side_nav a").live("click", unload2);
	$(".nav a").live("click", unload1); //click on main navigation
	$(".gallery_button a").live("click", unload1); //click on fabric swatch
	$(".gallery_label a").live("click", unload1); //click on fabric swatch
	$("div[id^='back_button_parent_'] a").live("click", unload1);
})
function unload2 (event){							  							  
  	var href = $(this).attr("href");
  	var animDuration = 300;
  	if(href != "javascript:;"){
  		$("div.contentpane").animate({top:"200px",opacity:"0%",easing:"easeOutExpo"}, {duration:150});
		$("div.slider-wrap").animate({top:"70px",opacity:"0%",easing:"easeOutExpo"}, {duration:250});
		$("div.contentpane_contact").animate({top:"200px",opacity:"0%",easing:"easeOutExpo"}, {duration:150});
		$(".gallery_button").fadeOut(300);
		$(".gallery_label").fadeOut(200);
		$("#frame").animate({top:"200px",opacity:"0%",easing:"easeOutExpo"}, {duration:150});
		$("div[id*='theme_']").fadeOut(200);	
		setTimeout(hidegallerybutton,100);
  		setTimeout(function () {
   		 window.location = href;
  		}, animDuration);
 		 return false; // prevent user navigation away until animation's finished
		};
	}
function unload1(event){
		var href = $(this).attr("href");
  		var animDuration = 610;
  		if(href != "javascript:;"){
			$('#nav').fadeOut(200);
			$('#top_nav').fadeOut(200);
			$('#side_nav').fadeOut(200);
			$("#gallery_slit").fadeOut(200);
			$("div.contentpane").animate({top:"200px",opacity:"0%",easing:"easeOutExpo"}, {duration:150});
			$("div.contentpane_contact").animate({top:"200px",opacity:"0%",easing:"easeOutExpo"}, {duration:150});
			$("div.slider-wrap").animate({top:"60px",opacity:"0%",easing:"easeOutExpo"}, {duration:150});
			$(".gallery_label li").fadeOut(100);
			$("#tabs").animate({top:"200px",opacity:"0%",easing:"easeOutExpo"}, {duration:150});
			$("#frame").animate({top:"200px",opacity:"0%",easing:"easeOutExpo"}, {duration:150});
			$("div[id*='theme_']").fadeOut(500);
			$("#home_animation").fadeOut(500);
			setTimeout(hidegallerybutton,150);
			setTimeout(hidefwdback,200);
			setTimeout(hidebackground,300);
			setTimeout(function () {
			  window.location = href;
			 }, animDuration);
				return false; // prevent user navigation away until animation's finished
		};
}							
function hidegallerybutton(){
		$(".gallery_button").animate({top:"+=70px",opacity:"0%",easing:"easeInQuad"}, {duration:330});
		$("a.trigger").animate({top:"+=40px",opacity:"0%",easing:"easeInQuad"}, {duration:250}); //home page news placeholder
}	
function hidebackground(){ 
		$('#background').hide("clip",{direction: "vertical"},200);
}
function hidefwdback(){
	$("div[id^='back_button_parent_']").animate({top:"+=40px",opacity:"0%",easing:"easeInQuad"}, {duration:250});
	$("div.fwdback").animate({top:"+=40px",opacity:"0%",easing:"easeInQuad"}, {duration:150});
}
