// For Additional Product Images Scroll Bar 
var speed = 5;
var grap  = 200;

$(function() {
$(".submenu ul").hide();
$(".submenu span").click(function() {
if($(this).parent().parent().hasClass("submenu")) { 
            $(this).parent().parent().find("ul").slideToggle();    
            var n = $(".submenu span").index(this);
            createCookie("menuPos",n,1);    
            return false;       
} else {
}
});
var menuVal = getCookie("menuPos");
if(menuVal!=null) {
            $(".submenu span").eq(menuVal).parent().parent().find("ul").show();
}
});
function createCookie(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString()}else var expires="";document.cookie=name+"="+value+expires+"; path=/"}function getCookie(cookieName){var cookieJar=document.cookie.split("; ");for(var x=0;x<cookieJar.length;x++){var oneCookie=cookieJar[x].split("=");if(oneCookie[0]==escape(cookieName)){return unescape(oneCookie[1])}}return null}
$(function() {
	$('.productPriceDiscount').each(function(){
		var removeSave = $(this);
		removeSave.html( removeSave.html().replace('Save: ','') );
	});


}); 

$(function() {

$(".search_box").attr("autocomplete","off");
	$('#menu_bottom .search_box').keyup(function(e) {
	        var $this = $(this);
	        
	        // Sometimes IE dont know the event
	        var code = (e.keyCode ? e.keyCode : e.which);
	           
	        // The Enter Button
	        if (e.keyCode == '13') {
	            e.preventDefault();
	        }   
            
            clearTimeout($.data(this, 'timer'));

            // Only do the ajax call then a centin amount of letters have been called.

            if ($this.val().length <= 3) {
               $("#predictive-content").html("<p>More than 3 characters required.</p>");
               return;
            }  else {            	
            	$("#predictive-content").html("");            	
            } 
            
            var wait = setTimeout(function() {productSearch($this)}, 500); 
            
    });


});


function productSearch($this)
{
   $.ajax({
          	type: "POST", 
           	url:  "ajax.php", 
           	data: "type=product&action=predictiveSearch&l=5&size=medium&searchfor="+$this.val(), 
           	dataType: "json",
           	success: function(options){ 
               	    var max    = options.length;
                    var string = '';
					string = '<div id="predictive-top"></div><div id="predictive-content">';
               	    if (max > 1) {
	        	           for (var i = 0; i < max; i++) {	
   	                            string += '<a class="search_image" href="' + options[i].url + '">' + options[i].image + '</a><a class="search_name" href="' + options[i].url + '">' + options[i].name + '</a><div class="search_description">' + options[i].description + '</div><div class="search_clear"></div>\n';
	                	   } 
					string = string + '</div><div id="predictive-bot"></div>';	   
	             	      $('#predictiveSearch').html(string).show();
	            	} else {
	            	       $('#predictiveSearch').html('').hide();
	            	}              
       	}
   });
}

