!function(e,t,s){e.isMobile=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),e.isIframe=e.parent!=e.self&&location.host===parent.location.host;var a={},l=0,n=function(s,i){var l;return e.isMobile&&!i.mobile?!1:this===e?new n(s,i):("string"==typeof s&&"#"===s[0]&&(s=t.getElementById(s.substr(1))),(l=s.getAttribute("data-dkcacheid"))?(r.extend(a[l].data.settings,i),a[l]):"SELECT"===s.nodeName?this.init(s,i):void 0)},o=function(){},d={initialize:o,change:o,open:o,close:o,search:"strict"},r={hasClass:function(e,t){var s=new RegExp("(^|\\s+)"+t+"(\\s+|$)");return e&&s.test(e.className)},addClass:function(e,t){e&&!r.hasClass(e,t)&&(e.className+=" "+t)},removeClass:function(e,t){var s=new RegExp("(^|\\s+)"+t+"(\\s+|$)");e&&(e.className=e.className.replace(s," "))},toggleClass:function(e,t){var s=r.hasClass(e,t)?"remove":"add";r[s+"Class"](e,t)},extend:function(e){return Array.prototype.slice.call(arguments,1).forEach(function(t){if(t)for(var s in t)e[s]=t[s]}),e},offset:function(s){var i=s.getBoundingClientRect()||{top:0,left:0},a=t.documentElement;return{top:i.top+e.pageYOffset-a.clientTop,left:i.left+e.pageXOffset-a.clientLeft}},position:function(e,t){for(var s={top:0,left:0};e!==t;)s.top+=e.offsetTop,s.left+=e.offsetLeft,e=e.parentNode;return s},closest:function(e,t){for(;e;){if(e===t)return e;e=e.parentNode}return!1},create:function(e,s){var i,a=t.createElement(e);s||(s={});for(i in s)s.hasOwnProperty(i)&&("innerHTML"==i?a.innerHTML=s[i]:a.setAttribute(i,s[i]));return a}};n.prototype={add:function(e,s){var i,a,l;"string"==typeof e&&(i=e,e=t.createElement("option"),e.text=i),"OPTION"===e.nodeName&&(a=r.create("li",{"class":"dk-option","data-value":e.value,innerHTML:e.text,role:"option","aria-selected":"false",id:"dk"+this.data.cacheID+"-"+(e.id||e.value.replace(" ","-"))}),r.addClass(a,e.className),this.length+=1,e.disabled&&(r.addClass(a,"dk-option-disabled"),a.setAttribute("aria-disabled","true")),this.data.select.add(e,s),"number"==typeof s&&(s=this.item(s)),this.options.indexOf(s)>-1?s.parentNode.insertBefore(a,s):this.data.elem.lastChild.appendChild(a),a.addEventListener("mouseover",this),l=this.options.indexOf(s),this.options.splice(l,0,a),e.selected&&this.select(l))},item:function(e){return e=0>e?this.options.length+e:e,this.options[e]||null},remove:function(e){var t=this.item(e);t.parentNode.removeChild(t),this.options.splice(e,1),this.data.select.remove(e),this.select(this.data.select.selectedIndex),this.length-=1},init:function(s,i){var o,h=n.build(s,"dk"+l);if(this.data={},this.data.select=s,this.data.elem=h.elem,this.data.settings=r.extend({},d,i),this.disabled=s.disabled,this.form=s.form,this.length=s.length,this.multiple=s.multiple,this.options=h.options.slice(0),this.selectedIndex=s.selectedIndex,this.selectedOptions=h.selected.slice(0),this.value=s.value,s.parentNode.insertBefore(this.data.elem,s),this.data.elem.addEventListener("click",this),this.data.elem.addEventListener("keydown",this),this.data.elem.addEventListener("keypress",this),this.form&&this.form.addEventListener("reset",this),!this.multiple)for(o=0;ot,i=o>t,direction=s&&!i?"-up":"-down",this.isOpen=!0,r.addClass(a,"dk-select-open"+direction),l.setAttribute("aria-expanded","true"),this._scrollTo(this.options.length-1),this._scrollTo(this.selectedIndex),void this.data.settings.open.call(this))},disable:function(e,t){var i="dk-option-disabled";(0==arguments.length||"boolean"==typeof e)&&(t=e===s?!0:!1,e=this.data.elem,i="dk-select-disabled",this.disabled=t),t==s&&(t=!0),"number"==typeof e&&(e=this.item(e)),r[t?"addClass":"removeClass"](e,i)},select:function(e,t){var s,i,a,l,n=this.data.select;if("number"==typeof e&&(e=this.item(e)),"string"==typeof e)for(s=0;sa&&l>i&&(i=a),i>l&&l>a&&(l=a),this.reset(!0),l>i)for(;l+1>i;)this.select(i++);else for(;i>l-1;)this.select(i--);else t.ctrlKey||t.metaKey?this.select(n):(this.reset(!0),this.select(n))}else this[this.isOpen?"close":"open"](),r.hasClass(n,"dk-option")&&this.select(n)},_highlight:function(e){var t,s=e.target;if(!this.multiple){for(t=0;ti.length-1?a=i.length-1:0>a&&(a=0),this.data.select.options[a].disabled||(this.reset(!0),this.select(a),this._scrollTo(a));break;case l.space:if(!this.isOpen){e.preventDefault(),this.open();break}case l.tab:case l.enter:for(a=0;aa.offsetHeight?(t+=e.offsetHeight,a.scrollTop=t-a.offsetHeight):0>s&&(a.scrollTop=t))):!1}},n.build=function(e,t){var s,i,a=[],l={elem:null,options:[],selected:[]},n=function(e){var s,i,a,o,d=[];switch(e.nodeName){case"OPTION":s=r.create("li",{"class":"dk-option","data-value":e.value,innerHTML:e.text,role:"option","aria-selected":"false",id:t+"-"+(e.id||e.value.replace(" ","-"))}),r.addClass(s,e.className),e.disabled&&(r.addClass(s,"dk-option-disabled"),s.setAttribute("aria-disabled","true")),e.selected&&(r.addClass(s,"dk-option-selected"),s.setAttribute("aria-selected","true"),l.selected.push(s)),l.options.push(this.appendChild(s));break;case"OPTGROUP":for(i=r.create("li",{"class":"dk-optgroup"}),e.label&&i.appendChild(r.create("div",{"class":"dk-optgroup-label",innerHTML:e.label})),a=r.create("ul",{"class":"dk-optgroup-options"}),o=e.children.length;o--;d.unshift(e.children[o]));d.forEach(n,a),this.appendChild(i).appendChild(a)}};for(l.elem=r.create("div",{"class":"dk-select"+(e.multiple?"-multi":"")}),s=r.create("ul",{"class":"dk-select-options",id:t+"-listbox",role:"listbox"}),e.disabled&&r.addClass(l.elem,"dk-select-disabled"),l.elem.id=t+(e.id?"-"+e.id:""),r.addClass(l.elem,e.className),e.multiple?(l.elem.setAttribute("tabindex",e.getAttribute("tabindex")||"0"),s.setAttribute("aria-multiselectable","true")):(l.elem.appendChild(r.create("div",{"class":"dk-selected",tabindex:e.tabindex||0,innerHTML:e.options[e.selectedIndex].text,id:t+"-combobox","aria-live":"assertive","aria-owns":s.id,role:"combobox"})),s.setAttribute("aria-expanded","false")),i=e.children.length;i--;a.unshift(e.children[i]));return a.forEach(n,l.elem.appendChild(s)),l},n.onDocClick=function(e){var s,i,l;(s=t.getElementById(e.target.htmlFor))&&null!==(i=s.getAttribute("data-dkcacheid"))&&a[i].data.elem.focus();for(l in a)r.closest(e.target,a[l].data.elem)||a[l].disabled||a[l].close()},e.Dropkick=n}(window,document);