//image variables
var c;
var l;
var images;
		
$(document).ready(function(){
						   
		//image cycling
		images = $('#pictures 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();
			});
		}
		
		//thumbs generation
		var thumbs=$('#thumbs div');		
		$('#pictures img').each(function(i){
			ts=$(this).attr('src');
			thumbs.eq(i).append('<img src="' + ts + '" alt="" />');
		});
		
		//thumbs hover function
		thumbs.mouseover(function(){
			ti=thumbs.index(this);
			images.fadeOut().eq(ti).fadeIn();
			c=ti;
		});	
		
		$('#baf').submit(function(){
		$('#baf_return').text("Processing...");
		if(CheckEmail($('#f1').val()))
		{
			postdata=$('#f1').val();
			$.post("media/php/baf.php",{emailadd: postdata},function(data){
				$('#baf_return').text(data);
			});
		}
		else
		{
			$('#baf_return').text("Please enter a valid email address");	
		}
		return false;
	});
		
		
});

function CheckEmail(inputemail) {
	AtPos = inputemail.indexOf("@");
	StopPos = inputemail.lastIndexOf(".");
	if (AtPos == -1 || StopPos == -1)
	{
		return false;
	}
	else
	{
		return true;	
	}

}
