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

