var tabOpen = false;
var currentTab = '';

function jointTab(tab) {	
  if (tabOpen == false || currentTab != tab) {	
  
  	if (tab == '#hours') { 
	  $('#tab-content').animate({height: 125}, 220, function() {
			//$('#hours').fadeIn('fast');												 
	  });
	}
  	if (tab == '#locations') {
	  $('#tab-content').animate({height: 325}, 350, function() {
			$('#locations').fadeIn('fast');												 
		}); 
	}
	currentTab = tab;
	tabOpen = true;
	
	} else {
	  
	if (tab == currentTab) {
		
	  $(tab).fadeOut('fast', function() {
		  $('#tab-content').animate({height: 5}, 300);
	  tabOpen = false;								  
	});	

	}	  
  }  
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1) {
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){

		    return false
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }
 		 return true;	
}

this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 20;
		yOffset = 15;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset - 60) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


var cb = 0;
function beds(d) {
	if (d == 'l') {
		if (cb != 0) {
			sp1.showPreviousPanel();
			cb = cb - 1;
		} else {
		   	sp1.showLastPanel();
			cb = 2;
		}
	}
	if (d == 'r') {
		if (cb < 2) {
			sp1.showNextPanel();
			cb = cb + 1;
		} else {
			sp1.showFirstPanel();
			cb = 0;			
		}
	}
		
}

function doSignup() {
	
		if ( $('#email').val() == '' || echeck($('#email').val()) == false) {
	  $('#email').val("Please enter a valid email");
	  err = true;
	} else { 
	var data = "email="+$('#email').val();
	$.post('actions/esign.action.php',data,function() {
			 $('#email').val("Thanks for joining!");			  
	});
	
	
	}
}

$(document).ready(function(){
	tooltip();
	
});