// ajs.$
(function(g,f){var i=false,c=" ",k=null,n="string",e=true,h=g.document,O=[].push,s=[].slice,D=/\./g,N=/^\d+/,m=/\s+/,l=/[\r\n\t]/g,M=new RegExp('(^|[^\\\\])((\\\\)*)"',"g"),K=/^\s+/,J=/\s+$/,b="length",o="prototype",E=String[o].trim,d="replace",j="className",r="getElement",H=r+"ById",u=r+"sByClassName",v=r+"sByTagName",y="querySelectorAll",A="EventListener",x="add"+A,F="remove"+A,w=!!h[y],I={fillOpacity:e,fontWeight:e,lineHeight:e,opacity:e,orphans:e,widows:e,zIndex:e,zoom:e},a=function(c,e){var d=this;if(!(d instanceof a))return new a(c,e);else if(c instanceof a)return c;d[b]=0;if(c==="body"){d[0]=h.body;d[b]=1}else if(c===g){d[0]=g;d[b]=1}else if(typeof c===n){d.context=e=e||h;if(c.charAt(0)=="<"){var f=h.createElement("div");f.innerHTML=c;d.push(f.childNodes);f=k}else d.push(t(a(e),c))}else if(c)if(c.nodeType==1||c.nodeType==9){d[0]=c;d[b]=1}else d.push(c);return d};a.gid=1;a.each=function(c,d){for(var a=0,e=c[b];a<e;a++)a in c&&d.call(c[a],a,c[a])};a.extend=function(c){var i=arguments,h=1,j=i[b],g,d,e;if(!j){a.expand(a.fn,c);return this}else{for(;h<j;h++)if(e=i[h])for(d in e)if((g=e[d])!==k&&g!==f)c[d]=g;return c}};a.noop=function(){};a.quote=function(a){return(a+"").replace(M,'"')};a.trim=E?function(a){return a==k?"":E.call(a)}:function(a){return a==k?"":a.toString()[d](K,"")[d](J,"")};a[o]=a.fn={constructor:a,attr:function(c,g){var d=this,a=d[0],i=0,j=d[b],e,h;if(typeof c==n&&g===f){if(a)if(c in a||!("getAttribute"in a))h=a[c];else h=a.getAttribute(c);return h}else{c=B(c,g);for(var i=0,j=d[b];i<j;i++){a=d[i];if(a)for(e in c){g=c[e];if(e in a||!("setAttribute"in a))a[e]=g;else a.setAttribute(e,g)}}return d}},css:function(d,c){var e=this,a=e[0],i=0,j=e[b],h,g;if(typeof d==n&&c===f){g=a&&a.style&&a.style[d]||f;if(N.test(g))g=parseFloat(g);return g}else{d=B(d,c);for(var i=0,j=e[b];i<j;i++){a=e[i];if(a&&(a=a.style))for(h in d){c=d[h];if(c!==""&&!isNaN(c)&&!I[h])c+="px";a[h]=c}}}return e},size:function(){return this[b]},push:function(e,g){var c=this;if(g){var f=a(e);f.prevObject=c;return f}for(var d=0,h=e[b];d<h;d++){c[d]=e[d];c[b]++}return c},each:function(b){a.each(this,b);return this},eq:function(a){return this.push(this[a],1)},filter:function(a){a=a.split(".");return this.push(p(this,a[0],a[1]),1)},find:function(a){return this.push(t(this,a),1)},children:function(c){var a=this;if(a[0]){var b=a[0].childNodes;return a.push(c===f?b:b[c],1)}return a.push(0,1)},end:function(){return this.prevObject||a()},parent:function(){return this.push(this[0]&&this[0].parentNode,1)},html:function(a){return a===f?this[0]&&this[0].innerHTML:this.each(function(){this.innerHTML=a})},val:function(a){return a===f?this[0]&&this[0].value||"":this.each(function(){this.value=a})},append:function(c){var b=this[0];b&&a(c).each(function(){b.appendChild(this)});return this},bind:function(a,b){return z(this,1,a,b)},unbind:function(a,b){return z(this,0,a,b)},trigger:function(a){return this.each(function(){this[a]()})},one:function(b,c){return this.bind(b,function d(){a(this).unbind(b,d);return c.apply(this,arguments)}.bind(this))},hasClass:function(a){a=a[d](l,c).split(m);for(var f=0,g=this[b];f<g;f++)if(q(this[f],a))return e;return i},addClass:function(f){f=f[d](l,c).split(m);for(var i=0,k=this[b],e,g,h=0;i<k;i++){e=this[i];if(e.nodeType==1)if(e[j]){g=(c+e[j]+c)[d](l);for(h=f[b];h--;)if(!~g.indexOf(c+f[h]+c))g+=f[h]+c;e[j]=a.trim(g)}else e[j]=f.join(c)}return this},removeClass:function(g){g=g[d](l,c).split(m);for(var i=0,k=this[b],e,f,h=0;i<k;i++){e=this[i];if(e.nodeType==1&&e[j]){f=(c+e[j]+c)[d](l);for(h=g[b];h--;)f=f[d](c+g[h]+c,c);e[j]=a.trim(f)}}return this},toggleClass:function(a,b){return this[b===f?!this.hasClass(a):b?"addClass":"removeClass"](a)},closest:function(b){var a=this[0],c;if(a){b=b.split(".");c=b[0]?b[0].toUpperCase():i;b=b[1]?b.slice(1):i;do if(a.nodeType==1&&(!c||a.tagName.toUpperCase()==c)&&(!b||q(a,b)))return this.push(a,1);while(a&&(a=a.parentNode)&&a!==h.body)}return this.push(f,1)},show:function(){return this.css("display","")},hide:function(){return this.css("display","none")},toggle:function(a){return this[a?"show":"hide"]()},remove:function(){return this.each(function(){this.parentNode&&this.parentNode.removeChild(this)})}};a.get=function(d,e){var c="ajs__jsonp__"+a.gid++,b=h.createElement("script");b.type="text/javascript";b.src=d=d+"&callback="+c;g[c]=function(d){e(d);a(b).remove();g[c]=k;try{delete g[c]}catch(f){}};a("head").append(b)};function q(g,f){if(g.nodeType==1){for(var h=(c+g[j]+c)[d](l,c),a=0,k=f[b];a<k;a++)if(!~h.indexOf(c+f[a]+c))return i;return e}}if(Function[o].bind===f)Function[o].bind=function(a){var b=s.call(arguments,1),c=this;return function(){return c.apply(a,b.concat(s.call(arguments,0)))}};var C={};function z(n,p,d,j){d=d.split(m);var q=n[b],c,k,r=d[b],f,o,l;j.gid=j.gid||a.gid++;for(;q--;)if(c=n[q]){c.ajs=c.ajs||a.gid++;for(k=0;k<r;k++){f=d[k];o=c.ajs+"_"+f+"_"+j.gid;l=C[o]=C[o]||function(a){a=a||g.event;if(!a.target)a.target=a.srcElement||h;if(a.target.nodeType===3)a.target=a.target.parentNode;if(!a.currentTarget)a.currentTarget=c;if(!a.relatedTarget&&a.fromElement)a.relatedTarget=a.fromElement===a.target?a.toElement:a.fromElement;if(!a.stopPropagation)a.stopPropagation=function(){this.cancelBubble=e};if(!a.preventDefault)a.preventDefault=function(){this.returnValue=i};if(j.call(c,a)===i){a.preventDefault();a.stopPropagation();return i}};if(c[x])c[p?x:F](f,l,i);else c[p?"attachEvent":"detachEvent"]("on"+f,l)}}return n}function B(a,c){if(c!==f){var b={};b[a]=c;return b}return a}var G=/\[native\s+code\]/i.test(h[u])?function(a,b){return b[u](a)}:function(a,b){return p(b[v]("*"),k,a)};function t(r,e){for(var a,n=[],q=0,u=r[b],f=e.indexOf(c),i=(~f?e.substr(0,f):e)[d](m),j,l,g,o;q<u;q++){g=r[q];if(~f&&w)a=g[y](e);else{l=i.substr(1);j=i.charAt(0);if(j==="#"){a=h[H](l);a=a?[a]:[]}else if(j===".")a=G(l[d](D,c),g);else{o=i.split(".");a=g[v](o[0]);if(~i.indexOf("."))a=p(a,k,o.slice(1));else a=L(a)}}if(a[b]){if(~f&&!w)a=t(a,e.substr(f+1));n=n.concat(s.call(a,0))}}return n}function p(h,f,a){var i=[],g=0,j=h[b],e;if(f)f=f.toUpperCase();if(a&&typeof a==n)a=a[d](D,c).split(m);for(;g<j;g++){e=h[g];e.nodeType==1&&(!f||f==e.tagName.toUpperCase())&&(!a||q(e,a))&&i.push(e)}return i}function L(b){for(var c=[],a=0,d=b.length;a<d;a++)if(a in b)c[a]=b[a];return c}if(!("ajs"in g))g.ajs={};if(!("ui"in ajs))ajs.ui={};g.ajs.$=a})(this);

// ajs.ui.dropdown
(function(d,b){var c="click";function a(d,e){var f="click mouseout mouseover",c=this;d=b(d);if(d.size()>1){d.each(function(){a(this,e)});return d}if(!(c instanceof a))return new a(d,e);c.opts=e=b.extend({cnLink:"js-link",cnMenu:"js-menu",cnExpand:"js-expand",timeout:200,hideByClick:false},e);c.__event=c._event.bind(c);c.$Elm=d;c.$Link=d.find("."+e.cnLink).bind(f,c.__event);c.$Menu=d.find("."+e.cnMenu).bind(f,c.__event)}a.prototype={constructor:a,_event:function(d){var a=this,b=a.opts,e=d.type,g=d.currentTarget,f=a.$Elm.hasClass(b.cnExpand);clearTimeout(a._tid);if(e==c){g===a.$Link[0]&&d.preventDefault();(b.hideByClick||!a._hitTest(d))&&a._expand(!f)}else if(b.timeout>0&&e=="mouseout")a._tid=setTimeout(a._expand.bind(a,false),b.timeout)},_hitTest:function(a){return!!b(a.target).closest("."+this.opts.cnMenu).size()},_expand:function(e){var a=this;a.$Elm.toggleClass(a.opts.cnExpand,e);a.$Menu.toggle(e);sfs();b(d).unbind(c,a.__event);e&&setTimeout(function(){b(d).bind(c,this.__event)}.bind(a),0)}};ajs.ui.dropdown=a})(this.document,ajs.$);

// ajs.ui.search
(function(c,d){var a=".";function b(e,f){var d=this;e=c(e);if(e.size()>1){e.each(function(){b(this)});return e}if(!(d instanceof b))return new b(e,f);d.opts=f=c.extend({cnForm:"js-form",cnInput:"js-input",cnLabel:"js-label",cnBlur:"js-blur",cnSectionTxt:"js-section-text",cnSection:"js-section",cnSectionLink:"js-section-link",cnSectionMenu:"js-section-menu",cnSectionExpand:"js-section-expand",cnSectionSelected:"js-selected",paddingRight:35,searchInputResize:true},f);d.__event=d._event.bind(d);d.$Elm=e;d.$Form=e.find(a+f.cnForm).bind("submit",d.__event);d.$Label=e.find(a+f.cnLabel);d.$Input=e.find(a+f.cnInput).bind("focus blur",d.__event);d.$Section=e.find(a+f.cnSectionTxt);d.$Sections=e.find(a+f.cnSection).bind("click",d._section.bind(d));ajs.ui.dropdown&&ajs.ui.dropdown(e,{cnLink:f.cnSectionLink,cnMenu:f.cnSectionMenu,cnExpand:f.cnSectionExpand});if(f.suggest&&ajs.ui.suggest)d.Suggest=ajs.ui.suggest(e,f.suggest);d._event({type:"blur"});d._section({});d.isReady=true}b.prototype={constructor:b,_event:function(e){var a=this,d=e.type,b=a.isEmpty(),c=d=="blur"&&b;if(d=="submit"&&b){a.$Input.trigger("focus");e.preventDefault()}else{a.$Elm.toggleClass(a.opts.cnBlur,c);c&&a.val("")}},_section:function(e){var b=this,g=b.opts,h=e.target,f=g.cnSectionSelected,d=c(h).closest(a+g.cnSection);if(h){b.$Sections.filter(a+f).removeClass(f);d.addClass(f)}if((d=b.$Sections.filter(a+f))[0]){b.$Form.attr({action:d.attr("data-action"),target:d.attr("data-target")||"_self"});b.$Input.attr("name",d.attr("data-input-name"));b.$Section.html(d.html());b.Suggest&&b.Suggest.set("ajaxUrl",d.attr("data-suggest-url"),!b.isReady)}b.$Section[0]&&g.searchInputResize&&b._resizeSearchInput();if(e&&e.preventDefault){e.type=="click"&&b.$Input.trigger("focus");e.preventDefault()}},_resizeSearchInput:function(){var b="offsetWidth",a=this;a.$Input.css({width:a.$Label.attr(b)-a.$Section.attr(b)-a.opts.paddingRight})},isEmpty:function(){return this.val()==""},val:function(a){if(a!==d){this.$Input.val(a);return this}return c.trim(this.$Input.val())}};ajs.ui.search=b})(ajs.$);

// ajs.ui.suggest
(function(a,e){var g="data-suggest",f="data-suggest-idx",c=false,b=".",h=/^.*\s+/,i=/\S+$/;function d(g,h){var f=this;g=a(g);if(g.size()>1){g.each(function(){d(this)});return g}if(!(f instanceof d))return new d(g,h);f.opts=h=a.extend({cnInput:"js-input",cnSuggest:"js-suggest",cnList:"js-suggest-list",cnItem:"js-suggest-item",cnSelected:"js-suggest-selected",cnInternet:"js-suggest-internet",getData:function(a){return a&&a[1]=="OK"&&a[2]},template:function(c,b){return'<div data-suggest="'+a.quote(b)+'" class="'+this.cnItem+'">'+b.text.replace(new RegExp(c,"i"),"<b>$&</b>")+"</div>"},request:function(b,c){a.get(b,c)},timeout:300,expire:0,autosubmit:true,ajaxUrl:e,searchUrl:"http://go.mail.ru/search?q=#query#",onselect:a.noop},h);f._cache={};f.$Elm=g;f.$Input=g.find(b+h.cnInput).attr("autocomplete","off").bind("blur focus click keyup keydown",f._event.bind(f));f.$Suggest=g.find(b+h.cnSuggest).bind("mouseup mousedown",function(a){this._down=a.type!="mouseup"}.bind(f));f.$Internet=g.find(b+h.cnInternet);f.$List=g.find(b+h.cnList).bind("click",f._selectByClick.bind(f));h.expire&&setInterval(function(){var a=this;if(a.$Suggest.css("display")=="none"){a.__val=e;a._loadVar=e;for(var b in a._cache){a._cache[b]=c;delete a._cache[b]}}}.bind(f),h.expire)}d.prototype={constructor:d,_event:function(f){var a=this,e=f.type,d=f.keyCode,i=a.opts;clearTimeout(a._tid);if(e=="blur")!a._down&&a.$Suggest.hide();else if(d==38||d==40){e=="keydown"&&a._select(d==38?-1:1);return c}else if(d==13&&e=="keydown"){var h=a.$List.find(b+i.cnSelected);if(h[0]&&a._onselect(f,h[0])===c)return c}else{var g=a.val();if(a._cache[g])a._rebuild(g);else a._tid=setTimeout(function(){this.find(g)}.bind(a),i.timeout)}},_closest:function(a,b){do if(a.nodeType==1&&"getAttribute"in a){b=a.getAttribute(f);if(b>0)return a}while(a&&(a=a.parentNode)&&a!==document.body)},_selectByClick:function(h){var d=this,f=d.opts,i=f.cnSelected,e=a(d._closest(h.target)),j=e.attr(g);if(d._onselect(h,e[0])!==c){d.$List.find(b+i).removeClass(i);d.$Input.trigger("focus");d.val(j);f.autosubmit&&d.$Input.closest("form").trigger("submit")}return c},_select:function(h){var d=this,e=d.opts.cnSelected,c=d.$List.find(b+e),i=d.$List,f=i.children();if(c.size()){c.removeClass(e);c=a(c[0][h>0?"nextSibling":"previousSibling"]).addClass(e)}else c=f.eq(h>0?0:f.size()-1).addClass(e);d.val(c[0]?c.attr(g):d.__val)},_loaded:function(b,c){var a=this;a._cache[b]=a.opts.getData(c);a.val()==b&&a._rebuild(b)},_rebuild:function(d){var b=this,c=b._cache[d];if(b.__val!==d){b.__val=d;if(c&&c.length){for(var e=0,h=c.length,g=[];e<h;e++)g.push(a.trim(b.opts.template(d,c[e])));b.$List.html(g.join("")).children().each(function(a,b){b.setAttribute(f,a+1)})}b._internetVal(d)}b.$List.toggle(!!(c&&c.length));b.$Suggest.toggle(!!(d.length>1))},_onselect:function(d,b){var a=this,h=b.getAttribute(g),e=b.getAttribute(f)-1,c=a._cache[a.__val];return a.opts.onselect({type:"select",target:b,event:d,item:c&&c[e],value:h,suggest:a})},_request:function(a,c,b){this.opts.request(a,c,b)},_internetVal:function(a){this.$Internet.attr({href:this.opts.searchUrl.replace("#query#",decodeURIComponent(a)),innerHTML:a})},val:function(b){var c=this;if(b!==e){if(c.opts.searchLast)b=c.$Input.val().replace(i,"")+b;c._internetVal(b);c.$Input.val(b);b==""&&c.$Suggest.hide();return c}b=a.trim(c.$Input.val());if(c.opts.searchLast)b=b.replace(h,"");return b},find:function(b){var a=this,c=a.opts.ajaxUrl;if(!c||b=="")a.$Suggest.hide();else if(a._loadVal!=b||a._loadUrl!=c){a._loadUrl=c;a._loadVal=b;a._request(c.replace("#query#",b)+"&"+Math.random(),a._loaded.bind(a,b),b)}},"set":function(c,d,b){var a=this;a.opts[c]=d;!b&&a.find(a.val());return a},"get":function(a){return this.opts[a]}};ajs.ui.suggest=d})(ajs.$);

