/*!
 * jQuery corner plugin: simple corner rounding
 * Examples and documentation at: http://jquery.malsup.com/corner/
 * version 2.12 (23-MAY-2011)
 * Requires jQuery v1.3.2 or later
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Authors: Dave Methvin and Mike Alsup
 */
/**
 *  corner() takes a single string argument:  $('#myDiv').corner("effect corners width")
 *
 *  effect:  name of the effect to apply, such as round, bevel, notch, bite, etc (default is round). 
 *  corners: one or more of: top, bottom, tr, tl, br, or bl.  (default is all corners)
 *  width:   width of the effect; in the case of rounded corners this is the radius. 
 *           specify this value using the px suffix such as 10px (yes, it must be pixels).
 */
function MeasurableTextField(a,b,c){this.field=a,this.hint=b,this.max=c}(function(a){function i(b,c){return parseInt(a.css(b,c))||0}function j(a){return a=parseInt(a).toString(16),a.length<2?"0"+a:a}function k(b){while(b){var c=a.css(b,"backgroundColor"),d;if(c&&c!="transparent"&&c!="rgba(0, 0, 0, 0)")return c.indexOf("rgb")>=0?(d=c.match(/\d+/g),"#"+j(d[0])+j(d[1])+j(d[2])):c;if(b.nodeName.toLowerCase()=="html")break;b=b.parentNode}return"#ffffff"}function l(a,b,c){switch(a){case"round":return Math.round(c*(1-Math.cos(Math.asin(b/c))));case"cool":return Math.round(c*(1+Math.cos(Math.asin(b/c))));case"sharp":return c-b;case"bite":return Math.round(c*Math.cos(Math.asin((c-b-1)/c)));case"slide":return Math.round(c*Math.atan2(b,c/b));case"jut":return Math.round(c*Math.atan2(c,c-b-1));case"curl":return Math.round(c*Math.atan(b));case"tear":return Math.round(c*Math.cos(b));case"wicked":return Math.round(c*Math.tan(b));case"long":return Math.round(c*Math.sqrt(b));case"sculpt":return Math.round(c*Math.log(c-b-1,c));case"dogfold":case"dog":return b&1?b+1:c;case"dog2":return b&2?b+1:c;case"dog3":return b&3?b+1:c;case"fray":return b%2*c;case"notch":return c;case"bevelfold":case"bevel":return b+1;case"steep":return b/2+1;case"invsteep":return(c-b)/2+1}}var b=document.createElement("div").style,c=b.MozBorderRadius!==undefined,d=b.WebkitBorderRadius!==undefined,e=b.borderRadius!==undefined||b.BorderRadius!==undefined,f=document.documentMode||0,g=a.browser.msie&&(a.browser.version<8&&!f||f<8),h=a.browser.msie&&function(){var a=document.createElement("div");try{a.style.setExpression("width","0+0"),a.style.removeExpression("width")}catch(b){return!1}return!0}();a.support=a.support||{},a.support.borderRadius=c||d||e,a.fn.corner=function(b){if(this.length==0){if(!a.isReady&&this.selector){var f=this.selector,j=this.context;a(function(){a(f,j).corner(b)})}return this}return this.each(function(f){var j=a(this),m=[j.attr(a.fn.corner.defaults.metaAttr)||"",b||""].join(" ").toLowerCase(),n=/keep/.test(m),o=(m.match(/cc:(#[0-9a-f]+)/)||[])[1],p=(m.match(/sc:(#[0-9a-f]+)/)||[])[1],q=parseInt((m.match(/(\d+)px/)||[])[1])||10,r=/round|bevelfold|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dogfold|dog|invsteep|steep/,s=(m.match(r)||["round"])[0],t=/dogfold|bevelfold/.test(m),u={T:0,B:1},v={TL:/top|tl|left/.test(m),TR:/top|tr|right/.test(m),BL:/bottom|bl|left/.test(m),BR:/bottom|br|right/.test(m)},w,x,y,z,A,B,C,D,E,F,G,H,I,J;!v.TL&&!v.TR&&!v.BL&&!v.BR&&(v={TL:1,TR:1,BL:1,BR:1});if(a.fn.corner.defaults.useNative&&s=="round"&&(e||c||d)&&!o&&!p){v.TL&&j.css(e?"border-top-left-radius":c?"-moz-border-radius-topleft":"-webkit-border-top-left-radius",q+"px"),v.TR&&j.css(e?"border-top-right-radius":c?"-moz-border-radius-topright":"-webkit-border-top-right-radius",q+"px"),v.BL&&j.css(e?"border-bottom-left-radius":c?"-moz-border-radius-bottomleft":"-webkit-border-bottom-left-radius",q+"px"),v.BR&&j.css(e?"border-bottom-right-radius":c?"-moz-border-radius-bottomright":"-webkit-border-bottom-right-radius",q+"px");return}w=document.createElement("div"),a(w).css({overflow:"hidden",height:"1px",minHeight:"1px",fontSize:"1px",backgroundColor:p||"transparent",borderStyle:"solid"}),x={T:parseInt(a.css(this,"paddingTop"))||0,R:parseInt(a.css(this,"paddingRight"))||0,B:parseInt(a.css(this,"paddingBottom"))||0,L:parseInt(a.css(this,"paddingLeft"))||0},typeof this.style.zoom!=undefined&&(this.style.zoom=1),n||(this.style.border="none"),w.style.borderColor=o||k(this.parentNode),y=a(this).outerHeight();for(z in u){A=u[z];if(A&&(v.BL||v.BR)||!A&&(v.TL||v.TR)){w.style.borderStyle="none "+(v[z+"R"]?"solid":"none")+" none "+(v[z+"L"]?"solid":"none"),B=document.createElement("div"),a(B).addClass("jquery-corner"),C=B.style,A?this.appendChild(B):this.insertBefore(B,this.firstChild),A&&y!="auto"?(a.css(this,"position")=="static"&&(this.style.position="relative"),C.position="absolute",C.bottom=C.left=C.padding=C.margin="0",h?C.setExpression("width","this.parentNode.offsetWidth"):C.width="100%"):!A&&a.browser.msie?(a.css(this,"position")=="static"&&(this.style.position="relative"),C.position="absolute",C.top=C.left=C.right=C.padding=C.margin="0",h?(D=i(this,"borderLeftWidth")+i(this,"borderRightWidth"),C.setExpression("width","this.parentNode.offsetWidth - "+D+'+ "px"')):C.width="100%"):(C.position="relative",C.margin=A?x.B-q+"px -"+x.R+"px -"+x.B+"px -"+x.L+"px":"-"+x.T+"px -"+x.R+"px "+(x.T-q)+"px -"+x.L+"px");for(E=0;E<q;E++)F=Math.max(0,l(s,E,q)),G=w.cloneNode(!1),G.style.borderWidth="0 "+(v[z+"R"]?F:0)+"px 0 "+(v[z+"L"]?F:0)+"px",A?B.appendChild(G):B.insertBefore(G,B.firstChild);if(t&&a.support.boxModel){if(A&&g)continue;for(H in v){if(!v[H])continue;if(!(!A||H!="TL"&&H!="TR"))continue;if(!A&&(H=="BL"||H=="BR"))continue;I={position:"absolute",border:"none",margin:0,padding:0,overflow:"hidden",backgroundColor:w.style.borderColor},J=a("<div/>").css(I).css({width:q+"px",height:"1px"});switch(H){case"TL":J.css({bottom:0,left:0});break;case"TR":J.css({bottom:0,right:0});break;case"BL":J.css({top:0,left:0});break;case"BR":J.css({top:0,right:0})}B.appendChild(J[0]);var K=a("<div/>").css(I).css({top:0,bottom:0,width:"1px",height:q+"px"});switch(H){case"TL":K.css({left:q});break;case"TR":K.css({right:q});break;case"BL":K.css({left:q});break;case"BR":K.css({right:q})}B.appendChild(K[0])}}}}})},a.fn.uncorner=function(){return(e||c||d)&&this.css(e?"border-radius":c?"-moz-border-radius":"-webkit-border-radius",0),a("div.jquery-corner",this).remove(),this},a.fn.corner.defaults={useNative:!0,metaAttr:"data-corner"}})(jQuery),jQuery.cookie=function(a,b,c){if(typeof b=="undefined"){var i=null;if(document.cookie&&document.cookie!=""){var j=document.cookie.split(";");for(var k=0;k<j.length;k++){var l=jQuery.trim(j[k]);if(l.substring(0,a.length+1)==a+"="){i=decodeURIComponent(l.substring(a.length+1));break}}}return i}c=c||{},b===null&&(b="",c.expires=-1);var d="";if(c.expires&&(typeof c.expires=="number"||c.expires.toUTCString)){var e;typeof c.expires=="number"?(e=new Date,e.setTime(e.getTime()+c.expires*24*60*60*1e3)):e=c.expires,d="; expires="+e.toUTCString()}var f=c.path?"; path="+c.path:"",g=c.domain?"; domain="+c.domain:"",h=c.secure?"; secure":"";document.cookie=[a,"=",encodeURIComponent(b),d,f,g,h].join("")},MeasurableTextField.prototype.measure=function(){var a=this.field.val().length,b;b=this.max-a,chars_left_string=b.toString(),a<=this.max?(b<20&&b>9?chars_word="символов":chars_left_string.search(/[^1]*1$/)>=0?chars_word="символ":chars_left_string.search(/[^1]*(2|3|4)$/)>=0?chars_word="символа":chars_word="символов",this.hint.html(chars_left_string),b<30?this.hint.removeClass("green").addClass("warning"):this.hint.removeClass("warning").addClass("green")):(this.hint.removeClass("green").addClass("warning"),this.hint.html(chars_left_string))},jQuery(function(a){a.fn.watchFieldLength=function(b,c){var d=new MeasurableTextField(this,b,c);a(this).bind("keyup change",function(){d.measure()})}}),function(a){var b=a.browser.msie&&parseInt(a.browser.version)===6&&typeof window.XMLHttpRequest!="object",c=a.browser.msie&&parseInt(a.browser.version)===7,d=null,e=[];a.modal=function(b,c){return a.modal.impl.init(b,c)},a.modal.close=function(){a.modal.impl.close()},a.modal.focus=function(b){a.modal.impl.focus(b)},a.modal.setContainerDimensions=function(){a.modal.impl.setContainerDimensions()},a.modal.setPosition=function(){a.modal.impl.setPosition()},a.modal.update=function(b,c){a.modal.impl.update(b,c)},a.fn.modal=function(b){return a.modal.impl.init(this,b)},a.modal.defaults={appendTo:"body",focus:!0,opacity:50,overlayId:"simplemodal-overlay",overlayCss:{},containerId:"simplemodal-container",containerCss:{},dataId:"simplemodal-data",dataCss:{},minHeight:null,minWidth:null,maxHeight:null,maxWidth:null,autoResize:!1,autoPosition:!0,zIndex:1e3,close:!0,closeHTML:'<a class="modalCloseImg" title="Close"></a>',closeClass:"simplemodal-close",escClose:!0,overlayClose:!1,position:null,persist:!1,modal:!0,onOpen:null,onShow:null,onClose:null},a.modal.impl={d:{},init:function(b,c){var e=this;if(e.d.data)return!1;d=a.browser.msie&&!a.boxModel,e.o=a.extend({},a.modal.defaults,c),e.zIndex=e.o.zIndex,e.occb=!1;if(typeof b=="object")b=b instanceof jQuery?b:a(b),e.d.placeholder=!1,b.parent().parent().size()>0&&(b.before(a("<span></span>").attr("id","simplemodal-placeholder").css({display:"none"})),e.d.placeholder=!0,e.display=b.css("display"),e.o.persist||(e.d.orig=b.clone(!0)));else if(typeof b=="string"||typeof b=="number")b=a("<div></div>").html(b);else return alert("SimpleModal Error: Unsupported data type: "+typeof b),e;return e.create(b),e.open(),a.isFunction(e.o.onShow)&&e.o.onShow.apply(e,[e.d]),e},create:function(c){var g=this;e=g.getDimensions(),g.o.modal&&b&&(g.d.iframe=a('<iframe src="javascript:false;"></iframe>').css(a.extend(g.o.iframeCss,{display:"none",opacity:0,position:"fixed",height:e[0],width:e[1],zIndex:g.o.zIndex,top:0,left:0})).appendTo(g.o.appendTo)),g.d.overlay=a("<div></div>").attr("id",g.o.overlayId).addClass("simplemodal-overlay").css(a.extend(g.o.overlayCss,{display:"none",opacity:g.o.opacity/100,height:g.o.modal?e[0]:0,width:g.o.modal?e[1]:0,position:"fixed",left:0,top:0,zIndex:g.o.zIndex+1})).appendTo(g.o.appendTo),g.d.container=a("<div></div>").attr("id",g.o.containerId).addClass("simplemodal-container").css(a.extend(g.o.containerCss,{display:"none",position:"fixed",zIndex:g.o.zIndex+2})).append(g.o.close&&g.o.closeHTML?a(g.o.closeHTML).addClass(g.o.closeClass):"").appendTo(g.o.appendTo),g.d.wrap=a("<div></div>").attr("tabIndex",-1).addClass("simplemodal-wrap").css({height:"100%",outline:0,width:"100%"}).appendTo(g.d.container),g.d.data=c.attr("id",c.attr("id")||g.o.dataId).addClass("simplemodal-data").css(a.extend(g.o.dataCss,{display:"none"})).appendTo("body"),g.setContainerDimensions(),g.d.data.appendTo(g.d.wrap),(b||d)&&g.fixIE()},bindEvents:function(){var c=this;a("."+c.o.closeClass).bind("click.simplemodal",function(a){a.preventDefault(),c.close()}),c.o.modal&&c.o.close&&c.o.overlayClose&&c.d.overlay.bind("click.simplemodal",function(a){a.preventDefault(),c.close()}),a(document).bind("keydown.simplemodal",function(a){c.o.modal&&a.keyCode===9?c.watchTab(a):c.o.close&&c.o.escClose&&a.keyCode===27&&(a.preventDefault(),c.close())}),a(window).bind("resize.simplemodal",function(){e=c.getDimensions(),c.o.autoResize?c.setContainerDimensions():c.o.autoPosition&&c.setPosition(),b||d?c.fixIE():c.o.modal&&(c.d.iframe&&c.d.iframe.css({height:e[0],width:e[1]}),c.d.overlay.css({height:e[0],width:e[1]}))})},unbindEvents:function(){a("."+this.o.closeClass).unbind("click.simplemodal"),a(document).unbind("keydown.simplemodal"),a(window).unbind("resize.simplemodal"),this.d.overlay.unbind("click.simplemodal")},fixIE:function(){var b=this,c=b.o.position;a.each([b.d.iframe||null,b.o.modal?b.d.overlay:null,b.d.container],function(a,b){if(b){var d=b[0].style;d.position="absolute";if(a<2)d.removeExpression("height"),d.removeExpression("width"),d.setExpression("height",'document.body.scrollHeight > document.body.clientHeight ? document.body.scrollHeight : document.body.clientHeight + "px"'),d.setExpression("width",'document.body.scrollWidth > document.body.clientWidth ? document.body.scrollWidth : document.body.clientWidth + "px"');else{var e;c&&c.constructor===Array?(a=c[0]?typeof c[0]=="number"?c[0].toString():c[0].replace(/px/,""):b.css("top").replace(/px/,""),a=a.indexOf("%")===-1?a+' + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"':parseInt(a.replace(/%/,""))+' * ((document.documentElement.clientHeight || document.body.clientHeight) / 100) + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"',c[1]&&(e=typeof c[1]=="number"?c[1].toString():c[1].replace(/px/,""),e=e.indexOf("%")===-1?e+' + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"':parseInt(e.replace(/%/,""))+' * ((document.documentElement.clientWidth || document.body.clientWidth) / 100) + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"')):(a='(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"',e='(document.documentElement.clientWidth || document.body.clientWidth) / 2 - (this.offsetWidth / 2) + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"'),d.removeExpression("top"),d.removeExpression("left"),d.setExpression("top",a),d.setExpression("left",e)}}})},focus:function(b){var c=this;b=b&&a.inArray(b,["first","last"])!==-1?b:"first";var d=a(":input:enabled:visible:"+b,c.d.wrap);setTimeout(function(){d.length>0?d.focus():c.d.wrap.focus()},10)},getDimensions:function(){var b=a(window);return[a.browser.opera&&a.browser.version>"9.5"&&a.fn.jquery<"1.3"||a.browser.opera&&a.browser.version<"9.5"&&a.fn.jquery>"1.2.6"?b[0].innerHeight:b.height(),b.width()]},getVal:function(a,b){return a?typeof a=="number"?a:a==="auto"?0:a.indexOf("%")>0?parseInt(a.replace(/%/,""))/100*(b==="h"?e[0]:e[1]):parseInt(a.replace(/px/,"")):null},update:function(a,b){var c=this;if(!c.d.data)return!1;c.d.origHeight=c.getVal(a,"h"),c.d.origWidth=c.getVal(b,"w"),c.d.data.hide(),a&&c.d.container.css("height",a),b&&c.d.container.css("width",b),c.setContainerDimensions(),c.d.data.show(),c.o.focus&&c.focus(),c.unbindEvents(),c.bindEvents()},setContainerDimensions:function(){var d=this,g=b||c,h=d.d.origHeight?d.d.origHeight:a.browser.opera?d.d.container.height():d.getVal(g?d.d.container[0].currentStyle.height:d.d.container.css("height"),"h");g=d.d.origWidth?d.d.origWidth:a.browser.opera?d.d.container.width():d.getVal(g?d.d.container[0].currentStyle.width:d.d.container.css("width"),"w");var i=d.d.data.outerHeight(!0),j=d.d.data.outerWidth(!0);d.d.origHeight=d.d.origHeight||h,d.d.origWidth=d.d.origWidth||g;var l=d.o.maxHeight?d.getVal(d.o.maxHeight,"h"):null,n=d.o.maxWidth?d.getVal(d.o.maxWidth,"w"):null;l=l&&l<e[0]?l:e[0],n=n&&n<e[1]?n:e[1];var o=d.o.minHeight?d.getVal(d.o.minHeight,"h"):"auto";h=h?d.o.autoResize&&h>l?l:h<o?o:h:i?i>l?l:d.o.minHeight&&o!=="auto"&&i<o?o:i:o,l=d.o.minWidth?d.getVal(d.o.minWidth,"w"):"auto",g=g?d.o.autoResize&&g>n?n:g<l?l:g:j?j>n?n:d.o.minWidth&&l!=="auto"&&j<l?l:j:l,d.d.container.css({height:h,width:g}),d.d.wrap.css({overflow:i>h||j>g?"auto":"visible"}),d.o.autoPosition&&d.setPosition()},setPosition:function(){var a=this,b,c;b=e[0]/2-a.d.container.outerHeight(!0)/2,c=e[1]/2-a.d.container.outerWidth(!0)/2,a.o.position&&Object.prototype.toString.call(a.o.position)==="[object Array]"?(b=a.o.position[0]||b,c=a.o.position[1]||c):(b=b,c=c),a.d.container.css({left:c,top:b})},watchTab:function(b){var c=this;if(a(b.target).parents(".simplemodal-container").length>0){c.inputs=a(":input:enabled:visible:first, :input:enabled:visible:last",c.d.data[0]);if(!b.shiftKey&&b.target===c.inputs[c.inputs.length-1]||b.shiftKey&&b.target===c.inputs[0]||c.inputs.length===0)b.preventDefault(),c.focus(b.shiftKey?"last":"first")}else b.preventDefault(),c.focus()},open:function(){var b=this;b.d.iframe&&b.d.iframe.show(),a.isFunction(b.o.onOpen)?b.o.onOpen.apply(b,[b.d]):(b.d.overlay.show(),b.d.container.show(),b.d.data.show()),b.o.focus&&b.focus(),b.bindEvents()},close:function(){var b=this;if(!b.d.data)return!1;b.unbindEvents();if(a.isFunction(b.o.onClose)&&!b.occb)b.occb=!0,b.o.onClose.apply(b,[b.d]);else{if(b.d.placeholder){var c=a("#simplemodal-placeholder");b.o.persist?c.replaceWith(b.d.data.removeClass("simplemodal-data").css("display",b.display)):(b.d.data.hide().remove(),c.replaceWith(b.d.orig))}else b.d.data.hide().remove();b.d.container.hide().remove(),b.d.overlay.hide(),b.d.iframe&&b.d.iframe.hide().remove(),setTimeout(function(){b.d.overlay.remove(),b.d={}},10)}}}}(jQuery),function(a){a.fn.SignUp=function(b){var c={},d=a.extend(c,b),e=function(a,b,c){var d=$('input[name="'+a+'"]',c),e=$('small[data-for="'+a+'"]',c),f=function(){b(d,e)};d.length&&(d.bind("change",f).bind("paste",f).bind("focus",f).bind("blur",f).bind("keyup",f),f())};return this.each(function(){e("user[password]",function(a,b){a.val().length<4?(a.addClass("invalid").removeClass("valid"),b.addClass("hint_invalid").removeClass("hint_valid")):(a.removeClass("invalid").addClass("valid"),b.removeClass("hint_invalid").addClass("hint_valid"))},this);var a=null,b,c,d=$('div.indicator[data-for="user[login]"]'),f=0,g=function(){f==0?d.addClass("hidden"):d.removeClass("hidden")};e("user[login]",function(d,e){if(d.val()==c)return;c=d.val();var h=!(c.length<3);if(h){var i=c.match(/[a-zA-Z0-9_\-]+/);h=h&&i&&i[0]&&i[0]==c}a&&a.abort(),h?(clearTimeout(b),b=setTimeout(function(){f++,g(),a=$.ajax({url:"/users/free.json",cache:!1,type:"GET",data:{login:c},complete:function(){f--,g()},success:function(a){a.free?(d.removeClass("invalid").addClass("valid"),e.removeClass("hint_invalid").addClass("hint_valid")):(d.addClass("invalid").removeClass("valid"),e.addClass("hint_invalid").removeClass("hint_valid"))}})},500)):(d.addClass("invalid").removeClass("valid"),e.addClass("hint_invalid").removeClass("hint_valid"))},this),e("user[email]",function(a,b){var c=a.val(),d=!(c.length<6);if(d){var e=/^[A-Z0-9_%\-\+\.\']+@(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2,4}|museum|travel)$/i,f=c.match(e);d=d&&f!==null&&f[0]&&f[0]==c}d?(a.removeClass("invalid").addClass("valid"),b.removeClass("hint_invalid").addClass("hint_valid")):(a.addClass("invalid").removeClass("valid"),b.addClass("hint_invalid").removeClass("hint_valid"))},this)})}}(jQuery),$(document).ready(function(){$("form.user").SignUp()})
