// 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="Nitto Tire – Fueled by Enthusiasts";
var oldLocation="";
var changedFromFlash=false;

//init flash vars and initialize hash poll. this function is activated from flash.
function init() {
	window.document.nittoFlash.SetVariable("is_iexplorer",is_iexplorer);
	window.document.nittoFlash.SetVariable("htmlTitle",htmlTitle);
	setInterval("checkIfChanged()", 100);
}

//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("%2E");
	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]){
		window.document.nittoFlash.SetVariable("urlChanged","true");
		oldLocation=window.document.location.hash.split("#")[1];

	} else {
		window.document.nittoFlash.SetVariable("urlChanged","false");
	}
}

// update hash. called from flash
function updateHash(hasher) {
	var str=new String(hasher);
	str=str.replace(/,/g, "&");
	if (hasher!=""){
		window.document.location.hash=str;
	} else{
		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["nittohistframe"].document.open();
document.frames["nittohistframe"].document.write("<html><head><title></title>");
document.frames["nittohistframe"].document.write("<script language='JavaScript'>");
document.frames["nittohistframe"].document.write("parent.updateHash('"+args+"');");
document.frames["nittohistframe"].document.write("</" +"script></head><body></body></html>");
document.frames["nittohistframe"].document.close();
}