// History Manager - Rev 0.1
// Benzin framework
// Copyright 2007 Ricardo Moutinho. All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function addToBrowserHistory(type, value){
	var currentLoc = document.location.href;
	var randomnumber=Math.floor(Math.random()*8973492837423);
	var protocol = document.location.protocol + "//";
	var domain = document.location.host;
	var path = document.location.pathname;
	var hash = document.location.hash;
	var suffix = "#type="+type+"&value="+value;
	var url = protocol + domain + path + suffix;
	addHistory(url, value); 
}


function createHistoryFrame() {
	historyFrame = document.createElement("iframe");
	historyFrame.setAttribute("name", "historyFrames");
	historyFrame.setAttribute("id", "historyFrames");

	historyFrame.setAttribute("src", 'javascript:;');
	historyFrame.style.position = "absolute";
	historyFrame.style.top = "-5000px";
	
	document.body.insertBefore(historyFrame,document.body.firstChild);
	historyFrameRef = frames["historyFrames"];
	
	createHistoryHTML("");
}

function updateFromHistory(hash){
	if (hash != ""){
		updateHash(hash);
		//alert(hash);
	}
	
}

function updateHash(url, title){
	//alert(historyFrame.src);
	
	//document.title = "PdM";

	if (document.location != url){
		document.location = url;		
		sendToActionScript(url);
	}
}

function createHistoryHTML($newHash) {
	with (historyFrameRef.document) {
		open("text/html");
		write("<html><head></head><body onl",
		'oad="parent.updateFromHistory(\''+$newHash+'\');">',
			$newHash+"</body></html>");
		close();
	}
}

function addHistory(url, title){
        //updateHash(url, title);
	document.location = url;
	document.title = title;
	historyFrame.src = url;
	createHistoryHTML(url);
}
