/**
 * Select Multiple List
 *
 * @Author	:	Frederik Buus Sauer
 * @Company	:	Dwarf A/S
 * @Version	:	1.0
 * @Date	:	01-01-2012
 *
 **/
(function($){$.fn.selectMultipleList=function(d){var a=$.extend({sortValue:true,sortAsc:true,sortNum:true,sortCustom:null,titleList:"All",titleSelected:"Selected",formName:null,classPrefix:"sml"},d),b={numeric:function(g,f){var i=parseFloat(a.sortValue?g.value:g.name),h=parseFloat(a.sortValue?f.value:f.name);if(a.sortAsc){return i-h}else{return h-i}},alpha:function(h,g){var j=(a.sortValue?h.value:h.name).toLowerCase(),i=(a.sortValue?g.value:g.name).toLowerCase(),f=0;if(j<i){f=-1}else{if(j>i){f=1}}if(!a.sortAsc){f*=-1}return f}},c={elem:null,name:null,arrOpts:null,arrList:null,arrSelected:null},e={setupOptions:function(){c.arrOpts=[];$("option",c.elem).each(function(){var f=$(this);if(f.is(":enabled")){c.arrOpts.push({name:f.text(),value:f.val(),selected:f.is(":selected")})}});if($.isFunction(a.sortCustom)){c.arrOpts.sort(a.sortCustom)}else{c.arrOpts.sort(a.sortNum?b.numeric:b.alpha)}},setupHTML:function(){var h=a.classPrefix,m,g,l=$("<div/>",{"class":h+"-main-"+c.name}),i=$("<div/>",{"class":h+"-container-list"}).appendTo(l),n=$("<div/>",{"class":h+"-container-selected"}).appendTo(l),f=$("<div/>",{"class":h+"-container-input"}).appendTo(l),j=$("<div/>",{"class":h+"-select-list"}).appendTo(i),k=$("<div/>",{"class":h+"-select-selected"}).appendTo(n);$("<span/>",{"class":h+"-title-list",html:a.titleList}).insertBefore(j);$("<span/>",{"class":h+"-title-selected",html:a.titleSelected}).insertBefore(k);c.arrList=j;c.arrSelected=k;for(m in c.arrOpts){g=c.arrOpts[m];g.input=$('<input type="hidden" />').attr({"class":h+"-input",value:g.value,name:g.selected?c.name+"[]":undefined}).appendTo(f);$("<span/>",{"class":h+"-choice",unselectable:"on",text:g.name}).data("sml-index",m).hover(function(){$(this).addClass(h+"-choice-hover")},function(){$(this).removeClass(h+"-choice-hover")}).click(function(){var r=$(this).detach().removeClass(h+"-choice-hover"),p,o=r.data("sml-index"),q=c.arrOpts[o];q.selected=!q.selected;if(q.selected){q.input.attr("name",c.name+"[]");p=c.arrSelected}else{q.input.removeAttr("name");p=c.arrList}$("span",p).each(function(){var s=$(this),t=s.data("sml-index");if(o-t<0){s.before(r);return false}});if(r.parent().length==0){r.appendTo(p)}}).appendTo(g.selected?k:j)}c.elem.after(l)},init:function(){c.name=typeof a.formName=="string"?a.formName:c.elem.attr("name");c.name=c.name.replace(/\[\]/g,"");if(c.name){e.setupOptions();e.setupHTML();c.elem.remove()}else{var f="The select element with ID '"+c.elem.attr("id")+"' and class '"+c.elem.attr("class")+"' does not have a name attribute!";if(typeof console!="undefined"){console.log(f)}else{alert(f)}}}};c.elem=this;e.init()}})(jQuery);

