$(document).ready(function() {
	
	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
		$(this).find('a.hover').stop().animate(
			{
				color: '#F46D02',
				backgroundColor: '#FFFFFF'
			},
			{
				duration: 'fast',
				queue: false
			}
		);
			
		//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(); 
	  });
		$(this).find('a.hover').stop().css(
			{
				color: '#FFFFFF',
				backgroundColor: 'transparent'
			}
		);
	}


	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: 10, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#prinav li .sub").css({'opacity':'0'});
	$("ul#prinav li.fade").hoverIntent(config);

});
// Fancy rollover breadcrumbs
$(document).ready(function() {
$('ul#prinav li .sub').mouseover(function(){
	$(this).parents('li').children('a').addClass('active');
});
$('ul#prinav li .sub').mouseout(function(){
	$(this).parents('li').children('a').removeClass('active');
});
});

//Box Sliders
$(document).ready(function(){
	//To switch directions up/down and left/right just place a "-" in front of the top/left attribute
	//Vertical Sliding
	$('.boxgrid.slidedown').hover(function(){
		$(".cover", this).stop().animate({top:'-260px'},{queue:false,duration:300});
	}, function() {
		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300});
	});
	//Horizontal Sliding
	$('.boxgrid.slideright').hover(function(){
		$(".cover", this).stop().animate({left:'325px'},{queue:false,duration:300});
	}, function() {
		$(".cover", this).stop().animate({left:'0px'},{queue:false,duration:300});
	});
	//Diagnal Sliding
	$('.boxgrid.thecombo').hover(function(){
		$(".cover", this).stop().animate({top:'260px', left:'325px'},{queue:false,duration:300});
	}, function() {
		$(".cover", this).stop().animate({top:'0px', left:'0px'},{queue:false,duration:300});
	});
	//Partial Sliding (Only show some of background)
	$('.boxgrid.peek').hover(function(){
		$(".cover", this).stop().animate({top:'90px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
	});
	//Full Caption Sliding (Hidden to Visible)
	$('.boxgrid.captionfull').hover(function(){
		$(".cover", this).stop().animate({top:'160px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'260px'},{queue:false,duration:160});
	});
	//Caption Sliding (Partially Hidden to Visible)
	$('.boxgrid.caption').hover(function(){
		$(".cover", this).stop().animate({top:'82px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'120px'},{queue:false,duration:160});
	});
});

var arrowMenu;
var arrowMenuSrc;

$(document).ready(function() {
	arrowMenu = $("#arrowMenu");
	arrowMenuSrc = arrowMenu.html();		

	restartMenu();
});

function restartMenu() { 

	arrowMenu.html(arrowMenuSrc);

	$("li.stepone").hover(function() { 
		$(this).append($('<div class="oneover"><img src="/themes/main/images/step-arrow-2.png" alt="arrow" /></div>').hide().fadeIn('1000'));
	}, function () { 
		restartMenu();
	});

	$("li.steptwo").hover(function() { 
		$(this).append($('<div class="twoover"><img src="/themes/main/images/step-arrow-2.png" alt="arrow" /></div>').hide().fadeIn('1000'));
	}, function () { 
		restartMenu();
	});

	$("li.stepthree").hover(function() { 
		$(this).append($('<div class="threeover"><img src="/themes/main/images/step-arrow-2.png" alt="arrow" /></div>').hide().fadeIn('1000'));
	}, function() { 
		restartMenu();
	});

	$("li.stepfour").hover(function() { 
		$(this).append($('<div class="fourover"><img src="/themes/main/images/step-arrow-2.png" alt="arrow" /></div>').hide().fadeIn('1000'));
	}, function() { 
		restartMenu();
	});
}

