$(document).ready(function() {

// PAGE FADER
// FADE EVERY PAGE IN
$('.fadewrapper').stop().hide().fadeIn(2000);	

// FADE EVERY PAGE OUT WHEN CLICKING ON LOGO
$('#logo').click(function(){
	$('.fadewrapper').stop().fadeOut('slow').queue(function() {
		window.location.replace("index.php");
	});
});

// HEADER
// FADE PAGE OUT/IN	
	$('#nav-main a').click(function() {
		var url = $(this).attr("href");
		var cn = $(this).attr("class");
		
		if (cn !== 'contact-overlay') {
			$('#sitewrapper').stop().fadeOut('slow').queue(function(){
				window.location.replace(url);
			});
			return false;
		} 
		
		
	});

// HEADER			
// MAIN NAV, DROPDOWN			
		function megaHoverOver(){
		$(this).find("> .sub-nav").stop().fadeTo('fast', 1).show();
		$(this).find("> a.year").stop().css({"color":"#111"});
	}
	
	function megaHoverOut(){ 
	 	 $(this).find("> a.year").stop().css({"color":"#585865"});
	  	 $(this).find("> .sub-nav").stop().fadeTo('fast', 0, function() {
		 $(this).hide(); 
	  });
	}

	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 10, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 150, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#nav-main li .sub-nav").css({'opacity':'0'});
	$("ul#nav-main li").hoverIntent(config);
	
	

//FOOTER	
//SITE CREDIT
	$("a.site-credit").hover(
		function() {
			$(".txt1").stop().animate({"opacity": "0"}, "fast");
			$(".txt2").stop(true,true).fadeIn("slow");	
	},
		function() {
			$(".txt2").stop(true,true).fadeOut("fast");	
			$(".txt1").stop().animate({"opacity": "1"}, "fast");
	});	
	
});


// homepage fade in sequence plugin
(function(a){a.fn.fadeInSequence=function(b,c,d){d=typeof d=="undefined"?"in":d;c=typeof c=="undefined"?0:c;b=typeof b=="undefined"?500:b;var e=a(this).size()*(b+c);var f=0;return a(this).each(function(){a(this).delay(f++*(b+c));e-=b+c;if(a(this).css("display")=="none"){if(d=="in"){a(this).fadeIn(b)}else{a(this).fadeOut(b)}}else{if(d=="in"){a(this).animate({opacity:1},b)}else{a(this).fadeOut(b)}}a(this).delay(e+c)})}})(jQuery)


