(function(f){var u=function(h,l,e){var g=f(h),c=g.attr("selected")||g.val();if(c!=""&&!e.selected)e.selected=c;c=g.attr("title");if(c!="")e.title=c;c=g.outerWidth();var d=g.attr("marginTop");d!==undefined&&(e.marginTop=parseFloat(d));d=g.attr("marginLeft");d!==undefined&&(e.marginLeft=parseFloat(d));d=g.attr("tabIndex");if(f.nodeName(h,"SELECT")){var m=f('<input name="'+h.name+'" id="'+h.id+'" />');g.after(m).remove();g=m}var b=f('<div class="'+i.selector+'" />'),q=null;h.className&&b.addClass(h.className);
b.css("width",c).attr("tabIndex",d||0).css("outline","none");b.mouseover(function(){b.addClass(i.hover);q=window.setTimeout(function(){b.mousedown()},800)}).mouseout(function(){q&&window.clearTimeout(q);b.removeClass(i.hover)});g.css("display","none").after(b);var p=f('<ul class="'+i.dropdown+'"/>'),n=-1,o=-1,s=false,j=[];h=function(){if(!s){q&&clearTimeout(q);b.addClass(i.focus);var a=b.position();p.css({width:b.width()+3,top:a.top+parseInt(b.outerHeight(true))+e.marginTop,left:a.left+e.marginLeft,
display:"block"});s=true;setTimeout(function(){f(document).mousedown(v)},0)}};var w=function(){if(s){f(document).unbind("mousedown",v);b.removeClass(i.focus);s=false;j[n]&&j[n].mouseout();n=-1;p.css("display","none")}},v=function(a){a.target==b[0]||a.target==p[0]||p.find("*").index(a.target)!=-1||w();return true};c=function(a){var t=(a.getAttribute?a.getAttribute("ico"):a.ico)||"noico",k=f('<li class="'+i.item+'" id="dropdown_'+a.value+'"><span class="'+t+'">'+a.text+"</span></li>");j.push(k);var r=
j.length-1;t=typeof a.onselect;var x=t=="string"?function(){eval("(function(value,text){"+a.onselect+"})").call(k[0],a.value,a.text)}:t=="function"?function(){a.onselect.call(k[0],a.value,a.text)}:null;k.click(function(){x&&x();g.val(a.value);b.html(this.innerHTML);if(r!=o){j[o]&&j[o].removeClass(i.selected);typeof e.onchange=="function"&&e.onchange(a.value,a.text);o=r}k.addClass(i.selected);w()}).mouseover(function(){if(n!=r){j[n]&&j[n].mouseout();n=r}k.addClass(i.hover)}).mouseout(function(){k.removeClass(i.hover)}).appendTo(p);
f("*",k).click(function(y){y.stopPropagation();y.preventDefault();k.click()});(a.selected||a.value!=undefined&&a.value==e.selected)&&(o=r)};d=0;for(m=l.length;d<m;d++)c(l[d]);b.mousedown(h).focus(h).after(p);b.find("*").mousedown(function(a){a.stopPropagation();a.preventDefault();b.mousedown()});o==-1?b.html("<span>"+e.title+"</span>"):j[o].click()},i=u.CLASSES={dropdown:"ct_dropdown",hover:"ct_hover",selector:"ct_selector",selected:"ct_selected",item:"ct_item",focus:"ct_focus"};u.CONFIG={title:"Make choice...",
marginTop:1,marginLeft:0,onchange:null,selected:null};f.fn.dropdown=function(h,l){l||(l={});for(var e=0,g=this.length,c=this[0];e<g;c=this[++e])if(!(!c.options&&(!c.name||!l[c.name]))){var d=f.makeArray(c.options),m=f.extend({},u.CONFIG),b=c.name||c.id;if(b){l[b]&&(d=d.concat(l[b]));f.extend(m,h&&h[b]||{})}u(c,d,m)}return this}})(jQuery);
