var i=0;

$(document).ready(function(){
    
	
	//Top Header Show/Hide function
	maxHeight = 60;
    minHeight = 0;
	minWidth= 0;
	maxWidth =563;
	
	bafheight=$('#friend').height();
	careersheight=$('#career').height();
	baf_press=false;
	career_press=false;
	
	if($('#promotion').length>0){
	$(window).bind("resize",function(){
		$('.pgecontainer').pgeConCen();					   
	});
	$(window).bind("load",function(){
			$('#promotion').PgeMask(function(){
			$('.pgecontainer img, .pgewrapper .pgemask').click(function(){
				$(this).PgeUnloadmask();					
			});				
		});
	});
	}

	
	$(window).bind("load",function(){

		//Cycle plugin
		$('#dispimagebox') .cycle({  
			fx:     'scrollLeft',
			easing: 'easeInOut',
			speed: 1500,
			delay:  -5000,
			timeout:  7000
		});	
		
		//Cycle Thumb function
		$('#goto1').click(function() { 
			$('#dispimagebox').cycle(0); 
			return false; 
		}); 
		 
		$('#goto2').click(function() {  
			$('#dispimagebox').cycle(1);  
			return false;  
		}); 
		$('#goto3').click(function() { 
			$('#dispimagebox').cycle(2); 
			return false; 
		}); 
		 
		$('#goto4').click(function() {  
			$('#dispimagebox').cycle(3);  
			return false;  
		});
	});
	
	
	$('#baf_form').submit(function(){
		$('#baf_result').text("Processing...");
								   
		if(CheckEmail($('#baf_email').val()))
		{
			inpemail=$('#baf_email').val();
			
			$.post("layout/scripts/php/baf_email.php",{f_email: inpemail},function(data){
				$('#baf_result').text(data);	  
			});
		}
		else
		{
			$('#baf_result').text("Please enter a valid email address.");
		}
		return false;
	});
	
	
	$('#career_form').submit(function(){
									  
		$('#baf_career').text("Processing...");
		
		ftitle=$('.tb_format').eq(0).val();
		fname=$('.tb_format').eq(1).val();
		fcontact=$('.tb_format').eq(2).val();
		femail=$('.tb_format').eq(3).val();
		
		i=0;
		
		if(fname!=""){i++;}
		if(fcontact!=""){i++;}
		if(femail!=""){i++;}
		if(CheckEmail(femail)){i++;}
		
		if(i==4)
		{
			$.post("layout/scripts/php/career_email.php",{f_title: ftitle, f_name: fname, f_contact: fcontact, f_email: femail},function(data){
				$('#baf_career').text(data);	  
			});
		}
		else
		{
			$('#baf_career').text("Please make sure all fields are filled in correctly.");
		}
			
		return false;
	});	
	
	$('#friend').height(25);
	$('#career').height(25);
	
	$('#baf_toggle').click(function(){
		if(baf_press)
		{
			$('#friend').animate({
				height: "25px"					 
			}, 400);				 
			baf_press=false;
		}
		else
		{
			$('#friend').animate({
				height: bafheight+"px"				 
			}, 400);			 
			baf_press=true;
		}
	});
	
	$('#cereers_toggle').click(function(){
		if(career_press)
		{
			$('#career').animate({
				height: "25px"					 
			}, 400);
			career_press=false;
		}
		else
		{
			$('#career').animate({
				height: careersheight+"px"					 
			}, 400);			 
			career_press=true;
		}
	});
	
    $("#toggle").click(
      function(){
	  	curHeight = $("#no1").height();
	  	if(curHeight==60)
		{
			$("#no1").animate({height: minHeight+"px"}, { queue:false, duration:400 });
		}
		else
		{
			$("#no1").animate({height: maxHeight+"px"}, { queue:false, duration:400 });
		}
      });
	
    $("#toggle2").click(function () {
      $("#info_hide").slideToggle("slow");
    });
	
});

	function addBookmark()
	{
		
		var title="Malcolm John | Fish & Grill";
		var url="http://www.all-sorted.co.uk/malcolmjohn/lacassoulet/";
		
		if(window.sidebar)
		{ 
			window.sidebar.addPanel(title, url,""); 
		}
		else if( document.all )
		{
			window.external.AddFavorite( url, title);
		}
		else if( window.opera && window.print )
		{
			return true;
		}
	}

function CheckEmail(inputemail) {
AtPos = inputemail.indexOf("@");
StopPos = inputemail.lastIndexOf(".");

	if (AtPos == -1 || StopPos == -1)
	{
		return false;
	}
	else
	{
		return true;	
	}

}