$.preloadImages = function() {
	for(var i = 0; i<arguments.length; i++) {
		$("<img />").attr("src", arguments[i]);
	}
}

function formatText(index, panel) {
	return index + "";
};

$(document).ready(function() {
	
	$('a[rel*=ext]').click( function() { window.open(this.href); return false; });
	
	$('body').css( 'padding-bottom', '0' );
	
	$("html").addClass("js");
	
	$("ul.thumb li a", $(".item")).click(function() {
			var mainImage = $(this).attr("href"); //Find Image Name
			$("#main_view img", $(".item")).attr({ src: mainImage });
			return false;       
	});
	
	$.preloadImages("images/stationary-nav.png","images/computing-nav-bg.png","images/service-support-navigation-background.png","images/about-navigation-bg.png","images/printers-and-imaging-nav-bg.png","images/print-navigation-bg.png","images/contact-sub-nav.png");
	
	$("#side").accordion({
		event: "hover", 
		interval: 400,
		initShow : "#current"
	});
	
	$("#side-accordion").accordion({
			obj: "div", 
			wrapper: "div", 
			el: ".h", 
			head: "h3", 
			next: "div", 
			initShow : "div.outer:first",
			event : "hover",
			collapsible : false
		});
	
	$("html").removeClass("js");
	
	$('.anythingSlider').anythingSlider({
			easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: false,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
			delay: 5000,                    // How long between slide transitions in AutoPlay mode
			startStopped: false,            // If autoPlay is on, this can force it to start stopped
			animationTime: 600,             // How long the slide transition takes
			hashTags: true,                 // Should links change the hashtag in the URL?
			buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
			pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
			startText: "Go",                // Start text
			stopText: "Stop",               // Stop text
			navigationFormatter: formatText // Details at the top of the file on this use (advanced use)
	});
	
	$("#slide-jump").click(function() { $('.anythingSlider').anythingSlider(6); });

	$('.boxgrid.caption').hover(function(){
		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:375});
	}, function() {
		$(".cover", this).stop().animate({top:'177px'},{queue:false,duration:375});
	});

	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}


	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 500, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#navy li .sub").css({'opacity':'0'});
	$("ul#navy li").hoverIntent(config);

}); // END DOCUMENT READY

$(window).bind("load", function() {
	
	$("div#slider1").codaSlider();
	
	var autoSlide = setInterval( function() { $("#left-link").click(); }, 7000);
	
});
