(function($){
    
    if(!window.console){
        window.console = {log: function(){ }};
    }
    
    $(document).ready(function(){
        
        // IE only related JavaScript
        if($.browser.msie){
            // :hover pseudo selector fix (less than IE7)
            if($.browser.version < 7){
                $('.cell-wrapper').hover(
                    function(){
                        $(this).addClass('hover');
                    },
                    function(){
                        $(this).removeClass('hover');
                    }
                );
            }
            // PNG Fix (IE 5.5 and 6)
            if($.browser.version >= 5.5 && $.browser.version < 7){
                // PNG Fix
                $('img[@src$=.png]').ifixpng('/images/pixel.gif');
            }
        }
        
        // Preload tooltip images
        preloadImages(
            '/images/categories_layout/tooltip/top.gif',
            '/images/categories_layout/tooltip/bottom.gif'
        );
        
        // Weight to Volume conversion
        $('#volume-weight').keydown(function(e){
            var $target = $(this);
            var result  = false;
            // Check if key pressed is numeric
            var unicode = (e.charCode ? e.charCode : e.keyCode);
            // Numeric (0-9), Num Pad (0-9), . (period), backspace key, DEL key
            if((unicode >= 48 && unicode <= 57) || (unicode >= 96 && unicode <= 105) || unicode==46 || unicode==8 || unicode==127){
                result = true;
            }
            // Display conversion result
            setTimeout(function(){
                var sizeHtml = '';
                var weight   = $target.val();
                if(weight != ''){
                    sizeHtml = weight + ' cu/in. or greater';
                }
                $('#volume-needed').html(sizeHtml);
            }, 250);
            return result;
        });
        
        // ------------------------------------------------------------------------------
        
		var moveDistance = 25;
		
        // Bubble Tip for Product Stats
        $(".volume").hoverIntent(
            function(){
                var $bubbleTip = $(this).parents(".cell-wrapper-inside").children(".bubble-tip");
                displayBubbleTip($bubbleTip);
            },
            function(){
                var $bubbleTip = $(this).parents(".cell-wrapper-inside").children(".bubble-tip");
                hideBubbleTip($bubbleTip);
            }
        );
    
        function displayBubbleTip($bubbleTip){
            if($bubbleTip.length){
				$bubbleTip.animate({ opacity: "show", bottom: "-=" + moveDistance }, "fast");
            }
        }
    
        function hideBubbleTip($bubbleTip){
			if($bubbleTip.length){
				$bubbleTip.animate({ opacity: "hide", bottom: "+=" + moveDistance }, "normal");
			}
        }
				
        // ------------------------------------------------------------------------------

			$(".learn, #close").click(function() {
				if($("#catInfo").css("display") == "none") {
					$(".learn").toggle();
					$("#catInfo").slideToggle("slow");	
					return false;
				} else {
					$("#catInfo").slideToggle("slow", function() { $(".learn").toggle(); });	
					return false;
				}
			});
			
        // ------------------------------------------------------------------------------

		$("dd.show-all").click(function() {
			$(this).siblings(".children-extra").show();	
			$(this).hide();
			return false;
		});
				    
    });
    
})(jQuery);