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

InitializeTemplate = function()	{
	mainMenuRollover();
	//setupLogInPanel();
	setupMainMenuTabs();
	
	setupTooltip();
	setupTooltipFr();
	
	DisableLinks();
	
}

staying_in_site = false;

$("a,input").click(function(event){
 
    staying_in_site = true;
  					 
}); 

//this runs right before the page is unloaded and checks to see if they are remaining on the site, closing the window or leaving the site
/*window.onunload = checkUser;

function checkUser() {
  if(staying_in_site) {
    return;
  }
  //clear any timeslots that might be reserved and not confirmed
  alert('I see you are leaving the site');
}*/

DisableLinks = function(){
	$(".disabled").click(function(e){
	  e.preventDefault();
	 });
}

AjaxLogin = function(){
	$.ajax({
		type: "POST",
		url: "scripts/process-login.php",
		data: "login-email=facebook@whatever.com&login-password=whatever",
		success: function(data){
			//if we got a result, load the xml content
			//console.log('logged in with facebook');
		}
	});
}

function update_user_box() {

  var user_box = document.getElementById("user");

  // add in some XFBML. note that we set useyou=false so it doesn't display "you"
  user_box.innerHTML =
      "<span>"
    + "<img alt='You are connected to Facebook Connect' src='http://static.ak.fbcdn.net/images/icons/favicon.gif'> <fb:name uid=loggedinuser useyou=false></fb:name>"
    + "</span>";

  // because this is XFBML, we need to tell Facebook to re-process the document 
  FB.XFBML.Host.parseDomTree();
}

/**** PAGE SETUP FUNCTIONS *****/
mainMenuRollover = function()	{
	$("#nav_cage").mouseover(function() {$(".dropdown-cage").show();});
	$("#nav_cage").mouseout(function()	{$(".dropdown-cage").hide();});
	
	$("#nav_adults").mouseover(function()	{$(".dropdown-adults").show();});
	$("#nav_adults").mouseout(function()	{$(".dropdown-adults").hide();});
	
	$("#nav_kids").mouseover(function()	{$(".dropdown-kids").show();});
	$("#nav_kids").mouseout(function()	{$(".dropdown-kids").hide();});
	
	$("#nav_cage").mouseover(function() {$(".dropdown-cage-fr").show();});
	$("#nav_cage").mouseout(function()	{$(".dropdown-cage-fr").hide();});
	
	$("#nav_adults").mouseover(function()	{$(".dropdown-adults-fr").show();});
	$("#nav_adults").mouseout(function()	{$(".dropdown-adults-fr").hide();});
	
	$("#nav_kids").mouseover(function()	{$(".dropdown-kids-fr").show();});
	$("#nav_kids").mouseout(function()	{$(".dropdown-kids-fr").hide();});
}

setupLogInPanel = function()	{
	$("#nav-loginBtn").click(function(e)	{
		e.preventDefault();
		if ($("#loging-in").is(":hidden"))	{
			$("#loging-in").slideDown();	
		} else	{
			$("#loging-in").slideUp();
		}						
	});
	
	$("#imgCancelLogin").click(function()	{
		$("#loging-in").slideUp();							  
	});	
}

setupMainMenuTabs = function()	{
	$("#thecagePage").click(function()	{staying_in_site = true;window.location = "index.php?lang=EN";});
	//$("#adultsPage").click(function()	{staying_in_site = true;window.location = "adults.php?lang=EN";});
	$("#kidsPage").click(function()	{staying_in_site = true;window.location = "kids.php?lang=EN";});
	$("#thecagePage-fr").click(function()	{staying_in_site = true;window.location = "index.php?lang=FR";});
	//$("#adultsPage-fr").click(function()	{staying_in_site = true;window.location = "adults.php?lang=FR";});
	$("#kidsPage-fr").click(function()	{staying_in_site = true;window.location = "kids.php?lang=FR";});
}

setupTooltip = function()	{
	$("#bookNow, .insidebannerbtn, .insidebannerbtn2, .bookcagebtn, #facilitybooking-moreinfo, .btnbookcage").click(function(e){
		e.preventDefault();							 
	});
	$("#bookNow, .insidebannerbtn, .insidebannerbtn-en2, .bookcagebtn, #facilitybooking-moreinfo, .btnbookcage").qtip({
		content: 
		'Call or email us to book your Cage or Party<br /><br /><strong>(514) 351-1444</strong><br /><a href=\'mailto:info@sportiracage.com\'>info@sportiracage.com</a><br /><br /><small>Online booking system will be available shortly</small>',
		show: 'click',
		hide: {when: {event: 'unfocus'}},
		position: {
			corner: {target: 'bottomMiddle', tooltip: 'bottomMiddle'},
			adjust: {y: -45}},
		style: {name: 'blue', textAlign: 'center', width: 200, color: '#202020', tip: 'bottomMiddle'}
	});
}

setupTooltipFr = function()	{
	$("#bookNow-fr, .insidebannerbtn, .insidebannerbtn2, .bookcagebtn, #facilitybooking-moreinfo-fr, .btnbookcage-fr, .packageBookNow").click(function(e){
		e.preventDefault();							 
	});
	$("#bookNow-fr, .insidebannerbtn, .insidebannerbtn2, .bookcagebtn, #facilitybooking-moreinfo-fr, .btnbookcage-fr, .packageBookNow").qtip({
		content: 
		'R&eacute;servez votre cage par courriel ou par t&eacute;l&eacute;phone<br /><br /><strong>(514) 351-1444</strong><br /><a href=\'mailto:info@sportiracage.com\'>info@sportiracage.com</a><br /><br /><small>Le syst&egrave;me de r&eacute;sevation en ligne sera disponible bient&ocirc;t</small>',
		show: 'click',
		hide: {when: {event: 'unfocus'}},
		position: {
			corner: {target: 'bottomMiddle', tooltip: 'bottomMiddle'},
			adjust: {y: -45}},
		style: {name: 'blue', textAlign: 'center', width: 200, color: '#202020', tip: 'bottomMiddle'}
	});
}

