var orig_title = window.document.title;
var page_n = 0;//used to alternate between pages in history frame
var cur_page_id;//used to check if back or forward button has been pressed

//communication from flash:
function updateHistory(page_id, title) {
	cur_page_id = page_id;
	window.frames["hist"].location.href = "js/history"+(1-page_n)+".html?n="+(1-page_n)+"&page_id="+page_id+"&title="+title;
	return true;	
}

//communication to flash:
function sendPageIdToFlash(movie_id, page_id) {
	document.getElementById(movie_id).gotoPageBrowser(page_id);
}

//called from iframe document	
function setPage(querystr) {
	//read query string
	var params = {};
	var parts = querystr.split("&");
	for (var i=0;i<parts.length;i++) {
		var tmp = parts[i].split("=");
		params[tmp[0]] = tmp[1];
	}
	//check page id
	if (typeof(params["page_id"])!="undefined") {
		if (params["page_id"]!=cur_page_id) {
			sendPageIdToFlash("flash", params["page_id"]);
		}
	} else if (typeof(cur_page_id)!="undefined") {
		window.document.title = unescape(orig_title);
		sendPageIdToFlash("flash", "");
	}
	cur_page_id = params["page_id"];
	//set page title
	if (typeof(params["title"])!="undefined") {
		window.document.title = unescape(params["title"]);
		window.frames["hist"].document.title = unescape(params["title"]);
	}	
	//set counter for page-alternation in history frame
	if (typeof(params["n"])!="undefined") {
		page_n = params["n"];
	}
}
