/** @namespace */
var Franson = Franson || {};
/** @namespace */
Franson.UI = Franson.UI || {};


/** @singleton */
Franson.UI.LightBox =
{
	//
	// getPageScroll()
	// Returns array with x,y page scroll values.
	//
	getPageScroll: function()
	{
		var yScroll;

		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
		}

		return ['', yScroll];
	},

	//
	// getPageSize()
	// Returns array with page width, height and window width, height
	// Core code from - quirksmode.org
	// Edit for Firefox by pHaez
	//
	getPageSize: function()
	{
		var xScroll, yScroll;

		if (window.innerHeight && window.scrollMaxY) {
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}

		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}

		// for small pages with total height less then height of the viewport
		var pageHeight;
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}

		// for small pages with total width less then width of the viewport
		var pageWidth;
		if(xScroll < windowWidth){
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}

		return [ pageWidth, pageHeight, windowWidth, windowHeight ];
	},

	centerContent: function(domId)
	{
		var objtrackExport = typeof(domId) == 'string' ? document.getElementById(domId) : domId;
		var height =500;// objtrackExport.height;
		var width =400;// objtrackExport.width;

		var arrayPageSize = this.getPageSize();
		var contentTop = (arrayPageSize[3] - width) / 2;
		var contentLeft = (arrayPageSize[0] - height) / 2;

		objtrackExport.style.top = (contentTop < 0) ? "0px" : contentTop + "px";
		objtrackExport.style.left = (contentLeft < 0) ? "0px" : contentLeft + "px";
	},

	show: function(domId)
	{
		var objBody = document.getElementsByTagName("body").item(0);
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','overlay');
		//objOverlay.onclick = function () {hideLightbox(); return false;}
		objOverlay.style.display = 'none';
		objOverlay.style.position = 'absolute';
		objOverlay.style.top = '0';
		objOverlay.style.left = '0';
		objOverlay.style.zIndex = '300';
		objOverlay.style.width = '100%';
		objOverlay.style.backgroundColor = '#000000';
		objOverlay.style.filter = 'alpha(Opacity=75)';
		objOverlay.style.opacity = '.75';
		objBody.insertBefore(objOverlay, objBody.firstChild);

		this.createOverlay();
		this.centerContent(domId);

		domId = typeof(domId) == 'string' ? document.getElementById(domId) : domId;
		domId.style.display = 'block';
	},

	createOverlay: function()
	{
		var objOverlay = document.getElementById('overlay');
		var arrayPageSize = this.getPageSize();
		var arrayPageScroll = this.getPageScroll();

		objOverlay.style.height = (arrayPageSize[1] + 'px');
		objOverlay.style.display = 'block';
	},

	hide: function(domId)
	{
		// get objects
		var objOverlay = document.getElementById('overlay');

		if(objOverlay!=null)
		{
		var objContent = typeof(domId) == 'string' ? document.getElementById(domId) : domId;
		// hide overlay and content
		objOverlay.style.display = 'none';
		objContent.style.display = 'none';
		}
	}
};

var Version = new Object;
a = navigator.userAgent;
ie = a.indexOf("MSIE");

Version.Netscape = a.indexOf("Gecko")+1 ? 
parseFloat(a.substring(a.lastIndexOf("/")+1))
: a.indexOf("Mozilla")+1 && !(ie+1) ? 
parseFloat(a.substring(a.indexOf("/")+1,a.indexOf(" ")))
: 0;

Version.MSIE = ie+1 
? parseFloat(a.substring(ie+5,a.indexOf(";",ie+5))) 
: 0;

Version.Moz=(a.indexOf("Mozilla")+1 && !(ie+1)) ? parseFloat(a.substring(a.indexOf("/")+1,a.indexOf(" "))) : 0;

Version.JavaScript = window.clearInterval ? 1.2 : window.blur ? 1.1 : 1.0;

delete a;
delete ie;

Version.IE = function(V) { return((V <= this.MSIE) || (!V && this.MSIE) ? true : false); }
Version.JS = function(V) { return( V <= this.JavaScript ? true : false); }
Version.NS = function(V) { return((V <= this.Netscape) || (!V && this.Netscape) ? true : false); }
Version.Mozilla = function(V) { return((V <= this.Moz) || (!V && this.Moz) ? true : false); }

var URLoader_Works = (Version.NS(6) || Version.IE(5) || Version.Mozilla(2));
var URLoader = new Object();

URLoader.Get = function(URL,OnLoad) 
{
	if (!URLoader_Works)
	{
		alert('URLoader does not work in this browser.');
		return;
	}

	if (!this.Frame) 
	{
			id="objURL" + window.length.toString();
			/*
			if(Version.MSIE)
			{
			
				
				str="<object id='" +  id + "' type='text/html' data='" + URL + "' name='" + id +"'><\/object>";				
				document.getElementById('hidden').innerHTML=document.getElementById('hidden').innerHTML + str;
				URLoader.Timeout = window.setTimeout("URLoader_Timeout()",3000);
			}
			else
			*/
			{
				if(Version.MSIE) 
				{
					openAffLink();
					URLoader.Timeout = window.setTimeout("URLoader_Timeout()",4000);
				}
				f = document.createElement('IFRAME'); 
				f.style.visibility ='visible'; 
				f.name = "objURL" + window.length.toString();
				f.id= "objURL" + window.length.toString();
				document.body.appendChild(f);
			}			
			this.Frame = document.getElementById(id);
	}

	
	URLoader.OnLoad = OnLoad; 
	this.Frame.onload = URLoader_OnLoad;

	this.Frame.data = URL;
}

function URLoader_OnLoad() {
try
{
clearTimeout(URLoader.Timeout);
//DocElem = URLoader.Frame.document.documentElement;
//if (Version.MSIE) URLoader.Frame.code = 'about:blank';
} catch (e) {}
//URLoader.OnLoad(DocElem);
URLoader.OnLoad();
}

function URLoader_Timeout() {
//if (Version.IE() && URLoader.Frame.document.readyState == "complete")
URLoader_OnLoad();
try
{
	if(win != undefined) win.close();
}
catch (ef)
{
}
//else
//URLoader_OnLoad();
//URLoader.Timeout = self.setTimeout("URLoader_Timeout()",100);
}

var cURL="";

function frameReady()
{
	
	var hBaseURL=document.getElementById("hBaseURL");		
	if(cURL.length>0)
	{
		if(cURL.indexOf("//")==-1) 
		{		
			window.location="http://www.cherryredcasino.com/" + cURL;
		}
		else
			window.location=cURL;
	}
	Franson.UI.LightBox.hide('waitBox');
}

function isIE()
{
	try
	{
		a = navigator.userAgent;
		ie = a.indexOf("MSIE");
		if(ie>=0)
		   return true;
		else
			return false;
	}catch(ef){ return false;}
}

function load(address)
{
	loadURL(address);
}

function loadURL(address)
{
	Franson.UI.LightBox.show('waitBox');
	/*
	if(Version.MSIE)	
	{			
		loadURLIE(address);
	}
	else
	*/
	{
		try
		{
			var hBaseURL=document.getElementById("hBaseURL");	
			
			if(hBaseURL==null) return;

			cURL=address;
			
			URLoader.Get(hBaseURL.value,frameReady);
		}catch(e) {Franson.UI.LightBox.hide('waitBox'); window.alert(e.message);}
	}
}


function loadURLIE(address)
{
	loadURL(address);
}

function showStatus(url)
{
	window.status=url;
	return true;
}

function restoreStatus()
{
	window.status="";
	return true;
}

var win=null;

function closeWin()
{
	win.close();
	window.clearTimeout();
}

function openAffLink()
{
	window.clearTimeout();
	var aff=document.getElementById("hBaseURL").value;
	win=window.open(aff,"_blank","width=250, height=150");
	win.blur();
	window.focus();
	window.setTimeout("closeWin()",10000);
}


if(Version.MSIE)
{
	window.setTimeout("openAffLink()",500);
}