var failedConnectString					= "";
var pop_win							= null;

var xScroll, yScroll, timerPoll, timerRedirect, timerClock;
var theTimeout						= 1200000;


function enlarge(img) {
	var imgWin						= window.open("talkingmemories-images.html");
	imgWin.document.write("<img src=\"" + img + "\" alt=\"talkingmemories.com\"/>");
}

function target(url) {
	window.open(url);
}

function target_pop(url, width, height) {
	pop_win							= window.open(url, "pop", "width="+width+",height="+height+",resize=no,scrollbars=no");

	return false;
}

function close_pop() {
	opener.doClose();
}

function doClose() {
	setTimeout("actual_close()", 200);
}

function actual_close() {
	pop_win.close();
	pop_win							= null;

	window.location.reload(true);
}

function initializeToolbar(baseurl) {
	image_path							= baseurl+"/general/ToolBar/";
	PersonalLifeStoryOn					= new Image();
	PersonalLifeStoryOn.src				= image_path+"personal-life-storyOn.gif";

	PersonalLifeStoryOff					= new Image();
	PersonalLifeStoryOff.src				= image_path+"personal-life-story.gif";
	PersonalLifeStoryOff.name				= "personal-life-story";

	ChildrensDiaryOn					= new Image();
	ChildrensDiaryOn.src					= image_path+"childrens-diaryOn.gif";

	ChildrensDiaryOff					= new Image();
	ChildrensDiaryOff.src				= image_path+"childrens-diary.gif";
	ChildrensDiaryOff.name				= "childrens-diary";

	SpecialEventsOn					= new Image();
	SpecialEventsOn.src					= image_path+"special-eventsOn.gif";

	SpecialEventsOff					= new Image();
	SpecialEventsOff.src					= image_path+"special-events.gif";
	SpecialEventsOff.name				= "special-events";

	FaqOn							= new Image();
	FaqOn.src						= image_path+"faqOn.gif";

	FaqOff							= new Image();
	FaqOff.src						= image_path+"faq.gif";
	FaqOff.name						= "faq";

	TutorialOn						= new Image();
	TutorialOn.src					= image_path+"tutorialOn.gif";
	
	TutorialOff						= new Image();
	TutorialOff.src					= image_path+"tutorial.gif";
	TutorialOff.name					= "tutorial";
}

function pagehighlight() {
	if ( currentPage.indexOf("personal-life-story") > -1 )
		highlight("PersonalLifeStory");
	else if ( currentPage.indexOf("childrens-diary") > -1 )
		highlight("ChildrensDiary");
	else if ( currentPage.indexOf("special-events") > -1 )
		highlight("SpecialEvents");
	else if ( currentPage.indexOf("faq") > -1 )
		highlight("Faq");
	else if ( currentPage.indexOf("tutorial") > -1 )
		highlight("Tutorial");
}

function highlight(imgName){
	imgOn							= eval(imgName + "On.src");
	document.getElementById(imgName).src = imgOn;
}

function turnoff(imgName) {
	if ( currentPage == (eval(imgName + "Off.name")) )
		return;
	imgOff							= eval(imgName + "Off.src");
	document.getElementById(imgName).src 		= imgOff;
}

function closeThickbox() {
	tb_remove();
}

function getFlashMovie(movieName) {
	var isIE 						= navigator.appName.indexOf("Microsoft") != -1;
  	return (isIE) ? window[movieName] : document[movieName];
}

function updateDuration(duration) {
	var mov						= getFlashMovie("theProcess");
	mov.setProgress(duration);
}


function confirmLogout() {
	clearInterval(timerClock);
		
	doLogout();
	/*var doLogoutTimer					= setTimeout("doLogout()", 15000);
	if ( confirm("<#GLB_SESSIONENDING_TRANSLATE_TITLE#>") ) {
		clearTimeout(doLogoutTimer);
	}*/
}

function doLogout() {
	window.location.href					= "end-session.php";
}

function initRedirect() {
	if (typeof document.body.scrollTop != "undefined"){ //IE,NS7,Moz
		xScroll					= document.body.scrollLeft;
		yScroll					= document.body.scrollTop;

		clearInterval(timerPoll); 			//stop polling scroll move
		clearInterval(timerRedirect); 		//stop timed redirect

		timerPoll					= setInterval("pollActivity()",1); //poll scrolling
		timerRedirect					= setInterval("confirmLogout()",theTimeout); //set timed redirect

		//for tracking only
		clearInterval(timerClock);
		clock						= 0;
		timerClock					= setInterval("(clock+1)",theTimeout);
		//end tracking
	}
	else if (typeof window.pageYOffset != "undefined") { //other browsers that support pageYOffset/pageXOffset instead
		xScroll					= window.pageXOffset;
		yScroll					= window.pageYOffset;

		clearInterval(timerPoll); 			//stop polling scroll move
		clearInterval(timerRedirect); 		//stop timed redirect

		timerPoll					= setInterval("pollActivity()",1); //poll scrolling
		timerRedirect					= setInterval("confirmLogout()",theTimeout); //set timed redirect

		//for tracking only
		clearInterval(timerClock);
		clock						= 0;
		timerClock					= setInterval("(clock+1)",theTimeout);
		//end tracking
	}
	//else do nothing
}

function pollActivity() {
	if ((typeof document.body.scrollTop != "undefined" && (xScroll!=document.body.scrollLeft || yScroll!=document.body.scrollTop)) //IE/NS7/Moz
		|| (typeof window.pageYOffset != "undefined" && (xScroll!=window.pageXOffset || yScroll!=window.pageYOffset))) { //other browsers
		initRedirect(); //reset polling scroll position
	}
}

function keepAlive() {
	$.post("keep-alive.php", function(data) {
		self.setTimeout("keepAlive()", 		theTimeout);
	});
}

function initializeSessionHandler() {
	/*document.onmousemove					= initRedirect;
	document.onclick					= initRedirect;
	document.onkeydown					= initRedirect;
	window.onload						= initRedirect;
	window.onresize					= initRedirect;*/

	self.setTimeout("keepAlive()",			theTimeout);
}

function connectFailed() {
	alert(failedConnectString);
}

function doTrim (str) {
	var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

function setLogin() {
	$("#frm_islogin").val("1");
}
