/* nifty preload function */
(function($) {
  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);
    }
  }
})(jQuery)

function sortLandingImages(id,over){
	var images = $(".landingHover").get();
	for(var i=0;i<images.length;i++){
		var $$ = $(images[i]);
		var n=$$.attr("name");
		if(over)
		{
			$$.stop(true);
			if(id==n)
			{
				$$.parent().find('.fade').stop(true).animate({opacity:0},10);
				$$.parent().find('.over').stop(true).animate({opacity:1},10);
			} else {
				
				$$.parent().find('.fade').stop(true).animate({opacity:1},10);
				$$.parent().find('.over').stop(true).animate({opacity:0},10);
			}
			$$.animate({opacity:0},250);	
		} else {
			// the =+0 thing just creates a 250ms delay
			$$.stop(true).animate({opacity: '+=0'}, 250).animate({opacity:1},100);
		}
	}
}


$(document).ready(function () {
	$(".landingHover").hover(function(){						  
		var n=$(this).attr("name");
		$("#"+n).css("left",$(this).parent().parent().css("left")).css("top",$(this).parent().parent().css("top").replace("px","")>16?"16px":"213px").fadeIn(250);
		sortLandingImages(n,true);
	},
	function(){					  
		var n=$(this).attr("name");
		$("#"+n).fadeOut(50);
		sortLandingImages(n,false);
	});
	$("#subNav li.first").hover(function(e){
		$(this).addClass("active");
		var drop = $(this).children("ul");
		var img = $(this).children("img");
		var h = 18;
		if(drop.length==1)
		{
			h = $(drop[0]).height();
		}
		if(img.length==1)
		{
			$(img[0]).css("top",(h+$(this).height())+"px");
		}	
	},
	function(e){
		$(this).removeClass("active");	
	});

});
