$(document).ready(function(){

	$('#menu div.button').each(function (i) {
		var submenu = '#submenu_' + $(this).attr("rel");
		$(this).mouseover(function() {
			$(submenu).css("display","block");
		});
		$(this).mouseout(function() {
			$(submenu).css("display","none");
		});
	});
	$('#menu div.button div.submenu').each(function (i) {
		$(this).mouseover(function() {
			$(this).css("display","block");
		});
		$(this).mouseout(function() {
			$(this).css("display","none");
		});
	});
	$('#menu div.button div.submenu a').each(function (i) {
		$(this).mouseover(function() {
			$(this).addClass("select");
		});
		$(this).mouseout(function() {
			$(this).removeClass("select");
		});
	});

    $('img.photo').each(function (i) {
        $(this).click(function() {
            var big_photo = $(this).attr("rel");
            //$("#big_photo_block").fadeOut();
            $("img#big_photo").attr("src",'/images/'+big_photo);
            //$("#big_photo_block").fadeIn();
		});
    });

    $('#cover').cycle({ 
        fx:      'cover', 
        speed:    1500, 
        timeout:  4000
    });
    
    
    
    $('#order #send').click(function(){
		var errors = 0;
		var form = document.forms.order;
		$('#message').html('');
		
		$('#order .check_null').each(function (i) {
			if(this.value == ''){
				$(this).addClass('error');
				var error_text = $(this).attr("rel");
				$('#message').append(error_text);
				errors++;
			} else {
				$(this).removeClass('error');
			}
		});
		
		$('#order .check_phone').each(function (i) {
			if((testPhone(this.value) == false) || (this.value == '')){
				$(this).addClass('error');
				var error_text = $(this).attr("rel"); 
				$('#message').append(error_text);
				errors++;
			} else {
				$(this).removeClass('error');
			}
		});

		$('#order .check_email').each(function (i) {
			if((testEmail(this.value) == false) || (this.value == '')){
				$(this).addClass('error');
				var error_text = $(this).attr("rel"); 
				$('#message').append(error_text);
				errors++;
			} else {
				$(this).removeClass('error');
			}
		});

		if(errors == 0){
			$('#message').show('slow');
			form.submit();
		} else {
			$('#message').show('slow');
			return false;
		}
	});


	function testEmail(email){
		reg = /^[A-Za-z_\-\d.]+@{1}[A-Za-z\d.\-]+.[ru|su|com|org|net|tele|name|biz]$/;
		var result=reg.test(email);  
		return (result);
	}
	function testPhone(phone){
		reg = /^(?:8|\+7)? ?\(?(\d{3})\)? ?(\d{3})[ -]?(\d{2})[ -]?(\d{2})$/;
		var result=reg.test(phone);  
		return (result);
	}
   
});

