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