 $(document).ready(function() {
 	
	function headerPromoRotation() {
		var l = $('.header-promotions .view-content ul li').length;
		var i = $('.header-promotions .view-content ul li.active').attr('rel');
		i = i * 1;
		var n = i + 1;
		
		if (n == l) {
			n = 0;
		} 
		
		$('.header-promotions .view-content ul li.active').css({'z-index': '10', 'position': 'absolute', 'top': '0', 'left': '0'});
		$('.header-promotions .view-content ul li.active').fadeOut();
		$('.header-promotions .view-content ul li[rel="'+n+'"]').css({'position': 'absolute', 'top': '0', 'left': '0'});
		$('.header-promotions .view-content ul li[rel="'+n+'"]').fadeIn('normal', function() {
			$('.header-promotions .view-content ul li.active').css({'position': '', 'top': '', 'left': ''}).removeClass('active');
			$('.header-promotions .view-content ul li[rel="'+n+'"]').css({'position': '', 'top': '', 'left': ''}).addClass('active');
		});
		
		var t = setTimeout(headerPromoRotation, 5000);
	}
	
	if ($('body').hasClass('home')) {
		var t = setTimeout(headerPromoRotation, 5000);
	}

	//This function hides the active menu when you are not hovered over the parent so other parent sub menus can be seen
	function correctMenu() {
		$('.primary-links .menu li').each(function() {
			$(this).mouseover(function() {
			//if the item does not contain the active trail, hide the active trail
			if ($(this).hasClass('active-trail')) {
				$('.primary-links .menu li.active-trail ul').show();
			} else {
				$('.primary-links .menu li.active-trail ul').hide();
			}
			});
			
			$(this).mouseout(function() {
				$('.primary-links .menu li.active-trail ul').show();
			});
		});
	}
	
	correctMenu();
	
});
