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

	// Baackground Rotate
	$(document).ready(function(){
		bgImageTotal=4;
		randomNumber = Math.round(Math.random()*(bgImageTotal-1))+1;
		imgPath=('/images/seasonbackgrounds/summer/'+randomNumber+'.jpg');
		$('body').css({"background": '#000 url('+imgPath+') no-repeat top center fixed' });
	});
	// Image Navigation Fade
	$(document).ready(function(){
		$('.navfade').mouseover(function(){
			$(this).stop().animate({opacity: 1.0});
		});
		$('.navfade').mouseout(function(){
			$(this).stop().animate({opacity: 0.0}, 'slow');
		});
	});

// MEGA MENU
	$(document).ready(function() {
	

	function megaHoverOver(){
		$(this).find("div.sub").stop().fadeTo('fast', 1).show();
		$(this).css('cursor', 'pointer');
			
		//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("div.row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find("div.row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find("div.sub").css({'width' :biggestRow});
			$(this).find("div.row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find("div.sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
		$(this).css('cursor', 'auto');
	  $(this).find("div.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#special-nav-in li div.sub").css({'opacity':'0'});
	$("ul#special-nav-in li").hoverIntent(config);



});


$(document).ready(function() { 
	$('#nav_cc').click(function(e) { 
		e.preventDefault();
		window.location = 'http://viewer.zmags.com/publication/4bffa969';
		return false;
	});

	$('#nav_bb').click(function(e) { 
		e.preventDefault();
		window.location = 'http://viewer.zmags.com/publication/167ec369';
		return false;
	});
});

})(jQuery);

