/*
* Inline Form Validation Engine, jQuery plugin
* Copyright(c) 2009, Cedric Dugas
* http://www.position-relative.net
*/
jQuery.fn.validationEngine = function(settings) {
allRules={"required":{"regex":"none","alertText":"Это поле обязательно нужно заполнить","alertTextCheckboxMultiple":"Пожалуйста, выберите","alertTextCheckboxe":"Этот флажок должен быть отмечен"},"length":{"regex":"none","alertText":"Должно быть от ","alertText2":" до ","alertText3":" символов."},"minCheckbox":{"regex":"none","alertText":"Поставлено слишком много флажков"},"confirm":{"regex":"none","alertText":"Поле не соответствует требованиям"},"telephone":{"regex":"/^[0-9\-\–\+\(\)\ ]+$/","alertText":"Введите корректный номер телефона"},"email":{"regex":"/^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/","alertText":"Введите корректный e-mail"},"date":{"regex":"/^[0-9]{1,2}\-\[0-9]{1,2}\-\[0-9]{4}$/","alertText":"введите корректную дату (формат: DD-MM-YYYY)"},"onlyNumber":{"regex":"/^[0-9\ ]+$/","alertText":"В этом поле допустимы только цифры"},"noSpecialCaracters":{"regex":"/^[0-9a-zA-Zа-яА-Я]+$/","alertText":"В этом поле допустимы только цифры и буквы"},"onlyLetter":{"regex":"/^[a-zA-Zа-яА-Я\-\–\.\,\ \']+$/","alertText":"В этом поле допустимы только буквы"}}
settings = jQuery.extend({	allrules:allRules,success : false,failure : function() {}}, settings);$("form").bind("submit", function(caller){if(submitValidation(this) == false){if (settings.success){settings.success && settings.success(); return false;}}else{settings.failure && settings.failure(); return false;}});$(this).not("[type=checkbox]").bind("blur", function(caller){loadValidation(this)});$(this+"[type=checkbox]").bind("click", function(caller){loadValidation(this)});var buildPrompt = function(caller,promptText) {var divFormError = document.createElement('div');var formErrorContent = document.createElement('div');var arrow = document.createElement('div');$(divFormError).addClass("formError");$(divFormError).addClass($(caller).attr("name"));$(formErrorContent).addClass("formErrorContent");$(arrow).addClass("formErrorArrow");$("body").append(divFormError);$(divFormError).append(arrow);$(divFormError).append(formErrorContent);$(arrow).html('<div class="line10"></div><div class="line9"></div><div class="line8"></div><div class="line7"></div><div class="line6"></div><div class="line5"></div><div class="line4"></div><div class="line3"></div><div class="line2"></div><div class="line1"></div>');$(formErrorContent).html(promptText);/* далее идет вызов плагина уголков! */$(formErrorContent).corner('round 5px');callerTopPosition = $(caller).offset().top;callerleftPosition = $(caller).offset().left;callerWidth =  $(caller).width();callerHeight =  $(caller).height();inputHeight = $(divFormError).height();if (callerWidth > 250) callerleftPosition = callerleftPosition + callerWidth -214; else callerleftPosition = callerleftPosition - 20;callerTopPosition = callerTopPosition  -inputHeight -8;$(divFormError).css({top:callerTopPosition,left:callerleftPosition,opacity:0});/* добавлено убирание предупреждения */$(divFormError).fadeTo(200,1).delay(3000).fadeTo(200,0,function(){$(this).remove();})};var updatePromptText = function(caller,promptText) {updateThisPrompt =  $(caller).attr("name");$("."+updateThisPrompt).find(".formErrorContent").html(promptText);callerTopPosition  = $(caller).offset().top;inputHeight = $("."+updateThisPrompt).height();callerTopPosition = callerTopPosition  -inputHeight -10;$("."+updateThisPrompt).animate({top:callerTopPosition});};var loadValidation = function(caller) {rulesParsing = $(caller).attr('class');rulesRegExp = /\[(.*)\]/;getRules = rulesRegExp.exec(rulesParsing);str = getRules[1];pattern = /\W+/;result= str.split(pattern);	var validateCalll = validateCall(caller,result);return validateCalll;};var validateCall = function(caller,rules) {var promptText ="";var prompt = $(caller).attr("name");var caller = caller;isError = false;callerType = $(caller).attr("type");for (i=0; i<rules.length;i++){switch (rules[i]){case "optional": if(!$(caller).val()){closePrompt(caller);return isError;}break;case "required": _required(caller,rules);break;case "custom": _customRegex(caller,rules,i);break;case "length": _length(caller,rules,i);break;case "minCheckbox": _minCheckbox(caller,rules,i);break;case "confirm": _confirm(caller,rules,i);break;default :;};};if (isError == true){if($("input[name="+prompt+"]").size()> 1 && callerType == "radio") {caller = $("input[name="+prompt+"]:first")}($("."+prompt).size() ==0) ? buildPrompt(caller,promptText)	: updatePromptText(caller,promptText)}else{closePrompt(caller)}function _required(caller,rules){callerType = $(caller).attr("type");if (callerType == "text" || callerType == "password" || callerType == "textarea"){if(!$(caller).val()){isError = true;promptText += settings.allrules[rules[i]].alertText+"<br />"}	}if (callerType == "radio" || callerType == "checkbox" ){callerName = $(caller).attr("name");if($("input[name="+callerName+"]:checked").size() == 0) {isError = true;if($("input[name="+callerName+"]").size() ==1) {promptText += settings.allrules[rules[i]].alertTextCheckboxe+"<br />";}else{promptText += settings.allrules[rules[i]].alertTextCheckboxMultiple+"<br />";}}}if (callerType == "select-one") {callerName = $(caller).attr("name");if(!$("select[name="+callerName+"]").val()) {isError = true;promptText += settings.allrules[rules[i]].alertText+"<br />";}}if (callerType == "select-multiple") {callerName = $(caller).attr("id");if(!$("#"+callerName).val()) {isError = true;promptText += settings.allrules[rules[i]].alertText+"<br />";}}}function _customRegex(caller,rules,position){customRule = rules[position+1];pattern = eval(settings.allrules[customRule].regex);if(!pattern.test($(caller).attr('value'))){isError = true;promptText += settings.allrules[customRule].alertText+"<br />";}}function _confirm(caller,rules,position){confirmField = rules[position+1];if($(caller).attr('value') != $("#"+confirmField).attr('value')){isError = true;promptText += settings.allrules["confirm"].alertText+"<br />";}}function _length(caller,rules,position){startLength = eval(rules[position+1]);endLength = eval(rules[position+2]);feildLength = $(caller).attr('value').length;if(feildLength<startLength || feildLength>endLength){isError = true;promptText += settings.allrules["length"].alertText+startLength+settings.allrules["length"].alertText2+endLength+settings.allrules["length"].alertText3+"<br />";}}function _minCheckbox(caller,rules,position){nbCheck = eval(rules[position+1]);groupname = $(caller).attr("name");groupSize = $("input[name="+groupname+"]:checked").size();if(groupSize > nbCheck){isError = true;promptText += settings.allrules["minCheckbox"].alertText+"<br />";}}return(isError) ? isError : false;};var closePrompt = function(caller) {closingPrompt = $(caller).attr("name");$("."+closingPrompt).fadeTo("fast",0,function(){$("."+closingPrompt).remove();});};var submitValidation = function(caller) {var stopForm = false;$(caller).find(".formError").remove();var toValidateSize = $(caller).find("[class^=validate]").size();$(caller).find("[class^=validate]").each(function(){var validationPass = loadValidation(this);return(validationPass) ? stopForm = true : "";});if(stopForm){destination = $(".formError:first").offset().top;/* $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100); */return true;}else{return false;}};};

/*
* hoverIntent r5 // 2007.03.27
* http://cherne.net/brian/resources/jquery.hoverIntent.html
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

/*
* jQuery corner plugin: simple corner rounding
* Examples and documentation at: http://jquery.malsup.com/corner/
* version 2.03 (05-DEC-2009)
* Dual licensed under the MIT and GPL licenses
* Модифицировал Н. Громов: если браузер поддерживает CSS3, к целевому блоку добавляется класс native
*/
;(function($) { 
var ua = navigator.userAgent;
var moz = $.browser.mozilla && /gecko/i.test(ua);
var webkit = $.browser.safari && /Safari\/[5-9]/.test(ua);
var expr = $.browser.msie && (function() {
var div = document.createElement('div');
try { div.style.setExpression('width','0+0'); div.style.removeExpression('width'); }
catch(e) { return false; }
return true;
})();
function sz(el, p) { 
return parseInt($.css(el,p))||0; 
};
function hex2(s) {
var s = parseInt(s).toString(16);
return ( s.length < 2 ) ? '0'+s : s;
};
function gpc(node) {
for ( ; node && node.nodeName.toLowerCase() != 'html'; node = node.parentNode ) {
var v = $.css(node,'backgroundColor');
if (v == 'rgba(0, 0, 0, 0)')
continue; // webkit
if (v.indexOf('rgb') >= 0) { 
var rgb = v.match(/\d+/g); 
return '#'+ hex2(rgb[0]) + hex2(rgb[1]) + hex2(rgb[2]);
}
if ( v && v != 'transparent' )
return v;
}
return '#ffffff';
};
function getWidth(fx, i, width) {
switch(fx) {
case 'round':  return Math.round(width*(1-Math.cos(Math.asin(i/width))));
case 'cool':   return Math.round(width*(1+Math.cos(Math.asin(i/width))));
case 'sharp':  return Math.round(width*(1-Math.cos(Math.acos(i/width))));
case 'bite':   return Math.round(width*(Math.cos(Math.asin((width-i-1)/width))));
case 'slide':  return Math.round(width*(Math.atan2(i,width/i)));
case 'jut':    return Math.round(width*(Math.atan2(width,(width-i-1))));
case 'curl':   return Math.round(width*(Math.atan(i)));
case 'tear':   return Math.round(width*(Math.cos(i)));
case 'wicked': return Math.round(width*(Math.tan(i)));
case 'long':   return Math.round(width*(Math.sqrt(i)));
case 'sculpt': return Math.round(width*(Math.log((width-i-1),width)));
case 'dog':    return (i&1) ? (i+1) : width;
case 'dog2':   return (i&2) ? (i+1) : width;
case 'dog3':   return (i&3) ? (i+1) : width;
case 'fray':   return (i%2)*width;
case 'notch':  return width; 
case 'bevel':  return i+1;
}
};
$.fn.corner = function(options) {
if (this.length == 0) {
if (!$.isReady && this.selector) {
var s = this.selector, c = this.context;
$(function() {
$(s,c).corner(options);
});
}
return this;
}
return this.each(function(index){
var $this = $(this);
var o = [ options || '', $this.attr($.fn.corner.defaults.metaAttr) || ''].join(' ').toLowerCase();
var keep = /keep/.test(o);
var cc = ((o.match(/cc:(#[0-9a-f]+)/)||[])[1]); 
var sc = ((o.match(/sc:(#[0-9a-f]+)/)||[])[1]);
var width = parseInt((o.match(/(\d+)px/)||[])[1]) || 10;
var re = /round|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dog/;
var fx = ((o.match(re)||['round'])[0]);
var edges = { T:0, B:1 };
var opts = {
TL:  /top|tl|left/.test(o),       TR:  /top|tr|right/.test(o),
BL:  /bottom|bl|left/.test(o),    BR:  /bottom|br|right/.test(o)
};
if ( !opts.TL && !opts.TR && !opts.BL && !opts.BR )
opts = { TL:1, TR:1, BL:1, BR:1 };
if ($.fn.corner.defaults.useNative && fx == 'round' && (moz || webkit) && !cc && !sc) {
if (opts.TL)
$this.css(moz ? '-moz-border-radius-topleft' : '-webkit-border-top-left-radius', width + 'px');
if (opts.TR)
$this.css(moz ? '-moz-border-radius-topright' : '-webkit-border-top-right-radius', width + 'px');
if (opts.BL)
$this.css(moz ? '-moz-border-radius-bottomleft' : '-webkit-border-bottom-left-radius', width + 'px');
if (opts.BR)
$this.css(moz ? '-moz-border-radius-bottomright' : '-webkit-border-bottom-right-radius', width + 'px');
$this.addClass('native');
return;
}
else
$this.addClass('not-native');
var strip = document.createElement('div');
strip.style.overflow = 'hidden';
strip.style.height = '1px';
strip.style.backgroundColor = sc || 'transparent';
strip.style.borderStyle = 'solid';
var pad = {
T: parseInt($.css(this,'paddingTop'))||0,     R: parseInt($.css(this,'paddingRight'))||0,
B: parseInt($.css(this,'paddingBottom'))||0,  L: parseInt($.css(this,'paddingLeft'))||0
};
if (typeof this.style.zoom != undefined) this.style.zoom = 1; // force 'hasLayout' in IE
if (!keep) this.style.border = 'none';
strip.style.borderColor = cc || gpc(this.parentNode);
var cssHeight = $.curCSS(this, 'height');
for (var j in edges) {
var bot = edges[j];
if ((bot && (opts.BL || opts.BR)) || (!bot && (opts.TL || opts.TR))) {
strip.style.borderStyle = 'none '+(opts[j+'R']?'solid':'none')+' none '+(opts[j+'L']?'solid':'none');
var d = document.createElement('div');
$(d).addClass('jquery-corner');
var ds = d.style;
bot ? this.appendChild(d) : this.insertBefore(d, this.firstChild);
if (bot && cssHeight != 'auto') {
if ($.css(this,'position') == 'static')
this.style.position = 'relative';
ds.position = 'absolute';
ds.bottom = ds.left = ds.padding = ds.margin = '0';
if (expr)
ds.setExpression('width', 'this.parentNode.offsetWidth');
else
ds.width = '100%';
}
else if (!bot && $.browser.msie) {
if ($.css(this,'position') == 'static')
this.style.position = 'relative';
ds.position = 'absolute';
ds.top = ds.left = ds.right = ds.padding = ds.margin = '0';
if (expr) {
var bw = sz(this,'borderLeftWidth') + sz(this,'borderRightWidth');
ds.setExpression('width', 'this.parentNode.offsetWidth - '+bw+'+ "px"');
}
else
ds.width = '100%';
}
else {
ds.position = 'relative';
ds.margin = !bot ? '-'+pad.T+'px -'+pad.R+'px '+(pad.T-width)+'px -'+pad.L+'px' : 
		(pad.B-width)+'px -'+pad.R+'px -'+pad.B+'px -'+pad.L+'px';                
}
for (var i=0; i < width; i++) {
var w = Math.max(0,getWidth(fx,i, width));
var e = strip.cloneNode(false);
e.style.borderWidth = '0 '+(opts[j+'R']?w:0)+'px 0 '+(opts[j+'L']?w:0)+'px';
bot ? d.appendChild(e) : d.insertBefore(e, d.firstChild);
}
}
}
});
};
$.fn.uncorner = function() { 
if (moz || webkit)
this.css(moz ? '-moz-border-radius' : '-webkit-border-radius', 0);
$('div.jquery-corner', this).remove();
return this;
};
$.fn.corner.defaults = {
useNative: true, 
metaAttr:  'data-corner' 
};
})(jQuery);



/*
Nikolay Gromov
Author URI: http://nicothin.ru
*/
$(document).ready(function() {

// валидатор форм
$('[class^=validate]').validationEngine({
success : false,
failure : function() {}
})

// главное меню
var li = $('#header ul.main_nav li:first');
$(li).children('div').css({display:'block'});
var liul = $(li).children('div').children('ul');
var ulheight = $(liul).height() + 16;
$(liul).css({display:'block',marginTop:-ulheight});
$(li).children('div').css({display:'none'});
function megaHoverOver(){
$(li).children('a').addClass("hover");
$(li).children('div').css({display:'block'});
$(liul).stop().animate({marginTop: 0}, 200);
}
function megaHoverOut(){ 
$(liul).stop().animate({marginTop: -ulheight}, 500, function(){
$(li).children('a').removeClass("hover");
$(li).children('div').css({display:'none'});
});
}
var config = {    
sensitivity: 2,
interval: 10,
over: megaHoverOver,
timeout: 300,
out: megaHoverOut
};
$(li).hoverIntent(config);

// уголки
$('.foto').css({border:'none'}).wrap('<div class="for-r" />').corner('round 3px').parent().corner('round 5px');
$('.big-inner2 a span b').wrap('<big />');
$('.pagination .pages *').wrapInner('<span />');
$('.big-inner2 a span b').corner('round 3px').parent().corner('round 5px');
$('.pagination a span, .pagination strong span').parent().corner('round 3px');

// работа инпута формы для поиска
$('#s').bind('focus',function(){
if ($(this).val() == 'Поиск...') $(this).val('');
}).bind('blur',function(){
if($(this).val() == '') $(this).val('Поиск...');
});

// закрытие блока сообщений об отправке/неотправке письма
$('.post-result a.cmw').click(function() {
$('.post-result').remove();
return false;
});

// открытие/закрытие блока с кодом картинки
$('a.you-blog-b').click(function() {
$('.img-code').show();
return false;
});
$('.img-code a.cmw').click(function() {
$('.img-code').hide();
return false;
});

// добавочная пагинация
$('.prev,.next').clone().appendTo('.cat-pagination')
}); 