// when the DOM is ready:
$(document).ready(function () {

// find the div.fade elements and hook the hover event
  $('div.fade').hover(function() {
    // on hovering over, find the element we want to fade *up*
    var fade = $('> div', this);
    
    // if the element is currently being animated (to a fadeOut)...
    if (fade.is(':animated')) {
      // ...take it's current opacity back up to 1
      fade.stop().fadeTo(400, 1);
    } else {
      // fade in quickly
      fade.fadeIn(400);
    }
  }, function () {
    // on hovering out, fade the element out
    var fade = $('> div', this);
    if (fade.is(':animated')) {
      fade.stop().fadeTo(2500, 0);
    } else {
      // fade away slowly
      fade.fadeOut(2500);
    }
            }); 
	// bind 'reviewsForm' and provide a simple callback function 
	$('#registerForm').ajaxForm({
                target: "#divToUpdate2",
				beforeSubmit:  beforeSubmitFunction,
				success: function() {
        				$('#divToUpdate').empty().append('<p>Обратите внимание, что наш каталог сайтов модерируется вручную, мы подбираем в него только интересные и полезные сайты.</p><p>Мы свяжемся с Вами по e-mail. Спасибо!</p>');
  							}
            }); 

// уголок

$("#pageflip").hover(function() { //On hover...
	$("#pageflip img , .msg_block").stop()
		.animate({ //Animate and expand the image and the msg_block (Width + height)
			width: '307px',
			height: '319px'
		}, 500);
	} , function() {
	$("#pageflip img").stop() //On hover out, go back to original size 50x52
		.animate({
			width: '50px',
			height: '52px'
		}, 220);
	$(".msg_block").stop() //On hover out, go back to original size 50x50
		.animate({
			width: '50px',
			height: '50px'
		}, 200); //Note this one retracts a bit faster (to prevent glitching in IE)
});




});
    
	function beforeSubmitFunction(formData, jqForm, options)
		{
		if($('input[name=user_name]').attr("value")=='') { $('input[name=user_name]').css('border','1px solid #ff0000').css('background-color','#dffb4b5'); alert("Введите Ваше имя."); return false;}
		if($('input[name=user_email]').attr("value")=='') { $('input[name=user_email]').css('border','1px solid #ff0000').css('background-color','#ffb4b5'); alert("Введите Ваш e-mail."); return false;}
		var re = /^\w+([\.-]?\w+)*@(((([a-z0-9]{2,})|([a-z0-9][-][a-z0-9]+))[\.][a-z0-9])|([a-z0-9]+[-]?))+[a-z0-9]+\.([a-z]{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/i;
		if(!re.test(eval("$('input[name=user_email]').attr(\"value\")"))){ $('input[name=user_email]').css('border','1px solid #ff0000').css('background-color','#ffb4b5'); alert("E-mail введен неверно."); return false;}
		if($('input[name=site_url]').attr("value")=='') { $('input[name=site_url]').css('border','1px solid #ff0000').css('background-color','#ffb4b5'); alert("Введите адрес сайта."); return false;}
		if($('input[name=site_name]').attr("value")=='') { $('input[name=site_name]').css('border','1px solid #ff0000').css('background-color','#ffb4b5'); alert("Введите название сайта."); return false;}
		if($('input[name=site_description]').attr("value")=='') { $('input[name=site_description]').css('border','1px solid #ff0000').css('background-color','#ffb4b5'); alert("Введите описание сайта."); return false;}
		if($('input[name=site_backlink]').attr("value")=='') { $('input[name=site_backlink]').css('border','1px solid #ff0000').css('background-color','#ffb4b5'); alert("Введите адрес страницы на которой разместите ссылку на наш сайт."); return false;}

		$('#loading').css('visibility','visible');
		return true;
		}
	



