$(document).ready(function() {

//$('p').widowFix({
//    linkFix: true 
//});


function checkLength( o, n, min ) {
	if ( o.val().length < min ) {
		alert( "Length of " + n + " must be greater than " +
			min + "." );
		return false;
	} else {
		return true;
	}
}

function checkRequired( o, n ) {
	str = jQuery.trim(o.val());
	if ( str.length < 1 ) {
		o.css("background","none repeat scroll 0 0 #F9EAE6");
		o.css("border","1px dashed #EE4377");
		return false;
	} else {
		o.css("background-color","#FFF");
		o.css("border","1px solid #CCCCCC");
		return true;
	}
}	
function checkEmail( o ) {
	str = jQuery.trim(o.val());
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
 	var emailaddressVal = o.val();
    if(!emailReg.test(emailaddressVal)) {
		o.css("background","none repeat scroll 0 0 #F9EAE6");
		o.css("border","1px dashed #EE4377");
		return false;
	} else {
		o.css("background-color","#FFF");
		o.css("border","1px solid #CCCCCC");
		return true;
	}
}
			
//animated scroll
$.localScroll({
			  offset: {top:-40},
			  easing: 'easeInOutExpo'
			  });

//send button thankyou
$('#submit_contact').click(function() {
	var dataString = 'subject=Contact&to=reservations@aviatorfarnborough.co.uk&cc=hd@aviatorfarnborough.co.uk,sb@aviatorfarnborough.co.uk';  
	var message = $( "#input_message" ),
	name = $( "#input_name" ),
	email = $( "#input_email" ),
	telephone = $( "#input_telephone" ),
	terms = ($( "#input_terms:checked").val()!==undefined)?'yes':'no';
	
	var bValid = true;
	//bValid = bValid && checkRequired( message, "Message" );
	//bValid = bValid && checkRequired( name, "Name" );
	//bValid = bValid && checkRequired( email, "Email address");
	//bValid = bValid && checkRequired( telephone, "Telephone number");
	bValid = checkRequired( message, "Message" ) && bValid;
	bValid = checkRequired( name, "Name" ) && bValid;
	bValid = checkEmail( email, "Email address") && bValid;
	bValid = checkRequired( telephone, "Telephone number") && bValid;
	
	if ( bValid ) {
		$('.info').fadeTo(300, 0.2);
		
		dataString = dataString + '&form_message='+ escape(message.val()) + '&form_name=' + escape(name.val()) + '&form_email=' + escape(email.val()) + '&form_telephone=' + escape(telephone.val())+ '&form_subscribes_to_updates=' + terms;  
		$.post('form-submission.php',dataString);
	

	  	$('#submit_contact').attr('src', '/images/thankyou_send.gif');
	  	setTimeout("window.location = 'http://www.aviatorfarnborough.co.uk/';", 2700);
  }
});

$('#submit_sign-up').click(function() {
	var dataString = 'subject=Sign up&to=marketing@aviatorfarnborough.co.uk';  
	var title = $( "#select_title" ),
	first_name = $( "#input_first-name" ),
	last_name = $( "#input_last-name" ),
	email = $( "#input_email" ),
	postcode = $( "#input_postcode" ),
	country = $( "#select_country" ),
	terms = $( "#input_terms:checked" );
	
	var bValid = true;
//	bValid = bValid && checkRequired( title, "Title");
	//bValid = bValid && checkRequired( first_name, "First name");
	//bValid = bValid && checkRequired( last_name, "Last name");
	//bValid = bValid && checkRequired( email, "Email address");
	//bValid = bValid && checkRequired( country, "Country");
	bValid = checkRequired( title, "Title") && bValid ;
	bValid = checkRequired( first_name, "First name") && bValid;
	bValid = checkRequired( last_name, "Last name") && bValid;
	bValid = checkEmail( email, "Email address") && bValid;
	bValid = checkRequired( country, "Country") && bValid;	
	
	if ( bValid ) {
		$('.info').fadeTo(300, 0.2);
		
		dataString = dataString + '&form_title='+ escape(title.val()) + '&form_first_name=' + escape(first_name.val()) + '&form_last_name=' + escape(last_name.val()) + '&form_email=' + escape(email.val())  + '&form_postcode=' + escape(postcode.val()) + '&form_country=' + escape(country.val()) + '&form_receive_updates=' + escape(terms.val());  
		$.post('form-submission.php',dataString);
		
	  $('#submit_sign-up').attr('src', '/images/thankyou_send.gif');
	  setTimeout("window.location = 'http://www.aviatorfarnborough.co.uk/';", 2700);
	}
});


//image hover
$('.img_reset').fadeTo(0.001, 0);
$('.img_hover').hover(function() {
				$('.img_reset', this).stop().fadeTo(300, 1);
				}, function() {
				$('.img_reset', this).stop().fadeTo(600, 0);
				});
//mask calc
		var docHeight;
		docHeight = $(document).height();		
		$('#mask').height(docHeight);
		
//popup   
//$('.enquire_popup').focus(function(){
               // $('#popup').show();
               // });           
$('.enquire_popup').click(function(){
                $('.submit').attr('src', '/images/submit.png');
				$('.info').fadeTo(0.01, 1);
				$('#mask').fadeTo(400, 0.8, function(){$.scrollTo('#popup', 600);});
                $('#popup').show();
                });

				
$('#close_popup, #mask').click(function(){
				$('#mask').hide();
				$('#popup').fadeOut();
				});
		
//menu accordion
	$(function() {
		$( "#menus" ).accordion({ autoHeight: false, collapsible: true, active: false});
	});			


//auto slideshow
$('#autoSlideshow').cycle({ 
    timeout: 4000, 
	pause: 1,
    next:   '#nextSlide', 
    prev:   '#prevSlide', 
	nowrap:	0,
	fx:		'scrollHorz',
	cleartypeNoBg: true,
	after:     onAfterAuto
    
});



$("#autoSlideshow").touchwipe({
 		wipeLeft: function() {
 	 		$("#autoSlideshow").cycle("next");
 		},
 		wipeRight: function() {
 	 		$("#autoSlideshow").cycle("prev");
 		}
	});

function onAfterAuto(curr,next,opts) {

	var caption = (opts.currSlide + 1) + '&nbsp; &nbsp; &nbsp;' + opts.slideCount;
	$('#caption').html(caption);
	
	//var index = opts.currSlide;
    //$('#prevSlide')[index == 0 ? 'hide' : 'show']();
    //$('#nextSlide')[index == opts.slideCount - 1 ? 'hide' : 'show']();

}

//slideshow
$('#slideshow').cycle({ 
    timeout: 0, 
    next:   '#nextSlide', 
    prev:   '#prevSlide', 
	nowrap:	1,
	fx:		'scrollHorz',
	cleartypeNoBg: true,
	after:     onAfter
    
});

$("#slideshow").touchwipe({
 		wipeLeft: function() {
 	 		$("#slideshow").cycle("next");
 		},
 		wipeRight: function() {
 	 		$("#slideshow").cycle("prev");
 		}
	});

function onAfter(curr,next,opts) {

	var caption = (opts.currSlide + 1) + '&nbsp; &nbsp; &nbsp;' + opts.slideCount;
	$('#caption').html(caption);
	
	var index = opts.currSlide;
    $('#prevSlide')[index == 0 ? 'hide' : 'show']();
    $('#nextSlide')[index == opts.slideCount - 1 ? 'hide' : 'show']();

}

$('.herolink_1').hover(function() {
	$('.heroimage_1').stop().fadeTo(200, 1);
}, function() {
	$('.heroimage_1').stop().fadeOut(200);
});

$('.herolink_2').hover(function() {
	$('.heroimage_2').stop().fadeTo(200, 1);
}, function() {
	$('.heroimage_2').stop().fadeOut(200);
});

$('.herolink_3').hover(function() {
	$('.heroimage_3').stop().fadeTo(200, 1);
}, function() {
	$('.heroimage_3').stop().fadeOut(200);
});


$('#prevSlide').click(function() {
	$('.heroimage_1').stop().hide();
	$('.heroimage_2').stop().hide();
	$('.heroimage_3').stop().hide();
});

$('#nextSlide').click(function() {
	$('.heroimage_1').stop().hide();
	$('.heroimage_2').stop().hide();
	$('.heroimage_3').stop().hide();
});

});



//popup window
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page = window.open(URL, 'popup', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=390,height=620,left = 200,top = 200');");
}
	
	
/*//floorplans

$(document).ready(function() {
	$('.poi').hover(function() {
		$('.tooltip', this).stop().fadeTo(200, 1);	
		}, function() {			
		$('.tooltip', this).stop().fadeOut(200);		
		});				
		
		$('.close-tooltip').click(function(){				
		$('.tooltip').stop().hide();			
		});			
});	*/


//Sliding Info List + Medium Gallery
	
	//Room detail quick links
	
	function roomDetails(roomName) {
		$.scrollTo('#rooms_container', 600);
		
		$('.sliding_info_list p').slideUp(300);
		$('.medium_gallery img').fadeTo(100, 0.01);
		$('.sliding_info_list h5').css({color:'#999'});
		
		$('#info_'+roomName+' p').delay(500).slideDown(300);
		$('#img_'+roomName).delay(500).fadeTo(400, 1);
		$('#info_'+roomName+' h5').delay(500).css({color:'#000'});	
	}
	
$(document).ready(function() {
	
	//Page load defaults
	$('.medium_gallery img').css({display:'none'});
	
	$('#info_aviator-room p').slideDown(300);
	$('#img_aviator-room').fadeTo(400, 1);
	$('#info_aviator-room h5').css({color:'#000'});
	
	
	$('.sliding_info_list li').click(function() {
		$('.sliding_info_list p').slideUp(300);
		$('p', this).slideDown(300);
		$('.medium_gallery img').fadeTo(100, 0.01);
		$('.sliding_info_list h5').css({color:'#999'});	
		$('h5', this).css({color:'#000'});	
	});
	
	$('#info_aviator-room').click(function() {
		$('#img_aviator-room').fadeTo(400, 1);	
	});
	
	$('#info_aviator-studio').click(function() {
		$('#img_aviator-studio').fadeTo(400, 1);
	});
	
	$('#info_sky-suite').click(function() {
		$('#img_sky-suite').fadeTo(400, 1);
	});
	
	//Cocktail Nav Fix
	$(window).scroll(function() {
	
	/*var sigPosition = $('#signature').offset().top;
	
	if (sigPosition < 200) {
		//$('#signature').addClass('.currenth2');
		alert('current title!');
	} else { 
		//('#signature').removeClass('.currenth2');
	};*/
	
	var scrollPosition = $(window).scrollTop();
	
	if (scrollPosition > 150) {
		$('#signature').addClass('currenth2');
		//alert('title!');
	} else {
		$('#signature').removeClass('currenth2');
	};
	
	if (scrollPosition > 1000) {
		$('#champagne').addClass('currenth2');
		//alert('title!');
	} else {
		$('#champagne').removeClass('currenth2');
	};
	
	if (scrollPosition > 1500) {
		$('#martinis').addClass('currenth2');
		//alert('title!');
	} else {
		$('#martinis').removeClass('currenth2');
	};
	
	if (scrollPosition > 2300) {
		$('#classic').addClass('currenth2');
		//alert('title!');
	} else {
		$('#classic').removeClass('currenth2');
	};
	
	if (scrollPosition > 395) {
		$('#cocktail_nav').css({position:'fixed', top:'0', left:'50%', marginLeft:'-480px', marginTop:'0'});
		$('.cocktailsintro').css({marginBottom:'60px'});
	} else {
		$('#cocktail_nav').css({position:'relative', marginTop:'20px'});
		$('.cocktailsintro').css({marginBottom:'0px'})
	};
	
	});
	
	
	//Cocktail Detail Page
	
	$('.ingredients').click(function() {
		$('.step-by-step').css({color:'#666'});
		$('#step-by-step').hide();
		$('#ingredients').slideDown();
		$(this).css({color:'#fff'});
	});
	
	$('.step-by-step').click(function() {
		$('.ingredients').css({color:'#666'});
		$('#ingredients').hide();
		$('#step-by-step').slideDown();
		$(this).css({color:'#fff'});
	});
	
	$('.more_info_close').click(function() {
		$('.ingredients , .step-by-step').css({color:'#666'});
		$('#ingredients , #step-by-step').slideUp();
	});
	
	
	
	
			
});

