
jQuery(function($){
	// Hide the Symfony debug toolbar...
	var ms = parseInt($("#sfWebDebugDetails li:eq(5)").text().replace(/\ ms/, ''));
	var db = parseInt($("#sfWebDebugDetails li:eq(6)").text());
	var error = parseInt($("#sfWebDebug:has(.sfWebDebugWarning)").size()) + parseInt($("#sfWebDebug:has(.sfWebDebugError)").size());
	
	if (ms < 750 && db < 10 && error == 0) {
		sfWebDebugToggleMenu();
	}
	
	$("ul").each(function(){
		$(this).children("li:first").addClass('first');
		$(this).children("li:last").addClass('last');
	});

	$(".floodNavContent").each(function(){
	    var $this = $(this);
	    
		$this.prev('a').click(function(e){
		    e.preventDefault();
		});
		
		$this.load($this.prev('a').attr('href'), function(){
		    var $this = $(this);
		    
		    //equalHeight($(".navCol", $this));
		    
			$this.children("ul").each(function(i,e){
				var num = (i+1)/5;
				if (parseInt(num) == num) {
					$(e).addClass('last').next('ul').addClass('first');
				}
			});
			
			$this.parents('li.flood').hoverIntent({
				interval: 		100,
				sensitivity: 	4,
				timeout: 		300,
				over: 			showFloodNav,
				out: 			hideFloodNav
			});

		});
	});
	
	function showFloodNav(){
        $("#nav-brands .floodNavContent .navCol").hide().fadeIn(500);
		$(this).addClass("active").children('div').css('zIndex', 200).slideDown(300, function(){		    
		    
            $(".navCol").css('height', '100%');
            $(this).css('height', $(this).height()+'px');
		});
	}
	function hideFloodNav(){

		$(this).removeClass("active").children('div').css('zIndex', 100).slideUp(300);
	}
	
	$("#rootCategoryHeader .col").each(function(i,e){
		var num = (i+1)/4;
		if (parseInt(num) == num) {
			$(e).next('.col').css('clear', 'left');
		}
	});
	
	$("#productSearchField").focus(function(){
	    var $this = $(this),
	        value = $this.val();
	    if(value == 'Product search...'){
	        $this.val('');
	    }
	});
	
	$("#productSearchField").blur(function(){
	    var $this = $(this),
            value = $this.val();
        if(value == ''){
            $this.val('Product search...');
        }
	});
	
	var heroImages = $("#homepageImages");
    
    if(heroImages.length > 0){
        heroImages.cycle({
            timeout: 8000
        });
        
        $("#homepageImages").hover(
            function(){
                heroImages.cycle('pause');
            },
            function(){
                heroImages.cycle('resume');
            }
        ); 
    }
});

