﻿/*resize*/
function resize_height(){
	
	$('.middle').css('height','auto');
	$('.middle').css('height',$('.middle').height()+28);
	
}
/*end resize*/
	
jQuery(window).load(function() {    
	
	resize_height();
	prettyPrint();
	
});

$(document).ready(function(){
	
	/*each blockuote*/
	$('blockquote').each(function(){
		
		$(this).append('<span class="blq_kav"></span>');
		
	});
	/*end each blockuote*/
	
	/*navigation*/
	$('.navigation ul li.active').next('li').children('a').css('border-left','none');
	/*end navigation*/
	
	/*pagination*/
	$('.pagination ul li a').mouseenter(function(){
		
		if(!$(this).parent('li').hasClass('active')){
			
			$(this).animate({ 'borderBottomColor':'#d0d0d0', 'backgroundColor': '#e5e5e5', 'color':'#000' }, 200);
			
		}
		
	});
	$('.pagination ul li a').mouseleave(function(){
		
		if(!$(this).parent('li').hasClass('active')){
			
			$(this).animate({ 'borderBottomColor':'#eee', 'backgroundColor': '#eee', 'color':'#5d5d5d' }, 300);
			
		}
		
	});
	/*end pagination*/
	
	/*popular*/
	/* $('.pop_elem').hover(
		
		function() {

			$(this).children(".pop_desc").stop(true,true).animate({opacity: 'show', top: '90'}, 'slow');
			
		},
		function() {
			
			$(this).children(".pop_desc").stop(true,true).animate({opacity: "hide", top: "85"}, "fast");
			
		}
		
	); 
	/*end popular*/
	
	/*comments*/
	function remove_addreplay(){
		
		$('.comment_form.replay').remove();
		
	}
	
	$('.comment_replay_link a').click(function(){
		
		remove_addreplay();
		
		$('.comment_form').hide();
		
		var action = $('#commentform').attr('action');
		var comid = $(this).parents('.comment').attr('id');
			comid = comid.split('_');
		var postid = $('input[name="comment_post_ID"]').val();
		var name = '';
			if($('#author').size()){
				name = $('#author').val();
			}
		var email = '';
			if($('#email').size()){
				email = $('#email').val();
			}
		var url = '';
			if($('#url').size()){
				url = $('#url').val();
			}
		
		var spam_textarea_name = $('textarea.cm_mess#comment').attr('name');
		
		console.log(spam_textarea_name);
		
		$(this).parents('.comment').next('.place_for_from').append('\
			\
			<form action="'+action+'" id="repcomform" method="post">\
			<div id="cm_form" class="comment_form replay">\
				<div class="cm_title">\
					ОСТАВИТЬ КОММЕНТАРИЙ\
					<a href="#" class="cancel_replay">отменить</a>\
				</div>\
				<div class="first_inputs">\
					<input type="text" name="author" value="'+name+'" placeholder="Имя" class="cm_name" />\
					<input type="text" name="email" value="'+email+'" placeholder="Email" class="cm_email" />\
					<input type="text" name="url" value="'+url+'" placeholder="Адрес сайта" class="cm_site" />\
				</div>\
				<div class="cm_messagebox">\
					<textarea class="cm_mess" id="comment" name="'+spam_textarea_name+'" aria-required="true"></textarea>\
					<input type="submit" value="оставить комментарий" class="cm_subm sbm">\
					<input type="hidden" name="comment_post_ID" value="'+postid+'" id="comment_post_ID" />\
					<input type="hidden" name="comment_parent" id="comment_parent" value="'+comid[1]+'" />\
				</div>\
			</div>\
			</form>\
			\
		');
		
		resize_height();
		
		return false;
	});
	
	$('.cancel_replay').live('click',function(){
		
		remove_addreplay();
		$('.comment_form').show();
		
		resize_height();
		
		return false;
	});
	
	$('#commentform').submit(function(){
	
		var error = false;
		
		if($('#commentform #author').val() == ''){
			$('#commentform #author').addClass('error');
			error = true;
		}
		else{
			$('#commentform #author').removeClass('error');
		}
		if($('#commentform #email').val() == ''){
			$('#commentform #email').addClass('error');
			error = true;
		}
		else{
			$('#commentform #email').removeClass('error');
		}
		if($('#commentform #comment').val() == ''){
			$('#commentform #comment').addClass('error');
			error = true;
		}
		else{
			$('#commentform #comment').removeClass('error');
		}
		
		if(error){
			
			//return false;
			
		}
	
	});
	$('#repcomform').live('submit',function(){
		
		var error = false;
		
		if($('#repcomform input[name="author"]').val() == ''){
			$('#repcomform input[name="author"]').addClass('error');
			error = true;
		}
		else{
			$('#repcomform input[name="author"]').removeClass('error');
		}
		if($('#repcomform input[name="email"]').val() == ''){
			$('#repcomform input[name="email"]').addClass('error');
			error = true;
		}
		else{
			$('#repcomform input[name="email"]').removeClass('error');
		}
		if($('#repcomform textarea[name="comment"]').val() == ''){
			$('#repcomform textarea[name="comment"]').addClass('error');
			error = true;
		}
		else{
			$('#repcomform textarea[name="comment"]').removeClass('error');
		}
		
		if(error){
			
			return false;
			
		}
		
	});
	
	/*end comments*/
	
	/*feedburnerform*/
	
	$('#feedburnerform').submit(function(){
		
		if($('#feedburnerform input.emial').val() == ''){
			
			$('#feedburnerform input.emial').addClass('error');
			return false;
		}
		else{
			
			$('#feedburnerform input.emial').removeClass('error');
			
		}
		
	});
	
	/*end feedburnerform*/
	
	/*search form*/
	/* $('.sinput').focus(function(){
		
		$(this).parent('.search').animate({'width':'696px'},'fast');
		$(this).animate({'width':'669px'},'fast');
		
	});
	
	$('.sinput').blur(function(){
		
		$(this).parent('.search').animate({'width':'211px'},'fast');
		$(this).animate({'width':'180px'},'fast');
		
	}); */

	/*end search form*/
	
});
