(function(A){A.fn.extend({getByteLength:function(D){var C,B=0;for(C=0;C<D.length;C++){if(escape(D.charAt(C)).length>=4){B+=2}else{B++}}return B}});A.fn.extend({getIndexByByte:function(E,B){var D,C=0;for(D=0;D<E.length;D++){if(escape(E.charAt(D)).length>=4){C+=2}else{C++}if(C>B){return[true,D]}}return false}});A.fn.extend({finalselect:function(J){var C={id:null,animalSpeed:100,selectWidth:"150px",selectImage:"/home/templates/images/custom_select.png",zIndex:0,viewHeight:"auto",viewWidth:"148px",viewMouseoverColor:"#cfdfff",viewTop:"18px",viewLeft:" 0px",selectedIndex:0};var F=0;if(typeof (J)!="undefined"){jQuery.extend(C,J)}var E='<div id="'+C.id+'-select" style="cursor: pointer;font-size:11px;z-index:'+C.zIndex+';border: solid 0px #999; padding: 0px; width: 150px; position: relative;">';E+='<div id="'+C.id+'-Text" style="background: url('+C.selectImage+") no-repeat 0 0; width: "+C.selectWidth+'; height: 18px; color: #333; padding: 0  0 0 5px;">';E+='<div class="textshow" style="padding: 1px 0 0 0;">'+C.selectText+'</div><div class="valueshow" style="display:none;"></div></div><div id="'+C.id+'-selectshow" style="overflow-y:hidden; overflow-x:hidden; height:'+C.viewHeight+";width:"+C.viewWidth+"; display:none; position: absolute; z-index: 999; left:"+C.viewLeft+"; top:"+C.viewTop+'; border: solid 1px #999; border-top: none; background: white;"></div></div>';var I=function(){A(this).html(E);D();G();B()};var D=function(){var K=A("#"+C.id+"-Text");A("#"+C.id+"-Text").bind("click",function(M){var L=A("#"+C.id+"-selectshow");if(L.css("display")=="none"){L.slideDown(C.animalSpeed,function(){L.show();L.css("overflow","auto");L.css("overflow-x","hidden")})}else{L.slideUp(C.animalSpeed,function(){L.hide()})}})};var H=function(){var L=0;while(A(".selectitem",A("#"+C.id+"-selectshow")).get(L)!=null){var K=A(".selectitem",A("#"+C.id+"-selectshow")).get(L);A(K).bind("mouseover",function(M){A(this).css("background-color",C.viewMouseoverColor)});A(K).bind("mouseout",function(M){A(this).css("background-color","#fff")});A(K).bind("click",function(O){var N=A(".thistext",A(this)).html();var M=A().getIndexByByte(N,16);if(M[0]==true){N=N.substring(0,M[1])+"..."}A(".textshow",A("#"+C.id+"-Text")).html(N);document.getElementById(C.id+"-selectshow").style.display="none";A(".valueshow",A("#"+C.id+"-Text")).html(A(".selectvalue",A(this)).html())});L++}};var G=function(){A("#"+C.id+"-Text").bind("mouseover",function(){A("#"+C.id+"-Text").css("background-position","0 -18px")})};var B=function(){A("#"+C.id+"-Text").bind("mouseout",function(){A("#"+C.id+"-Text").css("background-position","0 0px")})};this.setViewTop=function(K){A("#"+C.id+"-selectshow").css("top",K+"px")};this.setViewLeft=function(K){A("#"+C.id+"-selectshow").css("left",K+"px")};this.getLength=function(){return A(".selectitem",A("#"+C.id+"-selectshow")).length};this.addItem=function(M,L){var K='<div class="selectitem" style="cursor: pointer; margin: 0px; padding: 2px;"><div class="selecttext" style="width: 100%; text-align: left;">'+M+'</div><div class="selectvalue" style=" display:none;">'+L+'</div></div><div class="selectborder" style="border-bottom: solid 1px #ddd;"><div>';A("#"+C.id+"-selectshow").html(A("#"+C.id+"-selectshow").html()+K);H()};this.removeItem=function(K){if(A(".selectitem",A("#"+C.id+"-selectshow")).length>K){A(A(".selectitem",A("#"+C.id+"-selectshow")).get(K)).remove()}if(A(".selectborder",A("#"+C.id+"-selectshow")).length>K){A(A(".selectborder",A("#"+C.id+"-selectshow")).get(K)).remove()}};this.getValue=function(){return A(".valueshow",A("#"+C.id+"-Text")).html()};this.getText=function(){return A(".textshow",A("#"+C.id+"-Text")).html()};return this.each(I)}})})(jQuery)