(function(a){jQuery.fn.nicedropdowns=function(e){var c=a.extend({},a.fn.nicedropdowns.defaults,e);var b=a(this).length;a(this).each(function(){var k=a(this);var h=a.metadata?a.extend({},c,k.metadata()):c;var p=a(this);p.wrap('<div id="nicedropdown_'+p.attr("id")+'" class="nicedropdown" />');a("#nicedropdown_"+p.attr("id")).addClass(p.attr("class").replace(/{.*}/,"")).css("z-index",b);var i=p.parent(".nicedropdown");i.prepend('<div class="nicedropdown-arrow" />');p.hide();i.prepend('<div class="nicedropdown-info">'+((h.showFlags)?'<img src="'+h.flagPath+((a(this).val()!="-")?a(this).val():h.defaultFlag)+'.png" width="16" height="11" alt="" border="0" /> ':"")+a("#"+a(this).attr("id")+" option:selected").text()+"</div>");if(i.find("option").length>1){i.prepend('<div class="nicedropdown-field" />');i.find("option").each(function(){if(a(this).val()!="-"||(h.removeSelectedFromList&&!a(this).attr("selected"))){i.children(".nicedropdown-field").append('<div class="nicedropdown-row"><input type="hidden" value="'+a(this).val()+'" />'+((h.showFlags)?'<img src="'+h.flagPath+a(this).val()+'.png" width="16" height="11" alt="" border="0" /> ':"")+a(this).text()+"</div>");}});a(".nicedropdown-row").mouseenter(function(){a(this).addClass("nicedropdown-row-hover");}).mouseleave(function(){a(this).removeClass("nicedropdown-row-hover");});i.mouseup(function(r){r.stopPropagation();}).mousedown(function(r){if(a(this).children(".nicedropdown-field").css("display")=="block"){a(this).children(".nicedropdown-field").stop(true,true).slideUp(50);a(this).children(".nicedropdown-arrow").css("backgroundImage",i.find(".nicedropdown-arrow").css("backgroundImage").replace(/-up/,"-down"));}else{a(".nicedropdown-field").hide();a(document).find(".nicedropdown-arrow").css("backgroundImage",i.find(".nicedropdown-arrow").css("backgroundImage").replace(/-up/,"-down"));a(this).children(".nicedropdown-field").stop(true,true).slideDown(50);a(this).children(".nicedropdown-arrow").css("backgroundImage",i.find(".nicedropdown-arrow").css("backgroundImage").replace(/-down/,"-up"));}});i.find(".nicedropdown-row").mousedown(function(r){r.stopPropagation();}).mouseup(function(r){r.stopPropagation();a("#"+p.attr("id")).val(a(this).find("input[type=hidden]").val()).change();i.find(".nicedropdown-info").html(((h.showFlags)?'<img src="'+h.flagPath+a(this).find("input").val()+'.png" width="16" height="11" alt="" border="0" /> ':"")+a(this).text());d(r,i);});if(p.attr("onchange")){p.change(function(){p.attr("onchange");return false;});}}var n=i.find(".nicedropdown-arrow");var j=i.find(".nicedropdown-info");var l=i.find(".nicedropdown-field");if(h.maxWidth>0){var m=parseInt(n.outerWidth());var o=parseInt(h.maxWidth);var q={infopadding:(parseInt(j.outerWidth())-parseInt(j.width()))||0,fieldpadding:(parseInt(l.outerWidth())-parseInt(l.width()))||0};i.width(o);j.width(o-q.infopadding-m);l.width(o-(q.fieldpadding-h.fieldWidthCorrection)-m).hide();}else{var g=((parseInt(j.width())||0)>(parseInt(l.width())||0))?".nicedropdown-info":".nicedropdown-field";var m=parseInt(n.outerWidth());var o=parseInt(i.find(g).outerWidth());var q={infopadding:(parseInt(j.outerWidth())-parseInt(j.width()))||0,fieldpadding:(parseInt(l.outerWidth())-parseInt(l.width()))||0,infoborder:(parseInt(j.css("borderLeftWidth")))?parseInt(j.css("borderLeftWidth")):0+(parseInt(j.css("borderRightWidth")))?parseInt(j.css("borderRightWidth")):0,fieldborder:(parseInt(l.css("borderLeftWidth")))?parseInt(l.css("borderLeftWidth")):0+(parseInt(l.css("borderRightWidth")))?parseInt(l.css("borderRightWidth")):0};var f=(q.infoborder>q.fieldborder)?q.infoborder:q.fieldborder;i.width(o+(q.fieldpadding-f)+m);j.width(o-q.infopadding);l.width(o-(f-h.fieldWidthCorrection)).hide();}b--;});function d(f,g){a(g).children(".nicedropdown-field").stop(true,true).slideUp(50);a(g).children(".nicedropdown-arrow").css("backgroundImage",g.find(".nicedropdown-arrow").css("backgroundImage").replace(/-up/,"-down"));}a(document).mouseup(function(){if(a(this).find(".nicedropdown-field").css("display")=="block"){a(this).find(".nicedropdown-field").stop(true,true).slideUp(10);a(this).find(".nicedropdown-arrow").css("backgroundImage",a(this).find(".nicedropdown-arrow").css("backgroundImage").replace(/-up/,"-down"));}});};jQuery.fn.nicedropdowns.defaults={showFlags:false,defaultFlag:"de",flagPath:"/templates/web/gfx/flags/",maxWidth:0,fieldWidthCorrection:0,removeSelectedFromList:false};})(jQuery);
