head.ready(function(){
	
	var cells = $('#information_div td.form-label-required');
	$.each(cells, function(){
		var text = $(this).text();
		$(this).text(text + '*');
	})
	
	
	/* IE6 fix for input:hover pseudo selector */
	$('#cartInfo input[type="button"]').hover(
		function(){
			$(this).addClass('hover');
		},
		function(){
			$(this).removeClass('hover');
		}
	);
	
	function submitSearch()
	{
            $('form[name="ds_search"]').submit();
	}

	$('a[name="search"]').click(function(){
		submitSearch();

	})
	
	
	$('input[name="search"]').focus(function(){
		if($(this).val()=='Search for a product'){
		   $(this).attr('value', '');
		}
	})
	
	$('input[name="search"]').blur(function(){
		if($(this).val()==''){
		   $(this).attr('value', 'Search for a product');
		}
	})
	
        DropDownMenus.init();
        
        $('div.topProducts h3.ribbon')
        .hover(
            function(){
                $(this).parent().find('li:nth-child(3)').addClass('hover');
                return true;
            }
            ,function(){
                $(this).parent().find('li:nth-child(3)').removeClass('hover');
                return true;
            }
        )
        .click(function(){
            $(this).parent().find('li:nth-child(3)').trigger('click');
            return true;
        })
        .css('cursor', 'pointer');
        
        $('ol.product-grid div.topProductRibbon,ol.product-list div.topProductRibbon')
        .hover(
            function(){
                $(this).parent().find('a:first').addClass('hover');
                return true;
            }
            ,function(){
                $(this).parent().find('a:first').removeClass('hover');
                return true;
            }
        )
        .click(function(){
            //console.info('clicked: ', this, $(this).parent().find('a:first'));
            window.location = $(this).parent().find('a:first').attr('href');
            return true;
        })
        .css('cursor', 'pointer');
});

var DropDownMenus = function(){
    var ACTIVE_MENU_ITEM;
    var ACTIVE_MENU_ITEMS;
    return {
        init: function()
        {
            $(document.body).bind('click', this.clearMenus);
            $('#store-finder-menu a:first').bind('click', this.toggleMenu).attr('id', 'store-finder-menu-trigger');
        }
        ,toggleMenu: function(e)
        {
            if(e)
                e.stopPropagation();
            
            if(ACTIVE_MENU_ITEM)
                ACTIVE_MENU_ITEM.removeClass('active');

            if(ACTIVE_MENU_ITEMS)
                ACTIVE_MENU_ITEMS.fadeOut();

            //
            ACTIVE_MENU_ITEM = $(this).parent('li').addClass('active');
            ACTIVE_MENU_ITEMS = $(this).parent('li').find('ul').fadeIn(200);

            return false;
        }
        ,clearMenus: function()
        {
            if(ACTIVE_MENU_ITEM)
                ACTIVE_MENU_ITEM.removeClass('active');

            if(ACTIVE_MENU_ITEMS)
                ACTIVE_MENU_ITEMS.hide();
        }
    };
}();


var LaunchLiveChat = function(){
    $('#InstanteStoreLiveChat a:first').trigger('click');
    return false;
};
