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