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

