!function(a,b,c,d){a.fn.dropdown=function(b){var e,f=a(this),g=a(c),h=f.selector||"",i="ontouchstart"in c.documentElement,j=(new Date).getTime(),k=[],l=arguments[0],m="string"==typeof l,n=[].slice.call(arguments,1);return f.each(function(){var c,o=a.isPlainObject(b)?a.extend(!0,{},a.fn.dropdown.settings,b):a.extend({},a.fn.dropdown.settings),p=o.className,q=o.metadata,r=o.namespace,s=o.selector,t=o.error,u="."+r,v="module-"+r,w=a(this),x=w.find(s.text),y=w.find(s.search),z=w.find(s.input),A=w.prev().find(s.text).size()>0?w.prev().find(s.text):w.prev(),B=w.children(s.menu),C=B.find(s.item),D=!1,E=this,F=w.data(v);c={initialize:function(){c.debug("Initializing dropdown",o),c.setup.layout(),c.save.defaults(),c.set.selected(),i&&c.bind.touchEvents(),c.bind.mouseEvents(),c.bind.keyboardEvents(),c.instantiate()},instantiate:function(){c.verbose("Storing instance of dropdown",c),F=c,w.data(v,c)},destroy:function(){c.verbose("Destroying previous dropdown for",w),C.off(u),w.off(u).removeData(v)},setup:{layout:function(){w.is("select")&&c.setup.select(),c.is.search()&&!c.is.searchable()&&(y=a("").addClass(p.search).insertBefore(x)),c.is.searchable()?(c.debug("Searchable dropdown initialized"),y.val("").attr("tabindex",0),B.attr("tabindex","-1")):(c.debug("Simple selection dropdown initialized"),w.attr("tabindex")||(w.attr("tabindex",0),B.attr("tabindex","-1")))},select:function(){c.debug("Dropdown initialized on a select, generating html"),z=w,w=a("
").attr("class",z.attr("class")).addClass(p.selection).html(o.templates.select(c.get.selectValues())).insertBefore(z),z.removeAttr("class").prependTo(w),c.refresh()}},refresh:function(){x=w.find(s.text),y=w.find(s.search),z=w.find(s.input),B=w.children(s.menu),C=B.find(s.item)},bind:{keyboardEvents:function(){c.debug("Binding keyboard events"),w.on("keydown"+u,c.event.keydown),c.is.searchable()?(y.on("focus"+u,c.event.searchFocus).on(c.get.inputEvent(),c.event.input),w.on("blur"+u,c.event.blur)):w.on("mousedown",c.event.mousedown).on("mouseup",c.event.mouseup).on("focus"+u,c.event.focus).on("blur"+u,c.event.blur)},touchEvents:function(){c.debug("Touch device detected binding touch events"),c.is.searchable()||w.on("touchstart"+u,c.event.test.toggle),C.on("touchstart"+u,c.event.item.mouseenter).on("touchstart"+u,c.event.item.click)},mouseEvents:function(){c.verbose("Mouse detected binding mouse events"),c.is.searchable()||("click"==o.on?w.on("click"+u,c.event.test.toggle):"hover"==o.on?w.on("mouseenter"+u,c.delay.show).on("mouseleave"+u,c.delay.hide):w.on(o.on+u,c.toggle)),C.on("mouseenter"+u,c.event.item.mouseenter).on("mouseleave"+u,c.event.item.mouseleave).on("click"+u,c.event.item.click)},intent:function(){c.verbose("Binding hide intent event to document"),i&&g.on("touchstart"+u,c.event.test.touch).on("touchmove"+u,c.event.test.touch),g.on("click"+u,c.event.test.hide)}},unbind:{intent:function(){c.verbose("Removing hide intent event from document"),i&&g.off("touchstart"+u).off("touchmove"+u),g.off("click"+u)}},filter:function(b){var c,e=a(),f=new RegExp("(?:s|^)"+b,"i"),g=new RegExp(b,"i");C.each(function(){var b=a(this),c=b.data(q.text)!==d?b.data(q.text):o.preserveHTML?b.html():b.text(),h=b.data(q.value)!==d?b.data(q.value):"string"==typeof c?c.toLowerCase():c;f.test(c)||f.test(h)?e=e.add(b):o.fullTextSearch&&(g.test(c)||g.test(h))&&(e=e.add(b))}),c=C.not(e),C.removeClass(p.filtered).removeClass(p.selected),c.addClass(p.filtered),C.not("."+p.filtered).eq(0).addClass(p.selected)},event:{mousedown:function(){D=!0},mouseup:function(){D=!1},focus:function(){D||c.show()},searchFocus:function(){D=!0,c.show()},blur:function(a){D=!1,c.determine.eventInModule(a,c.hide)},input:function(){var a=y.val();x.addClass(p.filtered),c.filter(a)},keydown:function(b){var d,e=C.not(p.filtered).filter("."+p.selected).eq(0),f=C.not("."+p.filtered),g=b.which,h={enter:13,escape:27,upArrow:38,downArrow:40},i=p.selected,j=f.index(e),k=e.size()>0;if(k||(e=C.filter("."+p.active).eq(0),k=e.size()>0),g==h.escape&&(c.verbose("Escape key pressed, closing dropdown"),y.blur(),c.hide()),c.is.visible()){if(g==h.enter&&k)return c.verbose("Enter key pressed, choosing selected item"),c.is.searchable()&&(c.verbose("Removing focus from search input"),y.blur()),a.proxy(c.event.item.click,e)(b),b.preventDefault(),!1;g==h.upArrow?(d=k?e.prevAll(s.item+":not(."+p.filtered+")").eq(0):f.eq(0),0!==j&&(c.verbose("Up key pressed, changing active item"),C.removeClass(i),d.addClass(i),c.set.scrollPosition(d)),b.preventDefault()):g==h.downArrow&&(d=k?e.nextAll(s.item+":not(."+p.filtered+")").eq(0):f.eq(0),j+10&&(clearTimeout(c.itemTimer),c.itemTimer=setTimeout(function(){c.animate.hide(!1,e),c.verbose("Showing sub-menu",d),c.animate.show(!1,d)},2*o.delay.show),b.preventDefault())},mouseleave:function(){var b=a(this).find(s.menu);b.size()>0&&(clearTimeout(c.itemTimer),c.itemTimer=setTimeout(function(){c.verbose("Hiding sub-menu",b),c.animate.hide(!1,b)},o.delay.hide))},click:function(b){var e=a(this),f=e.data(q.text)!==d?e.data(q.text):o.preserveHTML?e.html():e.text(),g=e.data(q.value)!==d?e.data(q.value):"string"==typeof f?f.toLowerCase():f,h=function(){y.val(""),c.determine.selectAction(f,g),a.proxy(o.onChange,E)(g,f)},i=e.find(s.menu).size()>0;i||("touchstart"==b.type?e.one("click",h):h())}},resetStyle:function(){a(this).removeAttr("style")}},determine:{selectAction:function(b,d){c.verbose("Determining action",o.action),a.isFunction(c.action[o.action])?(c.verbose("Triggering preset action",o.action,b,d),c.action[o.action](b,d)):a.isFunction(o.action)?(c.verbose("Triggering user action",o.action,b,d),o.action(b,d)):c.error(t.action,o.action)},eventInModule:function(b,d){return d=d||function(){},0===a(b.target).closest(w).size()?(c.verbose("Triggering event",d),d(),!0):(c.verbose("Event occurred in dropdown, canceling callback"),!1)},eventInMenu:function(b,d){return d=d||function(){},0===a(b.target).closest(B).size()?(c.verbose("Triggering event",d),d(),!0):(c.verbose("Event occurred in dropdown menu, canceling callback"),!1)}},action:{nothing:function(){},hide:function(){c.hide()},select:function(a,b){b=b!==d?b:a,c.set.selected(b),c.set.value(b),c.hide()},activate:function(a,b){b=b!==d?b:a,c.set.selected(b),c.set.value(b),c.hide()},combo:function(a,b){b=b!==d?b:a,c.set.selected(b),c.set.value(b),c.hide()},auto:function(a,b){b=b!==d?b:a,c.set.selected(b),c.set.value(b),c.hide()},changeText:function(a,b){b=b!==d?b:a,c.set.selected(b),c.hide()},updateForm:function(a,b){b=b!==d?b:a,c.set.selected(b),c.set.value(b),c.hide()}},get:{text:function(){return x.text()},value:function(){return z.size()>0?z.val():w.data(q.value)},inputEvent:function(){var a=y[0];return a?a.oninput!==d?"input":a.onpropertychange!==d?"propertychange":"keyup":!1},selectValues:function(){var b={values:{}};return w.find("option").each(function(){var c=a(this).html(),e=a(this).attr("value")!==d?a(this).attr("value"):c;""===e?b.placeholder=c:b.values[e]=c}),c.debug("Retrieved values from select",b),b},item:function(b,e){var f=!1;return b=b!==d?b:c.get.value()!==d?c.get.value():c.get.text(),e=""===b?!0:e||!1,b!==d?C.each(function(){var g=a(this),h=g.data(q.text)!==d?g.data(q.text):o.preserveHTML?g.html():g.text(),i=g.data(q.value)!==d?g.data(q.value):"string"==typeof h?h.toLowerCase():h;e?(c.debug("Ambiguous dropdown value using strict type check",b),i===b?f=a(this):f||h!==b||(f=a(this))):i==b?f=a(this):f||h!=b||(f=a(this))}):b=c.get.text(),f||!1}},restore:{defaults:function(){c.restore.defaultText(),c.restore.defaultValue()},defaultText:function(){var a=w.data(q.defaultText);c.debug("Restoring default text",a),c.set.text(a)},defaultValue:function(){var a=w.data(q.defaultValue);a!==d&&(c.debug("Restoring default value",a),c.set.selected(a),c.set.value(a))}},save:{defaults:function(){c.save.defaultText(),c.save.defaultValue()},defaultValue:function(){w.data(q.defaultValue,c.get.value())},defaultText:function(){w.data(q.defaultText,x.text())}},set:{scrollPosition:function(a){var b,d,e,f,g,h,i,j,a=a||c.get.item(),k=a&&a.size()>0,l=5;a&&k&&(h=B.height(),d=a.height(),g=B.scrollTop(),f=B.offset().top,e=a.offset().top,b=g-f+e,j=b+l>g+h,i=g>b-l,(i||j)&&(c.debug("Scrolling to active item"),B.scrollTop(b)))},text:function(a){"combo"==o.action?(c.debug("Changing combo button text",a,A),o.preserveHTML?A.html(a):A.text(a)):"select"!==o.action&&(c.debug("Changing text",a,x),x.removeClass(p.filtered).removeClass(p.placeholder),o.preserveHTML?x.html(a):x.text(a))},value:function(a){c.debug("Adding selected value to hidden input",a,z),z.size()>0?z.val(a).trigger("change"):w.data(q.value,a)},active:function(){w.addClass(p.active)},visible:function(){w.addClass(p.visible)},selected:function(a){var b,e=c.get.item(a);e&&(c.debug("Setting selected menu item to",e),b=e.data(q.text)!==d?e.data(q.text):o.preserveHTML?e.html():e.text(),C.removeClass(p.active).removeClass(p.selected),e.addClass(p.active).addClass(p.selected),c.set.text(b))}},remove:{active:function(){w.removeClass(p.active)},visible:function(){w.removeClass(p.visible)}},is:{search:function(){return w.hasClass(p.search)},searchable:function(){return y.size()>0},selection:function(){return w.hasClass(p.selection)},animated:function(a){return a?a.is(":animated")||a.transition&&a.transition("is animating"):B.is(":animated")||B.transition&&B.transition("is animating")},visible:function(a){return a?a.is(":visible"):B.is(":visible")},hidden:function(a){return a?a.is(":hidden"):B.is(":hidden")}},can:{click:function(){return i||"click"==o.on},show:function(){return!w.hasClass(p.disabled)}},animate:{show:function(b,e){var f=e||B;b=b||function(){},c.is.hidden(f)&&(c.verbose("Doing menu show animation",f),"none"==o.transition?a.proxy(b,E)():a.fn.transition!==d&&w.transition("is supported")?f.transition({animation:o.transition+" in",duration:o.duration,queue:!0,complete:function(){a.proxy(b,E)()}}):"slide down"==o.transition?f.hide().clearQueue().children().clearQueue().css("opacity",0).delay(50).animate({opacity:1},o.duration,"easeOutQuad",c.event.resetStyle).end().slideDown(100,"easeOutQuad",function(){a.proxy(c.event.resetStyle,this)(),a.proxy(b,E)()}):"fade"==o.transition?f.hide().clearQueue().fadeIn(o.duration,function(){a.proxy(c.event.resetStyle,this)(),a.proxy(b,E)()}):c.error(t.transition,o.transition))},hide:function(b,e){var f=e||B;b=b||function(){},c.is.visible(f)&&(c.verbose("Doing menu hide animation",f),"none"==o.transition?a.proxy(b,E)():a.fn.transition!==d&&w.transition("is supported")?f.transition({animation:o.transition+" out",duration:o.duration,queue:!0,complete:function(){a.proxy(b,E)()}}):"slide down"==o.transition?f.show().clearQueue().children().clearQueue().css("opacity",1).animate({opacity:0},100,"easeOutQuad",c.event.resetStyle).end().delay(50).slideUp(100,"easeOutQuad",function(){a.proxy(c.event.resetStyle,this)(),a.proxy(b,E)()}):"fade"==o.transition?f.show().clearQueue().fadeOut(150,function(){a.proxy(c.event.resetStyle,this)(),a.proxy(b,E)()}):c.error(t.transition))}},show:function(){c.debug("Checking if dropdown can show"),c.is.hidden()&&(c.hideOthers(),c.set.active(),c.set.scrollPosition(),c.animate.show(function(){c.can.click()&&c.bind.intent(),c.set.visible()}),a.proxy(o.onShow,E)())},hide:function(){!c.is.animated()&&c.is.visible()&&(c.debug("Hiding dropdown"),c.can.click()&&c.unbind.intent(),c.remove.active(),c.animate.hide(function(){C.removeClass(p.filtered),c.remove.visible()}),a.proxy(o.onHide,E)())},delay:{show:function(){c.verbose("Delaying show event to ensure user intent"),clearTimeout(c.timer),c.timer=setTimeout(c.show,o.delay.show)},hide:function(){c.verbose("Delaying hide event to ensure user intent"),clearTimeout(c.timer),c.timer=setTimeout(c.hide,o.delay.hide)}},hideOthers:function(){c.verbose("Finding other dropdowns to hide"),f.not(w).has(s.menu+":visible").dropdown("hide")},toggle:function(){c.verbose("Toggling menu visibility"),c.is.hidden()?c.show():c.hide()},setting:function(b,e){if(c.debug("Changing setting",b,e),a.isPlainObject(b))a.extend(!0,o,b);else{if(e===d)return o[b];o[b]=e}},internal:function(b,e){if(a.isPlainObject(b))a.extend(!0,c,b);else{if(e===d)return c[b];c[b]=e}},debug:function(){o.debug&&(o.performance?c.performance.log(arguments):(c.debug=Function.prototype.bind.call(console.info,console,o.name+":"),c.debug.apply(console,arguments)))},verbose:function(){o.verbose&&o.debug&&(o.performance?c.performance.log(arguments):(c.verbose=Function.prototype.bind.call(console.info,console,o.name+":"),c.verbose.apply(console,arguments)))},error:function(){c.error=Function.prototype.bind.call(console.error,console,o.name+":"),c.error.apply(console,arguments)},performance:{log:function(a){var b,d,e;o.performance&&(b=(new Date).getTime(),e=j||b,d=b-e,j=b,k.push({Element:E,Name:a[0],Arguments:[].slice.call(a,1)||"","Execution Time":d})),clearTimeout(c.performance.timer),c.performance.timer=setTimeout(c.performance.display,100)},display:function(){var b=o.name+":",e=0;j=!1,clearTimeout(c.performance.timer),a.each(k,function(a,b){e+=b["Execution Time"]}),b+=" "+e+"ms",h&&(b+=" '"+h+"'"),(console.group!==d||console.table!==d)&&k.length>0&&(console.groupCollapsed(b),console.table?console.table(k):a.each(k,function(a,b){console.log(b.Name+": "+b["Execution Time"]+"ms")}),console.groupEnd()),k=[]}},invoke:function(b,f,g){var h,i,j,k=F;return f=f||n,g=E||g,"string"==typeof b&&k!==d&&(b=b.split(/[\. ]/),h=b.length-1,a.each(b,function(e,f){var g=e!=h?f+b[e+1].charAt(0).toUpperCase()+b[e+1].slice(1):b;if(a.isPlainObject(k[g])&&e!=h)k=k[g];else{if(k[g]!==d)return i=k[g],!1;if(!a.isPlainObject(k[f])||e==h)return k[f]!==d?(i=k[f],!1):(c.error(t.method,b),!1);k=k[f]}})),a.isFunction(i)?j=i.apply(g,f):i!==d&&(j=i),a.isArray(e)?e.push(j):e!==d?e=[e,j]:j!==d&&(e=j),i}},m?(F===d&&c.initialize(),c.invoke(l)):(F!==d&&c.destroy(),c.initialize())}),e!==d?e:this},a.fn.dropdown.settings={name:"Dropdown",namespace:"dropdown",debug:!1,verbose:!0,performance:!0,type:!1,on:"click",action:"activate",fullTextSearch:!0,preserveHTML:!0,delay:{show:200,hide:300,touch:50},transition:"slide down",duration:250,onChange:function(){},onShow:function(){},onHide:function(){},error:{action:"You called a dropdown action that was not defined",method:"The method you called is not defined.",transition:"The requested transition was not found"},metadata:{defaultText:"defaultText",defaultValue:"defaultValue",text:"text",value:"value"},selector:{text:"> .text:not(.icon)",input:'> input[type="hidden"], > select',search:"> .search",menu:".menu",item:".item"},className:{active:"active",disabled:"disabled",filtered:"filtered",placeholder:"default",search:"search",selected:"selected",selection:"selection",visible:"visible"}},a.fn.dropdown.settings.templates={select:function(b){var c=b.placeholder||!1,d=(b.values||{},"");return d+='',d+=b.placeholder?''+c+"
":'',d+='"}},a.extend(a.easing,{easeOutQuad:function(a,b,c,d,e){return-d*(b/=e)*(b-2)+c}})}(jQuery,window,document);