// JavaScript Document

$(function()
{
	$('#content #scroll, #content-contact #scroll, #content-bright #scroll, #content-winedinner #scroll').jScrollPane({scrollbarWidth:8, dragMinHeight:20});
	$("#thumbnails").jCarouselLite({
        btnNext: "#thumbnails-dn",
        btnPrev: "#thumbnails-up",
		vertical: true,
		visible: 5,
		mouseWheel: true,
		easing: "easeOutQuart",
		speed: 500
    });
	$('#menu a:not(.active) span')
	.css( {backgroundPosition: "0 0"} )
	.mouseover(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 19px)"}, 
			400, 'easeOutBack')
		})
	.mouseout(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 0)"}, 
			400, 'easeOutBack')
		})
	$('#quickmenu li:not(.active) span')
	.css( {backgroundPosition: "20px 0"} )
	.mouseover(function(){
		$(this).stop().animate(
			{backgroundPosition:"(10px 0)"}, 
			200, 'easeOutBack')
		})
	.mouseout(function(){
		$(this).stop().animate(
			{backgroundPosition:"(20px 0)"}, 
			300, 'easeOutBack')
		})
	$('#gallery-main img').attr({src:'images/gallery/1.jpg'});
	$('#thumbnails a')
	.click(function(){
		$('#gallery-main img')
		.load(
			function(){
				$(this).fadeIn(400);
			}
		)
		.attr({src:''})
		.hide()
		.attr({src:$(this).attr('href')})
		return false;
	})
	.css( {clip: "rect(4px, 51px, 51px, 4px)"} )
	.mouseover(function(){
		$(this).stop().animate(
			{clip: "rect(1px, 54px, 54px, 1px)"}, 
			100, 'easeOutBack')
		})
	.mouseout(function(){
		$(this).stop().animate(
			{clip: "rect(4px, 51px, 51px, 4px)"}, 
			100, 'easeOutBack')
		})
	$('#thumbnails-up span, #thumbnails-dn span')
	.css( {backgroundPosition: "0 0"} )
	.mouseover(function(){
		$(this).css( {backgroundPosition: "0 21px"} )
		})
	.mouseout(function(){
		$(this).css( {backgroundPosition: "0 0"} )
		})

	$('#reservation-form span, #newsletter-form span')
	.click(function() {
		$(this)
		.fadeOut(500)
		.parent().children('input')
			.focus();
	});
	$('#reservation-form input, #newsletter-form input')
	.blur(function() {
		if ( $(this).attr('value') == '' ) {
			$(this).parent().children('span')
			.fadeIn(500);
		}
	})
	.focus(function() {
		$(this).parent().children('span')
		.fadeOut(500);
	})
	$('#reservation-koszonjuk').hide();
	$('#newsletter-koszonjuk').hide();
	$('#newsletter-ok').hide();

	$('#reservation-form').ajaxForm( { beforeSubmit: validateReservation } );
	$('#newsletter-form').ajaxForm( { beforeSubmit: validateNewsletter } );
	if ( document.location.hash == '#ok' ) {
				$('#newsletter-ok').fadeIn(1000);
	}
	$('#reservation-submit-label span, #newsletter-submit-label span')
	.css( {display: "block"} )
	.hide()
	.mouseout(function(){
		$(this).fadeOut(400);
	})
	$('#reservation-submit-label, #newsletter-submit-label')
	.mouseover(function(){
		$(this).children('span').fadeIn(200);
	})
	
	$('#menumenu .over')
	.css( { display: 'block', opacity: 0 } )
	
	$('#menumenu a')
	.css( {backgroundPosition:"0 0px"} )
	.mouseover(function(){
		$(this)
		.stop().animate({backgroundPosition:"(0 5px)"}, 200, 'easeOutCubic')
		.children('.over').stop().animate( {opacity: 1}, 300, 'easeOutCubic' );
	})
	.mouseout(function(){
		$(this)
		.stop().animate({backgroundPosition:"(0 0px)"}, 300, 'easeOutCubic' )
		.children('.over').stop().animate( {opacity: 0}, 200, 'easeOutCubic' );
	})
});
function validateReservation( formData, jqForm, options ) {
	var form = jqForm[0];
	var lang = 'hu';
	if ( form.action == 'includes/reservation.php?lang=en' ) {
		lang = 'en;'
	}

	for (var i=0; i < formData.length; i++) { 
        if (!formData[i].value) { 
            if ( lang == 'hu' ) {
				alert( 'Kérjük, töltsön ki minden mezőt!' );
			} else {
				alert( 'Please fill in all fields!' );
			}
            return false; 
        } 
    }
	if ( !isValidEmail( form.email.value ) ) {
		if ( lang == 'hu' ) {
			alert( 'Kérjük, ellenőrizze e-mail címét, hogy válaszolni tudjunk foglalására!' );
		} else {
			alert( 'Please check your e-mail address, to let us answer your reservatioin!' );
		}
		return false;
	}
	if ( lang == 'hu' ) {
		if ( form.smoking.value != 'igen' && form.smoking.value != 'nem' ) {
			alert( 'Kérjük adja meg, hogy dohányzó helyiségben kíván-e asztalt foglalni! (igen/nem)' );
			return false;
		}
	} else {
		if ( form.smoking.value != 'yes' && form.smoking.value != 'no' ) {
			alert( 'Please choose if you would like to reserve to a smoking area or not! (yes/no)' );
			return false;
		}
	}
	$('#reservation-koszonjuk').fadeIn(1000);
}
function validateNewsletter( formData, jqForm, options ) {
	var form = jqForm[0];
	var lang = 'hu';
	if ( form.action == 'includes/newsletter.php?lang=en' ) {
		lang = 'en;'
	}

	for (var i=0; i < formData.length; i++) { 
        if (!formData[i].value) { 
            if ( lang == 'hu' ) {
				alert( 'Kérjük, töltsön ki minden mezőt!' );
			} else {
				alert( 'Please fill in all fields!' );
			}
            return false; 
        } 
    }
	if ( !isValidEmail( form.email.value ) ) {
		if ( lang == 'hu' ) {
			alert( 'Kérjük, ellenőrizze e-mail címét!' );
		} else {
			alert( 'Please check your e-mail address!' );
		}
		return false;
	}
	$('#newsletter-koszonjuk').fadeIn(1000);
}
function isValidEmail(email){ 
    var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/ 
    if(RegExp.test(email)){ 
        return true; 
    }else{ 
        return false; 
    } 
} 