(function(a) { a("html").addClass("stylish-select"); Array.prototype.indexOf = function(a, b) { for (var c = b || 0; c < this.length; c++) { if (this[c] == a) { return c } } }; 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(b) } }); a.fn.sSelect = function(b) { return this.each(function() { function B() { j = s - 1; w(j) } function A() { j = 0; w(j) } function z() { if (j > 0) { --j; w(j) } } function y() { if (j < s - 1) { ++j; w(j) } } function x(a) { a.onkeydown = function(a) { var b; if (a == null) { b = event.keyCode } else { b = a.which } m = true; switch (b) { case 40: case 39: y(); return false; break; case 38: case 37: z(); return false; break; case 33: case 36: A(); return false; break; case 34: case 35: B(); return false; break; case 13: case 27: h.hide(); v(); return false; break } keyPressed = String.fromCharCode(b).toLowerCase(); var c = k.indexOf(keyPressed); if (typeof c != "undefined") { ++j; j = k.indexOf(keyPressed, j); if (j == -1 || j == null || l != keyPressed) j = k.indexOf(keyPressed); w(j); l = keyPressed; return false } } } function w(a, b) { n.removeClass("hiLite").eq(a).addClass("hiLite"); if (h.is(":visible")) { n.eq(a).focus() } var c = n.eq(a).text(); var d = n.eq(a).parent().data("key"); if (b == true) { e.val(d); f.text(c); return false } e.val(d); e.change(); f.text(c) } function v() { g.css("position", "static") } function u() { g.css("position", "relative") } function t() { var a = g.offset().bottom; var b = jQuery(window).height(); var c = jQuery(window).scrollTop(); if (q > parseInt(d.ddMaxHeight)) { q = parseInt(d.ddMaxHeight) } a = a - c; if (a + q >= b) { h.css({ top: "-" + q + "px", height: q }); e.onTop = true } else { h.css({ top: r + "px", height: q }); e.onTop = false } } var c = { defaultText: "Please select", animationSpeed: 0, ddMaxHeight: "" }; var d = a.extend(c, b); var e = a(this); var f = a('<div class="selectedTxt" id="selectedTxt"></div>'); var g = a('<div class="newListSelected" tabindex="0"></div>'); var h = a('<ul class="newList"></ul>'); var i = -1; var j = -1; var k = []; var l = false; var m = false; var n; var o = true; var p = -1; a(this).data("ssOpts", b); g.insertAfter(e); f.prependTo(g); h.appendTo(g); e.hide(); if (e.children("optgroup").length == 0) { e.children().each(function(b) { var c = a(this).text(); var e = a(this).val(); k.push(c.charAt(0).toLowerCase()); if (a(this).attr("selected") == true) { d.defaultText = c; p = b } h.append(a('<li><a href="' + e + '" target="_self">' + c + "</a></li>").data("key", e)) }); n = h.children().children() } var q = h.height(); var r = g.height(); var s = n.length; if (j != -1) { w(j, true) } else { f.text(d.defaultText) } t(); a(window).resize(function() { t() }); a(window).scroll(function() { t() }); f.click(function(b) { b.stopPropagation(); a(".newList").not(a(this).next()).hide().parent().removeClass("newListSelFocus"); h.toggle(); o = true; n.eq(p).addClass("newListHover"); u() }); n.click(function(b) { var c = a(b.target); j = n.index(c); m = true; w(j); h.hide(); v() }); n.hover(function(b) { var c = a(b.target); j = n.index(c); c.addClass("newListHover"); if (o && j != p) { n.eq(p).removeClass("newListHover"); o = false } }, function(b) { var c = a(b.target); c.removeClass("newListHover") }); e.change(function(b) { $targetInput = a(b.target); if (m == true) { m = false; return false } $currentOpt = $targetInput.find(":selected"); j = $targetInput.find("option").index($currentOpt); w(j, true) }); g.click(function() { x(this) }); g.focus(function() { a(this).addClass("newListSelFocus"); x(this) }); g.blur(function() { a(this).removeClass("newListSelFocus") }); a("body").click(function() { g.removeClass("newListSelFocus"); h.hide(); v() }); f.hover(function(b) { var c = a(b.target); c.parent().addClass("newListSelHover") }, function(b) { var c = a(b.target); c.parent().removeClass("newListSelHover") }); h.css("left", "0").hide() }) } })(jQuery)
