$(document).ready(function(){
    
    /* отправка комментария */
    $("#commentform").submit(function() {
    	var params = $(this).serialize();	
    			 				
     	jQuery.ajax({			
    	  	data: params,
    		type: "POST",
    		url: '/back/comment',
    		timeout: 10000,			
    		error: function(xhr, desc, e) {
    			$("#error").html("Ошибка, повтори свою попытку");
    			reloadCaptcha();						
    		},			
    		success: function(response) {
    			$(".error").hide();
    			$(response).insertBefore("#result");
    			reloadCaptcha();																											
    		}	
    	});	
    	
    	return false;
    });
    
});

/* чистим форму комментариев */
function clearCommentForm(){
	var form = $("#commentform");
	
 	$(':input', form).each(function() {
    var type = this.type;
    var tag = this.tagName.toLowerCase(); 
    
    if (type == 'text' || tag == 'textarea')
    	this.value = "";
    
  });
  	
}


/* обновляем капчу */
function reloadCaptcha(){
	
	$("#captchaImg").attr("src","/captcha/"+Math.round(Math.random()*1000));
	$(".captchaText").attr("value","");
	
	return true;
}

/* разворачивающиеся блоки */
function toggleBlock(block){
	if ($("#"+block).css("display") == 'block'){	
		//сворачиваем				
		$("#"+block).slideUp("slow");
	}else{										
		$("#"+block).slideDown("slow");
		
	}	
}		

function preloader(){
    $("#overlay").hide();
}

function moveTo(divId, mainId) {			
	var topIn = jQuery("#"+divId).css("top");		
	var leftIn = jQuery("#"+divId).css("left");
	jQuery("#"+mainId).stop();
	
	topIn = topIn.replace(/px/, "");
	topIn = topIn - 200;
	
	leftIn = leftIn.replace(/px/, "");
	leftIn = leftIn - 250;
	
    jQuery("#"+mainId).animate({ 
		top: "-"+topIn,
		left: "-"+leftIn
    	}, 450 );
	return false;		
}	