var baseURL = "";
indx = location.href.indexOf("show");    
baseURL = location.href.substr(0,indx);

var url=location.href;

if(url&&url.length>0&&url.indexOf('/show')!=-1)
	baseURL=url.substr(0,url.indexOf('/show')+1);
else if(url&&url.length>0&&url.indexOf('\\show')!=-1)
	baseURL=url.substr(0,url.indexOf('\\show')+1);
else if(url&&url.length>0&&url.indexOf('\\index.php')!=-1)
	baseURL=url.substr(0,url.indexOf('\\index.php')+1);
else if(url&&url.length>0&&url.indexOf('/index.php')!=-1)
	baseURL=url.substr(0,url.indexOf('/index.php')+1);
else if(url&&url.length>0&&url.lastIndexOf('/')!=-1)
	baseURL=url.substr(0,url.lastIndexOf('/')+1);
else if(url&&url.length>0&&url.lastIndexOf('\\')!=-1)
	baseURL=url.substr(0,url.lastIndexOf('\\')+1);

var isReady = false;
var homePageReadyCalled = false;

function OnHomePageSWFReady(paramObject)
{
	//alert("OnHomePageSWFReady");
	homePageReadyCalled=true;
	NotifyPosition();
	
	//alert("OnHomePageSWFReady");
	login = new loginAPI();
	/*
	$('#signin').click(function() {
		getSWF("HomePage").focus();
		getSWF("HomePage").ShowLogin();
	});
	
	$('#register').click(function() {
		getSWF("HomePage").focus();
		getSWF("HomePage").ShowRegister();
	});
	*/
}


function GetBaseURL()
{
	return baseURL;
}

function LaunchTable(getParams)
{
	var windowFeatures='width=800,height=400,toolbar=0,location=0,scrollBars=0'
	var rndToAddToURLToStopCaching=new Date().getTime();
	var url=baseURL+"moc/chatTable/WatchitooShowLoader.php?"+getParams+"&rand="+rndToAddToURLToStopCaching;
	window.open(url, '', windowFeatures ) ;  
}


function watchitoo_OnLogin(username, nickname, certificate, accountType) 
{
	//alert("watchitoo_OnLogin. accountType="+accountType);
	if(accountType != 'Member') 
	{
		window.location="../index.php";
		return;
	}
	getSWF("HomePage").SetUsername(username,certificate,nickname,accountType);
	/*
	//alert("watchitoo_OnLogin");
	if (accountType != 'Temporary') {
		//var u = username; 
		//var n = nickname;
		//var c = certificate;
		if (document.getElementById("welcomeMessage")) {
			SetNickname(nickname);
		}
	}
	getSWF("HomePage").SetUsername(username,certificate,nickname,accountType);
	*/
}

function watchitoo_OnLogout() {
	//alert("watchitoo_OnLogout");
	//self.parent.clearWelcome();
	getSWF("HomePage").Signout();
	window.location="../index.php";
}

function watchitoo_OnLoginFailed(errorCode, description) {
	//alert("watchitoo_OnLoginFailed");
	//getSWF("HomePage").onLoginFailed(errorCode,description);
	//$('#loginLoader').hide();
	window.location="../index.php";
}

function watchitoo_OnStateChange(state) {
	//alert("state="+state);
	if(state=="loggedOut")
	{
		// added these lines to ensure logout gets processed
		//self.parent.clearWelcome();
		getSWF("HomePage").Signout();
		window.location="../index.php";
	
		// added this line to create a guest account if not logged in
		//setTimeout("CreateGuestAccount()",100);
	}
}

function watchitoo_OnRegister(params) {
	//getSWF("HomePage").onRegisterResult('success','', params);
}

function watchitoo_OnRegisterError(errorCode, description, params) {
	//getSWF("HomePage").onRegisterResult('error', description, params);
	window.location="../index.php";
}

function watchitoo_OnError(text) {
	//alert(text);
}

$(document).ready(function() {

/*
	//this is jQuery's init function - being run when the DOM is ready. (before the images are loaded)
	$('#signout').click(function(){
		// added these lines to ensure logout gets processed
		//self.parent.clearWelcome();
		Logout();
		//login.logout();
	});
*/
});

