(function(a){var b={ui:{customElem:'<div class="tsq-custom-select-front"><button type="button" class="tsq-custom-select-click-handle tsq-custom-select-menu-toggler">Select an Item</button><span class="tsq-custom-select-icon tsq-custom-select-menu-toggler"></span></div>',customElemList:'<div><input type="text" value="" class="custom-select-searchinput" style="border:1px solid #e1e1e1; width:99%; background:url(\'{{searchIconUrl}}\') no-repeat scroll 98% 50% #fff; text-transform:lowercase; "/><ul class="tsq-custom-select-item-list" tabindex="{{tabindex}}"></ul></div>',handleClass:".tsq-custom-select-click-handle",handleIconClass:".tsq-custom-select-icon",menuToggler:".tsq-custom-select-menu-toggler",searchInput:"custom-select-searchinput",searchIconUrl:"https://tsm-images.s3.amazonaws.com/icons/search_icon.png",appendTo:"body"},changeCallback:function(){},optionClickCallback:function(){},itemCreationCallback:function(){},applyWidthFix:0,isAnimating:0,lastSelected:a({})};a.customSelect=function(u){var B="mouseout",A="click.customselect",z="li:first-child > a",h="a",n="b2b-show-custom-select",t="block",i="hover",l="curr",y="undefined",s="data-value",p="none",o=true;if(!u.elem)a.extend(o,b,u);else{var c=a.extend(o,{},b,u),L=c.elem,f=a(L),J={display:p},d=a(c.ui.customElemList.replace("{{tabindex}}",a(".tsq-custom-select-item-list").length+1).replace("{{searchIconUrl}}",c.ui.searchIconUrl)),e=d.find("ul"),k=d.find("."+c.ui.searchInput),D=f.data("customclass")||0,I=f.data("customid")||0,E=typeof f.attr(s)===y?0:""+f.attr(s),g=a(c.ui.customElem),C=f.find("option"),j=g.find(c.ui.handleClass),P=g.find(c.ui.handleIconClass),K=f.data("proxyid")?f.data("proxyid"):0,H=a(c.ui.appendTo),w=f.outerWidth(),x=a(window),Q,m,R,r,v,M,O=function(){if(!c.isAnimating){c.isAnimating=1;if(d.data(l)){d.data(l).addClass(i);c.lastSelected=d.data(l)}m=d.height();M=typeof c.ui.appendToLeft===y?g.offset().left:c.ui.appendToLeft;r=g.offset().top+g.height()-H.offset().top;if(r+m-x.scrollTop()>x.height())r-=m+g.height();d.css({width:w,top:r,left:M,display:t,height:1,overflow:"visible"});e.css({"max-height":m,"overflow-y":"auto"});k.val("");d.stop(o,o).animate({height:m},{duration:200,easing:"easeOutCubic",complete:function(){c.isAnimating=0;d.addClass(n).find(h).removeClass(i);k.focus()}});c.searchString="";F(c.searchString)}},q=function(){if(!c.isAnimating){c.isAnimating=1;d.removeClass(n);d.css({display:p,height:m});c.isAnimating=0}},N=function(){d.bind("keyup",function(b){var d="a:visible";if(a(this).hasClass(n)){e.find(h).removeClass(i);k.val(k.val().replace(/\+/g,""));if(k.val()===""){if(b.keyCode===40){b.preventDefault();c.lastSelected=c.lastSelected.parent().next().length?c.lastSelected.parent().next().find(h):e.find(z);c.lastSelected.focus()}else if(b.keyCode===38){b.preventDefault();c.lastSelected=c.lastSelected.parent().prev().length&&c.lastSelected.parent().prev().find(h).length?c.lastSelected.parent().prev().find(h):e.find("li:last-child > a");c.lastSelected.focus()}else if(b.keyCode!==13)(b.keyCode>=48&&b.keyCode<=57||b.keyCode>=65&&b.keyCode<=90||b.keyCode>=96&&b.keyCode<=106||b.keyCode>=109&&b.keyCode<=111||b.keyCode>=186&&b.keyCode<=191)&&k.focus().val(String.fromCharCode(b.keyCode).toLowerCase())}else b.keyCode===13&&e.find(d).length&&c.lastSelected.trigger("click");if(F(k.val().toLowerCase()))c.lastSelected=a(e.find(d)[0]);c.lastSelected.addClass(i)}})},F=function(b){v=0;e.find(h).css({display:t}).each(function(){$this=a(this);if($this.html().toLowerCase().search(b)===-1){$this.css({display:p});v++}});return v},G=function(){if(!d.hasClass(n))O();else q()};E&&f.val(E);C.each(function(k){var b=a(this),f=0,d,g=k===C.length-1?'class="last"':"";if(b.is(":selected")){j.html(b.html());f=1}d=a("<li "+g+'><a href="javascript:void(0);" data-value="'+b.attr("value")+'">'+b.text()+"</a></li>");f&&d.find(h).addClass(i);e.append(d);c.itemCreationCallback(d)});c.searchString="";c.lastSelected=e.find("a.hover").length?e.find("a.hover"):e.find(z);d.data(l,c.lastSelected).css({display:p,position:"absolute"});e.css({display:t,position:"static"});g.addClass(L.className).width(w);j.width(w);K&&j.attr("id",K);if(c.applyWidthFix)J.width=f.width();f.css(J).after(g).bind("change.update-custom-select",function(){j.html(f.find("option:selected").html())}).data("proxy",g);d.css({width:f.width(),top:g.offset().top+g.height(),left:g.offset().left}).appendTo(H);D&&d.addClass(D);I&&d.attr("id",I);N();a(document).bind(A,function(d){var b=a(d.target);if(!b.hasClass(c.ui.searchInput))if(b===g||g.find(b).length)G();else q()});x.bind("scroll",function(){q()});j.bind("focus.fresh",function(){!d.hasClass(n)&&j.trigger(A)});e.delegate("a:not(.exclude)","click",function(){var b=a(this);j.html(b.html());G();f.val(b.attr(s));d.data(l,b);q();f.trigger("change.update-default");c.optionClickCallback(b);!a.browser.msie&&j.trigger("focus.stale")}).delegate(h,"mouseover",function(){e.find(h).removeClass(i);a(this).addClass(i);c.lastSelected=a(this)}).delegate(h,B,function(){a(this).removeClass(i)}).bind(B,function(){e.find(h).removeClass(i);c.lastSelected=c.lastSelected||d.data(l);c.lastSelected.addClass(i)})}};a.fn.customSelect=function(b){return this.each(function(){b=b||{};b.elem=this;a.customSelect(b)})};!a.easing.easeInCubic&&a.extend(a.easing,{easeInCubic:function(e,a,b,c,d){return c*(a/=d)*a*a+b}});!a.easing.easeOutCubic&&a.extend(a.easing,{easeOutCubic:function(e,a,b,c,d){return c*((a=a/d-1)*a*a+1)+b}})})(jQuery,window);
