var posleft_arr = new Array();
var iposleft_arr = new Array();
var dur = 500;

$(document).ready(function(){
	$('#hub_baf').submit(function(){
		emlstring=$('#hub_baf .txtbox').val();
		if(CheckEmail(emlstring))
		{
			if($('input#housename').length>0){
				hn=$('input#housename').val();
			} else {
				hn=0;
			}
			$.post("media/php/baf.php",{emailadd:emlstring,housename:hn},function(data){
				//alert(data);
				$('#frmreturn').html(data);			  
			});
		}
		else
		{
			$('#frmreturn').text("Please enter a valid email address");	
		}
		return false;
	});
});

$(function(){
	//greyhound timer

	//setup
	$('#images div div').each(function(){
			$(this).children('img').hide().eq(0).show();
	});
	$('#images div span').css({opacity: 0});
	$('.arrow').css({opacity: 0});
		
	$('#images div div img').each(function(i){
		iposleft = $(this).css('left');
		iposleft = parseInt(iposleft);
		
		iposleft_arr[i] = iposleft;
	});
	
	
	$('ul#hub li a').hover(function(){
		//expand
		
		thisindex = $('ul#hub li a').index(this);
		
		thisid = $('#images>div').eq(thisindex).attr('id');
		
		var c=0;
		
		$().everyTime(2000, function(){
			if(c==1) c=0; else c++; 
			$('#'+ thisid +' div img').fadeOut().eq(c).fadeIn();
		});
		
		//button
		$(this)
		.children('.arrow')
		.animate({
			opacity: 1,
			left: 180
		},{queue: false, duration: dur});
		
		//image
		$('#images>div')
		.animate({
			width: 0		 
		},{queue:false, duration: dur})
		.eq(thisindex)
		.animate({
			width: 960
		},{queue:false, duration: dur})
		.children("div")
		.animate({
			left: 0
		},{queue:false, duration: dur})
		.children('img')
		.animate({
			left: 0
		},{queue:false, duration: dur})
		.end()
		.end()
		.children('span')
		.animate({
			opacity: 1.0
		});
		
		
	},function(){
		$().stopTime();
		
		thisindex = $('ul#hub li a').index(this);
		
		//button
		$(this)
		.children('.arrow')
		.animate({
			opacity: 0,
			left: 150
		},{queue: false, duration: dur});
		
		//image
		$("#images>div")
		.animate({
			width: 192
		},{queue:false, duration: dur})
		/*.each(function(i){
		$(this)
		.children('div')
		.animate({
			left: 0			
		},{queue:false, duration: dur});
		})*/
		.eq(thisindex).children('span')
		.animate({
			opacity: 0
		},{queue:false, duration: dur})
		.end()
		.children('div')
		.children('img')
		.animate({
			left: iposleft_arr[thisindex]
		},{queue:false, duration: dur})

	
	});	
});

function CheckEmail(inputemail) {
	AtPos = inputemail.indexOf("@");
	StopPos = inputemail.lastIndexOf(".");

	if (AtPos == -1 || StopPos == -1)
	{
		return false;
	}
	else
	{
		return true;	
	}

}