// detect browser
var ua = navigator.userAgent.toLowerCase();
var is_iexplorer  = ( (ua.indexOf('msie') != -1 ) && ( ua.indexOf('win') != -1 ) && ( ua.indexOf('opera') == -1 ) && ( ua.indexOf('webtv') == -1 ) );

var htmlTitle="Cie Studios";
var oldLocation="";

//init flash vars and initialize hash poll. this function is activated from flash.
function init() {
	window.document.cie_main.SetVariable("is_iexplorer",is_iexplorer);
	window.document.cie_main.SetVariable("htmlTitle",htmlTitle);
	var i=new Object();
	i["is_iexplorer"]=is_iexplorer;
	i["htmlTitle"]=htmlTitle;
	setInterval("checkIfChanged()", 100);
	return i;
}

//parse hash string
function getParams(){
	var states = new Object();
	var stateStr = new String(document.location.search.substr(1) || document.location.href.split("#")[1]);
	var states = stateStr.split(".");
	return states;
}

// get current hash string in a form of an object. called from flash
function getState() {
	var params=getParams();
	return params;
}

// update page title. called from flash.
function updateTitle(title){
	window.document.title = title;
}

// hash poll function. check if the hash changed and send an event to flash
function checkIfChanged(){
	if (oldLocation!=window.document.location.hash.split("#")[1]){
		oldLocation=window.document.location.hash.split("#")[1];
		window.document.cie_main.retrieveState();
	}
}

// update hash. called from flash
function updateHash(hasher) {
	var str=new String(hasher);
	str=str.replace(/,/g, "&");
	window.document.location.hash=str;
}

//refresh iframe in order for explorer to add history entry. after that call updatehash function.
function writeIframe(args){
	document.frames["ciehistoryframe"].document.open();
	document.frames["ciehistoryframe"].document.write("<html><head><title></title>");
	document.frames["ciehistoryframe"].document.write("<script language='JavaScript'>");
	document.frames["ciehistoryframe"].document.write("parent.updateHash('"+args+"');");
	document.frames["ciehistoryframe"].document.write("</" +"script></head><body></body></html>");
	document.frames["ciehistoryframe"].document.close();
}