var c;
var l;
var images;

$(document).ready(function(){
    
	//Top Header Show/Hide function
	maxHeight = 60;
    minHeight = 0;
	minWidth= 0;
	maxWidth =563;
	
	//generate Thumbs 
	
	$('body').css('backgroundColor','#CFD1C3');
	
	$('#showbookingform').click(function(){
		conWidth=$('#content').width()-30;
		conHeight=$('#content').height();
		$('#bookingcontainer').css({width:conWidth,height:conHeight}).customFadeIn(300);
		return false;
	});
	
	$('#closebooking').click(function(){
		$('#bookingcontainer').fadeOut(300);
		return false;
	});
	
	$('#thumbs').empty();
	
	$('#images img').each(function(i){
		thissrc = $(this).attr('src');
		$('#thumbs').append("<span><img src='"+ thissrc +"' /></span>");
	});
	
	$('#thumbs span').click(function(){
		thisind = $('#thumbs span').index(this);
		$('#images img').fadeOut().eq(thisind).fadeIn();
	});

		
		//images (inside doc.ready)	   
		images = $('#images img');
		if(images.length>0){
			c=0; l=images.length-1;
			images.hide().eq(c).show();
			$().everyTime(5000, function(){
				if(c==l) c=0; else c++; 
				images.fadeOut().eq(c).fadeIn();
			});
		}

	
    $("#toggle").click(function () {
		var cur_l = $('#content').css('left');
		//alert(cur_l);
		if(cur_l == "560px") {
			$("#content").animate({left: "0px"}, {queue:false});
		} else {
			if(cur_l == "0px") {
				$("#content").animate({left: "560px"}, {queue:false});	
			}
		}
	  
    });
	
	$('#bafform').submit(function(){
		$('#bafresults').show().text("Processing...");
		
		inpemailaddress=$('.bafemail').val();
		
		if(CheckEmail(inpemailaddress))
		{
			$.post("media/php/bafform.php",{emailadd:inpemailaddress,innname:'Inn on the Wye'},function(data){
				$('#bafresults').show().text(data);			  
			});
			$('.bafemail').val("");
			$('#bafresults').animate({
				top:"0px"						 
			},3000,function(){
				$(this).hide();	
			});
		}
		else
		{
			$('#bafresults').show().text("Not a valid email address.");
			$('.bafemail').val("");
			$('#bafresults').animate({
				top:"0px"						 
			},3000,function(){
				$(this).hide();	
			});
		}
		return false;							  
	});
	
	var togheight = $('#content').height();
	$('#toggle').height(togheight);

});


(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
})(jQuery);

function CheckEmail(inputemail) {
	AtPos = inputemail.indexOf("@");
	StopPos = inputemail.lastIndexOf(".");

	if (AtPos == -1 || StopPos == -1)
	{
		return false;
	}
	else
	{
		return true;	
	}

}
