$(document).ready(function() {
	
	var animateTime = 400;
	
	  var cache = [];
	  // Arguments are image paths relative to the current page.
	  $.preLoadImages = function() {
	    var args_len = arguments.length;
	    for (var i = args_len; i--;) {
	      var cacheImage = document.createElement('img');
	      cacheImage.src = arguments[i];
	      cache.push(cacheImage);
	    }
	  }
		$.preLoadImages("emptyArrow.gif", "web/cuba-hover.jpg", "web/exposed-hover.jpg", "web/fresh-hover.jpg", "web/gibsons-hover.jpg",
	                       "web/mapart-hover.jpg", "web/textfields-hover.jpg", "img/archive/chymos-hover.jpg","img/archive/seekbots-hover.jpg",
	 					"img/archive/snow-hover.jpg", "img/archive/stereolumiscope-hover.jpg");
	
	//gallery
	$('a.gaiaGallery').click(function() {   
	   var gal = document.getElementById('firstGaia'); 
	   Shadowbox.open(gal);return false; 
	 });
	
	$('a.derelictGallery').click(function() {   
	   var gal = document.getElementById('firstDerelict'); 
	   Shadowbox.open(gal);return false; 
	 });
	
	
	//Nav Slide Down
	$(".top").hover(function(){

		$("#nav").stop(true, true);
		$("#activeSection").hide();
		$("#arrow").attr("src", "img/emptyArrow.gif");
		
		$("#nav").slideDown({
			duration: animateTime, 
			easing: "easeOutQuad"
		});
		//$("#nav").hide();

		
		$("#left").hover(function(){
		},function(){
			
			$("#arrow").attr("src", "img/fullArrow.gif");
			
			$("#nav").slideUp({
				duration: animateTime, 
				easing: "easeInQuad",
				complete:function(){ $("#activeSection").show();}
			});
		});
	});
	
	
	//NAV
	$("#active").css("background-color", "#fff");
	$("#active").css("color", "#222");
	
	var navTime = 80;
	
	$("#nav a").hover(function(){
		$("#active").css("background-color", "");
		$("#active").css("color", "");
		$(this).children().css("background-color", "#fff");
		$(this).children().css("color", "#222");
	},function(){
		
		$(this).children().css("background-color", "");
		$(this).children().css("color", "");
		$("#active").css("background-color", "#fff");
		$("#active").css("color", "#222");
	});
	
	
	//WEB
	$(".webItem").hover(function() {
		$(this).children().children().filter(".title").animate( { backgroundColor: '#fff' }, 250);
		$(this).children().children().filter(".title").children().filter("a").animate( { color: '#222' }, 250);
		/*$(this).parent().parent().children().children().filter(".title").css("padding-left", "10px");*/
    	$(this).children().children().filter("img").attr("src", $(this).children().children().filter("img").attr("src").split(".").join("-hover."));
	},
	function() {
		$(this).children().children().filter(".title").animate( { backgroundColor: '#222' }, 250);
		$(this).children().children().filter(".title").children().filter("a").animate( { color: '#fff' }, 250);
		$(this).parent().parent().children().children().filter(".title").css("padding-left", "");
    	$(this).children().children().filter("img").attr("src", $(this).children().children().filter("img").attr("src").split("-hover.").join("."));
	});
	
	
	//ARCHIVE
	$(".archiveImage").hover(function() {
        $(this).attr("src", $(this).attr("src").split(".").join("-hover."));
		$("#archive").text($(this).attr("title"));
    },
    function(){ 
        $(this).attr("src", $(this).attr("src").split("-hover.").join("."));
		$("#archive").text("ARCHIVE");
    });
});
