﻿/*
* jQuery doTimeout: Like setTimeout, but better! - v0.4 - 7/15/2009
* http://benalman.com/projects/jquery-dotimeout-plugin/
* 
* Copyright (c) 2009 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($) { var a = {}, c = "doTimeout", d = Array.prototype.slice; $[c] = function() { return b.apply(window, [0].concat(d.call(arguments))) }; $.fn[c] = function() { var f = d.call(arguments), e = b.apply(this, [c + f[0]].concat(f)); return typeof f[0] === "number" || typeof f[1] === "number" ? this : e }; function b(k) { var l = this, g, i = {}, m = arguments, h = 4, f = m[1], j = m[2], o = m[3]; if (typeof f !== "string") { h--; f = k = 0; j = m[1]; o = m[2] } if (k) { g = l.eq(0); g.data(k, i = g.data(k) || {}) } else { if (f) { i = a[f] || (a[f] = {}) } } i.id && clearTimeout(i.id); delete i.id; function e() { if (k) { g.removeData(k) } else { if (f) { delete a[f] } } } function n() { i.id = setTimeout(function() { i.fn() }, j) } if (o) { i.fn = function(p) { o.apply(l, d.call(m, h)) && !p ? n() : e() }; n() } else { if (i.fn) { j === undefined ? e() : i.fn(j === false); return true } else { e() } } } })(jQuery);
/*
* jQuery ajaxSort: Adds predictive search to DR catalogs - v0.7 - 2/4/2010
* 
* Copyright (c) 2010 Scott Hills for DR
*/
(function($) { var x = false; var y = ""; var z = []; var A = []; var B; var C; function showSearchResults(c, d, e) { C = 0; var f = $(searchfield).val(); f = f.replace(/[&\\]/g, ""); $('#searchValues').html('<div>...</div>'); var g = ""; var h = 0; z = []; var k = new Array(); k = f.split(' '); var o = k.length; k[o] = f; productStr = "0"; for (l = 0; l < (o + 1); l++) { if (k[l].length >= 3) { var p = A.length; for (n = 0; n < p; n++) { if (A[n][1].match(k[l].toLowerCase())) { var q = 0; for (var i = 0; i < A[n][1].length; i++) { if (k[l] == A[n][1].substr(i, k[l].length)) q++ } if (productStr.match(A[n][0]) != A[n][0]) { productStr = productStr + "##" + k[l] + "|" + A[n][0]; h++; var r = [k[l], A[n][0], q]; z.push(r) } else { var s = z.length; for (var j = 0; j < s; j++) { if (z[j][1] == A[n][0]) { z[j][0] = z[j][0] + "," + k[l]; z[j][2] = z[j][2] + q } } } } } } } function rankSort(a, b) { if (a[2] < b[2]) return 1; if (a[2] > b[2]) return -1; return 0 } z.sort(rankSort); var s = z.length; var t, thisProductRank, thisProductMatch; var u = c; if (c > s) { u = s } if (s > 0) { for (m = 0; m < u; m++) { thisProductMatch = z[m][0]; t = z[m][1]; thisProductRank = z[m][2]; var v = $(B).find('product[id=' + t + ']'); var w = v.find('description').text().substr(0, e) + '...'; g = g + '<div><a href="' + d + '/pd/productID.' + t + '"><img src="' + v.attr('image') + '" width="50" height="40" alt="" border="0" style="float: left;" /></a><h5><a href="' + d + '/pd/productID.' + t + '">' + v.attr('title') + '</a></h5><p>' + w + '</p></div>' } } if (g != "") { g = '<div class="searchHead">Products that may match your search:</div>' + g } $('#searchValues').html('' + g + ''); $('.resultsCount').html('' + s + ' results') } $.fn.ajaxSort = function(f) { var g = { searchSize: 6, descLength: 73, categoryWeight: 3, skuWeight: 3, storePath: "/store/shill/en_US/", uiDelay: 250 }; var f = $.extend(g, f); searchfield = this; return this.each(function() { $(searchfield).attr({ autocomplete: "off" }).focus(function() { if (!x) { var e = $(this); $('#searchValues').insertAfter(e); $.get(f.storePath + "/DisplayPage/id.ProductListXMLPage/", function(b) { x = true; B = b; var c, $category, $product, productID, productSku, productKeywords, categoryKeywords, productSku; c = "0"; $(b).find('category').each(function(i) { $category = $(this); categoryKeywords = ""; for (var i = 0; i < f.categoryWeight; i++) { categoryKeywords = categoryKeywords + " " + $category.attr("title") } $(this).find('product').each(function(j) { $product = $(this); productID = $product.attr("id"); productSku = ""; if (c.match(productID)) { } else { c = c + "," + productID; for (var j = 0; j < f.categoryWeight; j++) { productSku = productSku + " " + $product.attr("sku") } productKeywords = productSku + " || " + $product.attr("title") + " || " + $product.find('keywords').text() + " || " + $product.find('description').text() + " || " + categoryKeywords; A.push([productID, productKeywords.toLowerCase()]) } }) }); showSearchResults(); var d; e.keyup(function(a) { switch (a.keyCode) { case 13: if (C > 0) { location.href = $('#searchValues div:eq(' + C + ') a').attr('href'); return false } break; case 27: searchSelectIndex = 0; $('#searchValues div').css({ 'background-color': '#ffffff' }); this.value = ""; showSearchResults(); break; case 38: if (C >= 2) { C--; $('#searchValues div:not(:eq(' + C + '))').css({ 'background-color': '#ffffff' }); $('#searchValues div:eq(' + C + ')').css({ 'background-color': '#eeeeee' }) } return false; break; case 40: if (C < ($('#searchValues > div').size() - 1)) { C++; $('#searchValues div:not(:eq(' + C + '))').css({ 'background-color': '#ffffff' }); $('#searchValues div:eq(' + C + ')').css({ 'background-color': '#eeeeee' }) } return false; break; default: $(this).doTimeout('typing', f.uiDelay, function() { showSearchResults(f.searchSize, f.storePath, f.descLength) }) } }) }) } }) }) } })(jQuery);

