(function(a){var b="";a.fn.dd=function(f){$this=this;f=a.extend({height:120,visibleRows:4,rowHeight:23,showIcon:true,zIndex:9999,style:""},f);var q="",g={};g.insideWindow=true;g.keyboardAction=false;g.currentKey=null;var h=false;config={postElementHolder:"_msddHolder",postID:"_msdd",postTitleID:"_title",postTitleTextID:"_titletext",postChildID:"_child",postAID:"_msa",postOPTAID:"_msopta",postInputID:"_msinput",postArrowID:"_arrow",postInputhidden:"_inp"};styles={dd:"dd",ddTitle:"ddTitle",arrow:"arrow",ddChild:"ddChild",disabled:.5};attributes={actions:"onfocus,onblur,onchange,onclick,ondblclick,onmousedown,onmouseup,onmouseover,onmousemove,onmouseout,onkeypress,onkeydown,onkeyup",prop:"size,multiple,disabled,tabindex"};var c=a(this).attr("id"),t=a(this).attr("style");f.style+=t==undefined?"":t;var k=a(this).children();h=a(this).attr("size")>0||a(this).attr("multiple")==true?true:false;if(h)f.visibleRows=a(this).attr("size");var e={};B();function d(a){return c+config[a]}function n(c){var b=c,d=a(b).attr("style");return d}function s(e){var b=a("#"+c+" option:selected");if(b.length>1){for(var d=0;d<b.length;d++)if(e==b[d].index)return true}else if(b.length==1)if(b[0].index==e)return true;return false}function r(){var c=k,b="",g=d("postAID"),f=d("postOPTAID");c.each(function(i){var d=c[i];if(d.nodeName=="OPTGROUP"){b+="<div class='opta'>";b+="<span style='font-weight:bold;font-style:italic; clear:both;'>"+a(d).attr("label")+"</span>";var o=a(d).children();o.each(function(k){var c=o[k],h=f+"_"+i+"_"+k,d=a(c).attr("title");d=d.length==0?"":'<img src="'+d+'" align="left" /> ';var g=a(c).text(),m=a(c).val(),j=a(c).attr("disabled")==true?"disabled":"enabled";e[h]={html:d+g,value:m,text:g,index:c.index,id:h};var l=n(c);if(s(c.index)==true)b+='<a href="#" class="selected '+j+'"';else b+='<a  href="#" class="'+j+'"';if(l!=false)b+=' style="'+l+'"';b+=' id="'+h+'">';b+=d+g+"</a>"});b+="</div>"}else{var k=g+"_"+i,h=a(d).attr("title");h=h.length==0?"":'<img src="'+h+'" align="left" /> ';var j=a(d).text(),p=a(d).val(),l=a(d).attr("disabled")==true?"disabled":"enabled";e[k]={html:h+j,value:p,text:j,index:d.index,id:k};var m=n(d);if(s(d.index)==true)b+='<a href="#" class="selected '+l+'"';else b+='<a  href="#" class="'+l+'"';if(m!=false)b+=' style="'+m+'"';b+=' id="'+k+'">';b+=h+j+"</a>"}});return b}function A(){var c=d("postID"),b=d("postChildID"),a=f.style;sDiv="";sDiv+='<div id="'+b+'" class="'+styles.ddChild+'"';if(!h)sDiv+=a!=""?' style="'+a+'"':"";else sDiv+=a!=""?' style="border-top:1px solid #c3c3c3;display:block;position:relative;'+a+'"':"";sDiv+=">";return sDiv}function C(){var i=d("postTitleID"),h=d("postArrowID"),g=d("postTitleTextID"),k=d("postInputhidden"),j=a("#"+c+" option:selected").text(),b=a("#"+c+" option:selected").attr("title");b=b.length==0||b==undefined||f.showIcon==false?"":'<img src="'+b+'" align="left" /> ';var e='<div id="'+i+'" class="'+styles.ddTitle+'"';e+=">";e+='<span id="'+h+'" class="'+styles.arrow+'"></span><span class="textTitle" id="'+g+'">'+b+j+"</span></div>";return e}function p(){var j=d("postTitleID"),i=d("postArrowID"),e=d("postTitleTextID"),h=d("postInputhidden"),g=a("#"+c+" option:selected").text(),b=a("#"+c+" option:selected").attr("title");b=b.length==0||b==undefined||f.showIcon==false?"":'<img src="'+b+'" align="left" /> ';a("#"+e).html(b+g)}function D(){var e=d("postID"),b=d("postChildID");k=a("#"+c).children();a("#"+b).html(r());p();if(k.length>f.visibleRows){var h=parseInt(a("#"+b+" a:first").css("padding-bottom"))+parseInt(a("#"+b+" a:first").css("padding-top")),g=f.rowHeight*f.visibleRows-h;a("#"+b).css("height",g+"px")}if(a("#"+c).attr("disabled")==true)a("#"+e).css("opacity",styles.disabled);else a("#"+e).css("opacity","1")}function B(){var s=false,n=d("postID"),q=d("postTitleID"),I=d("postTitleTextID"),b=d("postChildID"),J=d("postArrowID"),K=a("#"+c).width(),t=a("#"+c).attr("class"),x=f.style;if(a("#"+n).length>0){a("#"+n).remove();s=true}a("#"+c).bind("change",function(){p()});a("#"+c).bind("focus",function(){v()});a("#"+c).bind("blur",function(){i();l()});a("#"+c).bind("optionsChanged",function(){D()});var e='<div id="'+n+'" class="'+styles.dd+'"';e+=x!=""?' style="'+x+'"':"";e+=">";if(!h)e+=C();e+=A();e+=r();e+="</div>";e+="</div>";if(s==true){var H=d("postElementHolder");a("#"+H).after(e)}else a("#"+c).after(e);a("#"+n).addClass(t);a("#"+b).addClass(t);if(k.length>f.visibleRows){var B=parseInt(a("#"+b+" a:first").css("padding-bottom"))+parseInt(a("#"+b+" a:first").css("padding-top")),y=f.rowHeight*f.visibleRows-B;a("#"+b).css("height",y+"px")}if(s==false){E();F(c)}if(a("#"+c).attr("disabled")==true)a("#"+n).css("opacity",styles.disabled);else{G();if(!h){a("#"+q).bind("mouseover",function(){o(1)});a("#"+q).bind("mouseout",function(){o(0)})}a("#"+b+" a.enabled").live("click",function(c){c.preventDefault();z(this);if(!h){a("#"+b).unbind("mouseover");j(false);var d=f.showIcon==false?a(this).text():a(this).html();m(d);l()}i()});a("#"+b+" a.disabled").css("opacity",styles.disabled);h&&a("#"+b).bind("mouseover",function(){if(!g.keyboardAction){g.keyboardAction=true;a(document).bind("keydown",function(b){var a=b.keyCode;g.currentKey=a;if(a==39||a==40){b.preventDefault();b.stopPropagation();w();i()}if(a==37||a==38){b.preventDefault();b.stopPropagation();u();i()}})}});a("#"+b).bind("mouseout",function(){j(false);a(document).unbind("keydown");g.keyboardAction=false;g.currentKey=null});!h&&a("#"+q).bind("click",function(){j(false);if(a("#"+b+":visible").length==1)a("#"+b).unbind("mouseover");else{a("#"+b).bind("mouseover",function(){j(true)});v()}});a("#"+q).bind("mouseout",function(){j(false)})}}function H(b){for(var a in e)if(e[a].index==b)return e[a]}function z(b){var f=d("postChildID");!h&&a("#"+f+" a.selected").removeClass("selected");var k=a("#"+f+" a.selected").attr("id");if(k!=undefined)var l=g.oldIndex==undefined||g.oldIndex==null?e[k].index:g.oldIndex;b&&!h&&a(b).addClass("selected");if(h){var m=g.currentKey;if(a("#"+c).attr("multiple")==true)if(m==17){g.oldIndex=e[a(b).attr("id")].index;a(b).toggleClass("selected")}else if(m==16){a("#"+f+" a.selected").removeClass("selected");a(b).addClass("selected");for(var n=a(b).attr("id"),j=e[n].index,i=Math.min(l,j);i<=Math.max(l,j);i++)a("#"+H(i).id).addClass("selected")}else{a("#"+f+" a.selected").removeClass("selected");a(b).addClass("selected");g.oldIndex=e[a(b).attr("id")].index}else{a("#"+f+" a.selected").removeClass("selected");a(b).addClass("selected");g.oldIndex=e[a(b).attr("id")].index}}}function F(b){document.getElementById(b).refresh=function(){a("#"+this.id).dd(f)}}function j(a){g.insideWindow=a}function y(){return g.insideWindow}function G(){for(var b=d("postID"),f=attributes.actions.split(","),e=0;e<f.length;e++){var g=f[e],h=a("#"+c).attr(g);if(h!=undefined)switch(g){case"onfocus":a("#"+b).bind("mouseenter",function(){document.getElementById(c).focus()});break;case"onclick":a("#"+b).bind("click",function(){document.getElementById(c).onclick()});break;case"ondblclick":a("#"+b).bind("dblclick",function(){document.getElementById(c).ondblclick()});break;case"onmousedown":a("#"+b).bind("mousedown",function(){document.getElementById(c).onmousedown()});break;case"onmouseup":a("#"+b).bind("mouseup",function(){document.getElementById(c).onmouseup()});break;case"onmouseover":a("#"+b).bind("mouseover",function(){document.getElementById(c).onmouseover()});break;case"onmousemove":a("#"+b).bind("mousemove",function(){document.getElementById(c).onmousemove()});break;case"onmouseout":a("#"+b).bind("mouseout",function(){document.getElementById(c).onmouseout()})}}}function E(){var b=d("postElementHolder");a("#"+c).after("<div style='height:0px;overflow:hidden;position:absolute;' id='"+b+"'></div>");a("#"+c).appendTo(a("#"+b))}function m(c){var b=d("postTitleTextID");a("#"+b).html(c)}function w(){for(var l=d("postTitleTextID"),c=d("postChildID"),i=a("#"+c+" a.enabled"),g=0;g<i.length;g++){var j=i[g],n=a(j).attr("id");if(a(j).hasClass("selected")&&g<i.length-1){a("#"+c+" a.selected").removeClass("selected");a(i[g+1]).addClass("selected");var b=a("#"+c+" a.selected").attr("id");if(!h){var k=f.showIcon==false?e[b].text:e[b].html;m(k)}parseInt(a("#"+b).position().top+a("#"+b).height())>=parseInt(a("#"+c).height())&&a("#"+c).scrollTop(a("#"+c).scrollTop()+a("#"+b).height()+a("#"+b).height());break}}}function u(){for(var l=d("postTitleTextID"),b=d("postChildID"),i=a("#"+b+" a.enabled"),g=0;g<i.length;g++){var j=i[g],n=a(j).attr("id");if(a(j).hasClass("selected")&&g!=0){a("#"+b+" a.selected").removeClass("selected");a(i[g-1]).addClass("selected");var c=a("#"+b+" a.selected").attr("id");if(!h){var k=f.showIcon==false?e[c].text:e[c].html;m(k)}parseInt(a("#"+c).position().top+a("#"+c).height())<=0&&a("#"+b).scrollTop(a("#"+b).scrollTop()-a("#"+b).height()-a("#"+c).height());break}}}function i(){var g=d("postChildID"),b=a("#"+g+" a.selected");if(b.length==1){var k=a("#"+g+" a.selected").text(),f=a("#"+g+" a.selected").attr("id");if(f!=undefined){var j=e[f].value;document.getElementById(c).selectedIndex=e[f].index}}else if(b.length>1)for(var l=a("#"+c+" > option:selected").removeAttr("selected"),h=0;h<b.length;h++){var f=a(b[h]).attr("id"),i=e[f].index;document.getElementById(c).options[i].selected="selected"}}function v(){var g=d("postChildID");if(b!=""&&g!=b){a("#"+b).slideUp("fast");a("#"+b).css({zIndex:"0"})}if(a("#"+g).css("display")=="none"){q=e[a("#"+g+" a.selected").attr("id")].text;a(document).bind("keydown",function(d){var b=d.keyCode;if(b==39||b==40){d.preventDefault();d.stopPropagation();w()}if(b==37||b==38){d.preventDefault();d.stopPropagation();u()}if(b==27||b==13){l();i()}a("#"+c).attr("onkeydown")!=undefined&&document.getElementById(c).onkeydown()});a(document).bind("keyup",function(){a("#"+c).attr("onkeyup")!=undefined&&document.getElementById(c).onkeyup()});a(document).bind("mouseup",function(){y()==false&&l()});a("#"+g).css({zIndex:f.zIndex});a("#"+g).slideDown("fast");setTimeout(function(){try{a("#"+g)[0].scrollTop=a("#"+g+" a.selected")[0].offsetTop}catch(b){}},100);if(g!=b)b=g}}function l(){var b=d("postChildID");a(document).unbind("keydown");a(document).unbind("keyup");a(document).unbind("mouseup");a("#"+b).slideUp("fast",function(){x();a("#"+b).css({zIndex:"0"})})}function x(){var f=d("postChildID");if(a("#"+c).attr("onchange")!=undefined){var b=e[a("#"+f+" a.selected").attr("id")].text;q!=b&&document.getElementById(c).onchange()}a("#"+c).attr("onmouseup")!=undefined&&document.getElementById(c).onmouseup();a("#"+c).attr("onblur")!=undefined&&a(document).bind("mouseup",function(){a("#"+c).focus();a("#"+c)[0].blur();i();a(document).unbind("mouseup")})}function o(c){var b=d("postArrowID");if(c==1)a("#"+b).css({backgroundPosition:"0 100%"});else a("#"+b).css({backgroundPosition:"0 0"})}};a.fn.msDropDown=function(c){for(var d=a(this),b=0;b<d.length;b++){var e=a(d[b]).attr("id");if(c==undefined)a("#"+e).dd();else a("#"+e).dd(c)}}})(jQuery);