Cufon.replace('#mainMenu li a', { hover: true, fontFamily: 'Caslon', textShadow: '0px 2px 1px #000' });
Cufon.replace('h1', { fontFamily: 'Futura-Bold' });
Cufon.replace('h2', { fontFamily: 'Futura-Book' });

$(function() {
	
	//Open external links in a new window
	$('a[href^="http://"]')
	  .attr({target: "_blank"});
	
	//Homepage flash video
	$('#scenery').flash({ src:'/swf/Youngs-Scene.swf', wmode:'transparent', width:980, height:575 }, 
    { update: false });
	
	//Switch video
	$(".vidLink").click(function(){
		$('#youngsTV').flash({ src:'/swf/Youngs-'+ $(this).attr("id") +'.swf', wmode:'transparent', width:725, height:470 }, 
	    { update: false });
	    $(".vidLink").html("<a href='#'>Play video</a>");
	    $(this).html("Now playing");
	    $(".eventBox").hide();
	    $("." + $(this).attr("id")).show();
		return false;
	});
	
	//Contact form client side validation
	$("#contactForm").submit(function() {
		if ($("#firstName").val() == "") {
			$("#message").html("Error: Please fill all form fields.");
			return false;
		}
		if ($("#surname").val() == "") {
			$("#message").html("Error: Please fill all form fields.");
			return false;
		}
		if ($("#email").val() == "") {
			$("#message").html("Error: Please fill all form fields.");
			return false;
		}else if (!isValidEmailAddress($("#email").val())) {
			$("#message").html("Error: Invalid email address");
			return false;
		}
		if ($("#comments").val() == "") {
			$("#message").html("Error: Please fill all form fields.");
			return false;
		}
	});
	
	//Drinking age validation
	$("#drinkingAge").submit(function() {

		var min_age;
		if ( $("#country").val()=="US") {
			min_age = 21;
		}else{
			min_age = 18;
		}
		
		var dobYY = document.forms["drinkingAge"]["dobYY"].value;
		var dobMM= document.forms["drinkingAge"]["dobMM"].value;
		var dobDD= document.forms["drinkingAge"]["dobDD"].value;
		
		if (dobYY!="YY"&&dobMM!="MM"&&dobDD!="DD"){

			var realYear;
			if (dobYY>20) {			
				realYear = "19" + dobYY;
			}else {
				realYear = "20" + dobYY;
			}
			
			var year = parseInt(realYear);
			var month = parseInt(document.forms["drinkingAge"]["dobMM"].value) - 1;
			var day = parseInt(document.forms["drinkingAge"]["dobDD"].value);

			var theirDate = new Date((year + min_age), month, day);
			var today = new Date;

			if ( (today.getTime() - theirDate.getTime()) < 0) {
			//too young
			}
			else {
				$.cookie('registeredOver18', true, { expires: 2 });
				$(".modal-window").hide();
				$(".modal-overlay").hide();	
			}
		}
		return false;
	});
	
	//Page peel effect
	$("#pageflip").hover(function() { //On hover...
		$("#pageflip img , .msg_block").stop()
			.animate({ //Animate and expand the image and the msg_block (Width + height)
				width: '300px',
				height: '319px'
			}, 500);
		} , function() {
		$("#pageflip img").stop() //On hover out, go back to original size 50x52
			.animate({
				width: '100px',
				height: '102px'
			}, 220);
		$(".msg_block").stop() //On hover out, go back to original size 50x50
			.animate({
				width: '100px',
				height: '98px'
			}, 200); //Note this one retracts a bit faster (to prevent glitching in IE)
	});
	
	
	//Auto clear text fields
	$('.clearField').clearField();
	
	//open light box when you click an advert
	$(".lightbox1").click(function(){
		$(".lightbox-window img").attr("src", $(this).attr("href"));
		$(".lightbox-overlay").show();
		$(".lightbox-window").show();
		return false;
	});
	
	$(".lightbox2").click(function(){
		$(".lightbox-overlay").show();
		$(".lightbox-window2").show();
		return false;
	});

	//close light box when you click away from it
	$(".lightbox-overlay").click(function(){
		$(".lightbox-overlay").hide();
		$(".lightbox-window").hide();
		$(".lightbox-window2").hide();
		$(".lightbox-window img").attr("src", "");
	});
	
	$(".close").click(function(){
		$(".lightbox-overlay").hide();
		$(".lightbox-window").hide();
		$(".lightbox-window2").hide();
		$(".lightbox-window img").attr("src", "");
		return false;
	});
	
});


function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}


