/**
 * uisearch.js v1.0.0
 * http://www.codrops.com
 *
 * Licensed under the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Copyright 2013, Codrops
 * http://www.codrops.com
 */
!function(t){"use strict";function e(t){return new RegExp("(^|\\s+)"+t+"(\\s+|$)")}var n,s,i;function r(t,e){(n(t,e)?i:s)(t,e)}"classList"in document.documentElement?(n=function(t,e){return t.classList.contains(e)},s=function(t,e){t.classList.add(e)},i=function(t,e){t.classList.remove(e)}):(n=function(t,n){return e(n).test(t.className)},s=function(t,e){n(t,e)||(t.className=t.className+" "+e)},i=function(t,n){t.className=t.className.replace(e(n)," ")});var a={hasClass:n,addClass:s,removeClass:i,toggleClass:r,has:n,add:s,remove:i,toggle:r};"function"==typeof define&&define.amd?define(a):t.classie=a}(window),function(t){"use strict";function e(t,e){this.el=t,this.inputEl=t.querySelector("form > input.sb-search-input"),this.inputSubmit=t.querySelector("form > input.sb-search-submit"),this._initEvents()}!t.addEventListener&&t.Element&&function(){function t(t,e){Window.prototype[t]=HTMLDocument.prototype[t]=Element.prototype[t]=e}var e=[];t("addEventListener",function(t,n){var s=this;e.unshift({__listener:function(t){t.currentTarget=s,t.pageX=t.clientX+document.documentElement.scrollLeft,t.pageY=t.clientY+document.documentElement.scrollTop,t.preventDefault=function(){t.returnValue=!1},t.relatedTarget=t.fromElement||null,t.stopPropagation=function(){t.cancelBubble=!0},t.relatedTarget=t.fromElement||null,t.target=t.srcElement||s,t.timeStamp=+new Date,n.call(s,t)},listener:n,target:s,type:t}),this.attachEvent("on"+t,e[0].__listener)}),t("removeEventListener",function(t,n){for(var s=0,i=e.length;s<i;++s)if(e[s].target==this&&e[s].type==t&&e[s].listener==n)return this.detachEvent("on"+t,e.splice(s,1)[0].__listener)}),t("dispatchEvent",function(t){try{return this.fireEvent("on"+t.type,t)}catch(i){for(var n=0,s=e.length;n<s;++n)e[n].target==this&&e[n].type==t.type&&e[n].call(this,t)}})}(),!String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),e.prototype={_initEvents:function(){var t=this,e=!1;this.el.addEventListener("click",function(e){e.stopPropagation(),t.inputEl.value=t.inputEl.value.trim(),classie.has(t.el,"sb-search-open")?classie.has(t.el,"sb-search-open")&&/^\s*$/.test(t.inputEl.value)&&(e.preventDefault(),t.close()):(e.preventDefault(),t.open())}),this.el.addEventListener("touchstart",function(e){t.inputEl.value=t.inputEl.value.trim(),classie.has(t.el,"sb-search-open")?classie.has(t.el,"sb-search-open")&&/^\s*$/.test(t.inputEl.value)&&t.close():t.open()},{passive:!0}),this.inputEl.addEventListener("click",function(t){t.stopPropagation()}),this.inputEl.addEventListener("keypress",function(n){if(13==n.which){var s=t.el.querySelector("form");e=!0,s.submit()}}),this.inputSubmit&&this.inputSubmit.addEventListener("click",function(n){n.preventDefault(),n.stopPropagation(),e||t.close()}),this.inputEl.addEventListener("touchstart",function(t){t.stopPropagation()},{passive:!0})},open:function(){var t=this;classie.add(this.el,"sb-search-open"),this.inputEl.focus();var e=function(n){t.close(),this.removeEventListener("click",e),this.removeEventListener("touchstart",e)};document.addEventListener("click",e),document.addEventListener("touchstart",e)},close:function(){this.inputEl.blur(),classie.remove(this.el,"sb-search-open")}},t.UISearch=e}(window);