BrowserHistory = new Object();

BrowserHistory.flashElement = null;
BrowserHistory.page_title = top.document.title;
/*
BrowserHistory.may_hash = (top.location.href.indexOf("#") == -1);
BrowserHistory.dont_hash = true;
*/

BrowserHistory.iframe_url = "browser_history_iframe.html";

BrowserHistory.actual = null;

BrowserHistory.init = function() {
	
	// Find flash object
	try {
		BrowserHistory.flashElement = document.getElementById(flash_name);
	} catch(e) {
		try {
			BrowserHistory.flashElement = document[flash_name];
		} catch(e) { }
	}
	
	if(BrowserHistory.flashElement != null) {
		BrowserHistory.flashElement.SetVariable("browser_history_init", "1");
	} else {
		setTimeout(BrowserHistory.init, 1000);
	}
	
}

// Changes the browser's title and address bar
BrowserHistory.updateBrowserInfo = function(title, add_main_title) {
	//BrowserHistory.updateBrowserAddrBar(BrowserHistory.actual);
	BrowserHistory.updateBrowserTitle(title, add_main_title);
}
BrowserHistory.updateBrowserAddrBar = function(value) {
	if(BrowserHistory.dont_hash) BrowserHistory.dont_hash = false;
	else if(BrowserHistory.may_hash && (top.location.hash != "#" + value)) top.location.hash = value;
}
BrowserHistory.updateBrowserTitle = function(title, add_main_title) {
	if(add_main_title !== true) title = BrowserHistory.page_title + " - " +  title;
	title = unescape(title);
	try {
		top.document.title = title;
		BrowserHistory.ifr.contentWindow.document.title = title;
	} catch(e) { };
}

// Set "flash listener" back or foward (navigation) value
BrowserHistory.setFlashVariable = function(value) {
	if(value != BrowserHistory.actual) {
		BrowserHistory.flashElement.SetVariable("browser_history_listener", value);
		BrowserHistory.actual = value;
	}
}

// Open iframe with rights arguments for history navigation
BrowserHistory.setBackSection = function(section, name, iframe_url) {
	
	BrowserHistory.actual = section;
	
	if(!iframe_url) var iframe_url = BrowserHistory.iframe_url;
	iframe_url += "?section=" + section + "&name=" + name;
	
	if(BrowserHistory.ifr) BrowserHistory.ifr.setAttribute("src", iframe_url);
	
}

// Define "Home" initial values
BrowserHistory.setHomeSection = function(section, name, iframe_url) {
	
	BrowserHistory.actual = section;
	
	if(!iframe_url) var iframe_url = "browser_history_iframe.html";
	iframe_url += "?section=" + section + "&name=" + name;
	
	var ifr = document.createElement("iframe");
	ifr.setAttribute("src", iframe_url);
	ifr.style.position = "absolute";
	ifr.style.width = "1px";
	ifr.style.height = "1px";
	ifr.style.top = "-10px";
	document.body.appendChild(ifr);
	
	BrowserHistory.ifr = ifr;
	
}

BrowserHistory.init();


