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