/*
Copyright (c) 2010, Blue Ocean Labs. All rights reserved.
*/

function tryLoginRedirect(){

	//we need to let the page load completely first, so FB can determine/set the logged in user first
	//before we can reload the page and get a FB user id from the API 
	window.onload = function() {
		var fbLoginCount = Cookie.get('fyesta_fblogincount');
		if ( isNaN(fbLoginCount)) {
			fbLoginCount = 1; 
		}
		else {
			fbLoginCount++;
		}
		//this cookie will be removed when logging in successfully
		Cookie.set('fyesta_fblogincount', fbLoginCount);
		//in case Facebook's ifUserConnected can incorrectly say you are FB logged in, even if you are not
		//we try 3 times at the most
		if (fbLoginCount <= 3) {
			showCoveringLayer();
			window.location.reload();
		}
	};
}

function showCoveringLayer() {
	
	var loginDisabler = document.getElementById('loginDisabler');
	var loginDisablerText = document.getElementById('loginDisablerText');
	
	var viewPortMaxDivDimension = getViewPortMaxDivDimension();
	var viewPortMaxHeight = viewPortMaxDivDimension.height;
	var viewPortMaxWidth = viewPortMaxDivDimension.width;
	
    loginDisabler.style.display = "block";
    loginDisabler.style.width = viewPortMaxWidth+'px';
    loginDisabler.style.height = viewPortMaxHeight+'px';
    loginDisablerText.style.display = "block";
}

function getViewPortMaxDivDimension() {

	var viewportWidth, viewportHeight;
	
	if (typeof window.innerWidth != 'undefined') {
		viewportWidth = window.innerWidth,
		viewportHeight = window.innerHeight
	 }
	 
	// IE6 standards compliant mode
	 else if (typeof document.documentElement != 'undefined'
	     && typeof document.documentElement.clientWidth !=
	     'undefined' && document.documentElement.clientWidth != 0) {
		 
		 viewportWidth = document.documentElement.clientWidth,
		 viewportHeight = document.documentElement.clientHeight
	 }
	 
	 // older IE
	 else {
		 viewportWidth = document.getElementsByTagName('body')[0].clientWidth,
		 viewportHeight = document.getElementsByTagName('body')[0].clientHeight
	 }

    return {width:viewportWidth, height:viewportHeight};
}

