jQuery.fn.selectbox=function(e){var f={className:"jquery-selectbox",animationSpeed:"normal",listboxMaxSize:10,replaceInvisible:false};var g="jquery-custom-selectboxes-replaced";var d=false;var c=function(i){var h=i.parents("."+f.className+"");i.slideDown(f.animationSpeed,function(){d=true});h.addClass("selecthover");jQuery(document).bind("click",b);return i};var a=function(i){var h=i.parents("."+f.className+"");i.slideUp(f.animationSpeed,function(){d=false;jQuery(this).parents("."+f.className+"").removeClass("selecthover")});jQuery(document).unbind("click",b);return i};var b=function(j){var h=j.target;var i=jQuery("."+f.className+"-list:visible").parent().find("*").andSelf();if(jQuery.inArray(h,i)<0&&d){a(jQuery("."+g+"-list"))}return false};f=jQuery.extend(f,e||{});return this.each(function(){var l=jQuery(this);if(l.filter(":visible").length==0&&!f.replaceInvisible){return}var j=jQuery('<div class="'+f.className+" "+g+'"><div class="'+f.className+'-moreButton" /><div class="'+f.className+"-list "+g+'-list" /><span class="'+f.className+'-currentItem" /></div>');jQuery("option",l).each(function(n,m){var m=jQuery(m);var o=jQuery('<span class="'+f.className+"-item value-"+m.val()+" item-"+n+'">'+m.text()+"</span>");o.click(function(){var s=jQuery(this);var r=s.parents("."+f.className);var t=s[0].className.split(" ");for(k1 in t){if(/^item-[0-9]+$/.test(t[k1])){t=parseInt(t[k1].replace("item-",""),10);break}}var p=s[0].className.split(" ");for(k1 in p){if(/^value-.+$/.test(p[k1])){p=p[k1].replace("value-","");break}}r.find("."+f.className+"-currentItem").text(s.text());r.find("select").val(p).triggerHandler("change");var q=r.find("."+f.className+"-list");if(q.filter(":visible").length>0){a(q)}else{c(q)}}).bind("mouseenter",function(){jQuery(this).addClass("listelementhover")}).bind("mouseleave",function(){jQuery(this).removeClass("listelementhover")});jQuery("."+f.className+"-list",j).append(o);if(m.filter(":selected").length>0){jQuery("."+f.className+"-currentItem",j).text(m.text())}});j.find("."+f.className+"-moreButton").click(function(){var o=jQuery(this);var n=jQuery("."+f.className+"-list").not(o.siblings("."+f.className+"-list"));a(n);var m=o.siblings("."+f.className+"-list");if(m.filter(":visible").length>0){a(m)}else{c(m)}}).bind("mouseenter",function(){jQuery(this).addClass("morebuttonhover")}).bind("mouseleave",function(){jQuery(this).removeClass("morebuttonhover")});l.hide().replaceWith(j).appendTo(j);var k=j.find("."+f.className+"-list");var h=k.find("."+f.className+"-item").length;if(h>f.listboxMaxSize){h=f.listboxMaxSize}if(h==0){h=1}var i=Math.round(l.width()+5);if(jQuery.browser.safari){i=i*0.94}j.css("width",i+"px");k.css({width:Math.round(i)+"px",height:(h)+"em"})})};jQuery.fn.unselectbox=function(){var a="jquery-custom-selectboxes-replaced";return this.each(function(){var b=jQuery(this).filter("."+a);b.replaceWith(b.find("select").show())})};
