/**
* Stylish Select 0.4.5 - jQuery plugin to replace a select drop down box with a stylable unordered list
* http://github.com/sko77sun/Stylish-Select
* 
* Requires: jQuery 1.3 or newer
* 
* Contributions from Justin Beasley: http://www.harvest.org/ Anatoly Ressin: http://www.artazor.lv/ Wilfred Hughes: https://github.com/Wilfred
* 
* Dual licensed under the MIT and GPL licenses.
*/
(function(a) { a("html").addClass("stylish-select"); if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(d) { if (this === void 0 || this === null) { throw new TypeError() } var e = Object(this); var b = e.length >>> 0; if (b === 0) { return -1 } var f = 0; if (arguments.length > 0) { f = Number(arguments[1]); if (f !== f) { f = 0 } else { if (f !== 0 && f !== (1 / 0) && f !== -(1 / 0)) { f = (f > 0 || -1) * Math.floor(Math.abs(f)) } } } if (f >= b) { return -1 } var c = f >= 0 ? f : Math.max(b - Math.abs(f), 0); for (; c < b; c++) { if (c in e && e[c] === d) { return c } } return -1 } } a.fn.extend({ getSetSSValue: function(b) { if (b) { a(this).val(b).change(); return this } else { return a(this).find(":selected").val() } }, resetSS: function() { var b = a(this).data("ssOpts"); $this = a(this); $this.next().remove(); $this.unbind(".sSelect").sSelect(b) } }); a.fn.sSelect = function(b) { return this.each(function() { var l = { defaultText: "Please select", animationSpeed: 0, ddMaxHeight: "", containerClass: "" }; var o = a.extend(l, b), f = a(this), m = a('<div class="selectedTxt"></div>'), u = a('<div class="newListSelected ' + o.containerClass + '"></div>'), k = a('<div class="SSContainerDivWrapper" style="visibility:hidden;"></div>'), C = a('<ul class="newList"></ul>'), w = -1, e = -1, j = -1, p = [], z = false, y = false, A; a(this).data("ssOpts", b); u.insertAfter(f); u.attr("tabindex", f.attr("tabindex") || "0"); m.prependTo(u); C.appendTo(u); C.wrap(k); k = C.parent(); f.hide(); m.data("ssReRender", !m.is(":visible")); if (f.children("optgroup").length == 0) { f.children().each(function(E) { var F = a(this).html(); var D = a(this).val(); p.push(F.charAt(0).toLowerCase()); if (a(this).attr("selected") == "selected") { o.defaultText = F; e = j = E } C.append(a('<li><a href="JavaScript:void(0);">' + F + "</a></li>").data("key", D)) }); A = C.children().children() } else { f.children("optgroup").each(function() { var D = a(this).attr("label"), F = a('<li class="newListOptionTitle">' + D + "</li>"), E = a("<ul></ul>"); F.appendTo(C); E.appendTo(F); a(this).children().each(function() { ++w; var H = a(this).html(); var G = a(this).val(); p.push(H.charAt(0).toLowerCase()); if (a(this).attr("selected") == "selected") { o.defaultText = H; e = j = w } E.append(a('<li><a href="JavaScript:void(0);">' + H + "</a></li>").data("key", G)) }) }); A = C.find("ul li a") } var r = C.height(), q = u.height(), B = A.length; if (e != -1) { i(e) } else { m.text(o.defaultText) } function s() { var E = u.offset().top, D = a(window).height(), F = a(window).scrollTop(); if (r > parseInt(o.ddMaxHeight)) { r = parseInt(o.ddMaxHeight) } E = E - F; if (E + r >= D) { C.css({ height: r }); k.css({ top: "-" + r + "px", height: r }); f.onTop = true } else { C.css({ height: r }); k.css({ top: q + "px", height: r }); f.onTop = false } } s(); a(window).bind("resize.sSelect scroll.sSelect", s); function v() { u.css("position", "relative") } function d() { u.css({ position: "static" }) } m.bind("click.sSelect", function(D) { D.stopPropagation(); if (a(this).data("ssReRender")) { r = C.height("").height(); k.height(""); q = u.height(); a(this).data("ssReRender", false); s() } a(".SSContainerDivWrapper").not(a(this).next()).hide().parent().css("position", "static").removeClass("newListSelFocus"); k.toggle(); v(); if (e == -1) { e = 0 } A.eq(e).focus() }); function c(E, D) { if (E == true) { j = e; f.change() } if (D == true) { e = j; i(e) } k.hide(); d() } A.bind("click.sSelect", function(E) { var D = a(E.target); e = A.index(D); y = true; i(e, true); c() }); A.bind("mouseenter.sSelect", function(E) { var D = a(E.target); D.addClass("newListHover") }).bind("mouseleave.sSelect", function(E) { var D = a(E.target); D.removeClass("newListHover") }); function i(D, H) { if (D == -1) { m.text(o.defaultText); A.removeClass("hiLite") } else { A.removeClass("hiLite").eq(D).addClass("hiLite"); var G = A.eq(D).text(), F = A.eq(D).parent().data("key"); try { f.val(F) } catch (E) { f[0].selectedIndex = D } m.text(G); if (H == true) { j = D; f.change() } if (k.is(":visible")) { A.eq(D).focus() } } } f.bind("change.sSelect", function(E) { var D = a(E.target); if (y == true) { y = false; return false } var F = D.find(":selected"); e = D.find("option").index(F); i(e) }); function t(D) { a(D).unbind("keydown.sSelect").bind("keydown.sSelect", function(G) { var F = G.which; y = true; switch (F) { case 40: case 39: x(); return false; break; case 38: case 37: n(); return false; break; case 33: case 36: h(); return false; break; case 34: case 35: g(); return false; break; case 13: case 27: c(true); return false; break } keyPressed = String.fromCharCode(F).toLowerCase(); var E = p.indexOf(keyPressed); if (typeof E != "undefined") { ++e; e = p.indexOf(keyPressed, e); if (e == -1 || e == null || z != keyPressed) { e = p.indexOf(keyPressed) } i(e); z = keyPressed; return false } }) } function x() { if (e < (B - 1)) { ++e; i(e) } } function n() { if (e > 0) { --e; i(e) } } function h() { e = 0; i(e) } function g() { e = B - 1; i(e) } u.bind("click.sSelect", function(D) { D.stopPropagation(); t(this) }); u.bind("focus.sSelect", function() { a(this).addClass("newListSelFocus"); t(this) }); u.bind("blur.sSelect", function() { a(this).removeClass("newListSelFocus") }); a(document).bind("click.sSelect", function() { u.removeClass("newListSelFocus"); if (k.is(":visible")) { c(false, true) } else { c(false) } }); m.bind("mouseenter.sSelect", function(E) { var D = a(E.target); D.parent().addClass("newListSelHover") }).bind("mouseleave.sSelect", function(E) { var D = a(E.target); D.parent().removeClass("newListSelHover") }); k.css({ left: "0", display: "none", visibility: "visible" }) }) } })(jQuery);
