var hash=(typeof((hash=location.href.split("#")[1]))!="undefined"?hash:"");
window.onload=function(){
	criaElementos(); verificaInt=setInterval("verifica()", 100);
	if(hash==""||hash==null){
    ajax('home.html'); return false;
	}
}
page=""; prefix="[page]"; index="homeBackState"; is_ie=(navigator.userAgent.toLowerCase().indexOf("msie")!=-1)?true:false;

function criaElementos(){
	var theBody=document.getElementsByTagName("body")[0];
	var iframe=document.createElement("iframe");
	iframe.setAttribute("src", "control.htm?id="+prefix+index);
	iframe.setAttribute("id", "bmr-ajaxControl");
	iframe.style.display="none";
	theBody.appendChild(iframe);
}

function volta_index(){
	location="http://"+location.host+location.pathname+"#"; location.reload();
}
	
function ajax(pag){
	var iframe=document.getElementById('bmr-ajaxControl');
	if(is_ie){
	iframe.src="control.htm?id="+prefix+pag;
	window.document.topo_flash.SetVariable("bt_selecionado", pag.split('.html').join(''));
	}else{
		if(pag!=index){location.hash=prefix+pag;
		}else{
		volta_index();
		}
	}
}
	
function verifica(){
	var hash=(typeof((hash=location.href.split("#")[1]))!="undefined"?hash:"");
	if(hash!=page){
		if(hash!="" && hash.indexOf(prefix)!=-1){
		new Ajax.Updater('conteudo', hash.replace(prefix,""), {asynchronous:true, evalScripts:true});
		page=hash; ajax(hash.replace(prefix,""));
		}else{
		clearInterval(verificaInt);
		location.hash=page; //Index
		ajax(index);
		}
	}

}