// For Additional Product Images Scroll Bar 
var speed = 5;
var grap  = 175;

$(function() {
$(".search_box").attr("autocomplete","off");
$('#headersearch .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"><h3>Live Search Results...</h3><input type="submit" title=" Search " alt="Search" value="View All Results" id="allresults"></div><div id="predictive-content">';
if (max > 1) {
for (var i = 0; i < max; i++) {
string += '<a class="search_image" href="' + options[i].url + '" _fcksavedurl="' + options[i].url + '">' + options[i].image + '</a><a class="search_name" href="' + options[i].url + '" _fcksavedurl="' + 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();
}
}
});
}
