
window.dhtmlHistory.create({
        toJSON: function(o) {
                return Object.toJSON(o);
        }
        , fromJSON: function(s) {
                return s.evalJSON();
        }
});

window.onload = function(){	
	// initialize the DHTML History framework
	dhtmlHistory.initialize();	
	// subscribe to DHTML history change events
	dhtmlHistory.addListener(historyChange);
	
	if (dhtmlHistory.isFirstLoad()) {		
		carrega_conteudo('home.php');
	}
}


function getXmlHttp() {
	//verifica se o browser tem suporte a ajax
	var xmlhttp;
	try{
		xmlhttp = new XMLHttpRequest();
	}
	catch(ee){
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e){
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(E){
				xmlhttp = false;
			}
		}
	}
	return xmlhttp;
}

function carrega_conteudo(pagina){
	dhtmlHistory.add(pagina,pagina);
	var obj = document.getElementById('conteudo_pagina'); 
	var xmlhttp = getXmlHttp();	
	url = pagina;
	xmlhttp.open("GET", url, true);
	obj.innerHTML = '<div style="margin:20px; text-align:center;"><img src="images/loading-blue.gif" /></div>';
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState == 4){				
			obj.innerHTML = xmlhttp.responseText;
			obj.style.display = "";	
		}
	}	
	xmlhttp.send(null);	
}

function carrega_noticia(id_noticia){	
	url = "noticias.php?id_noticia_link="+id_noticia;
	carrega_conteudo(url);
	/*dhtmlHistory.add(url,url);
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState == 4){				
			var string = xmlhttp.responseText.split("|");			
			document.getElementById('imagem_noticia').setAttribute('src','adm/_noticias/'+string[0]); 
			document.getElementById('data_noticia').innerHTML = string[1];
			document.getElementById('titulo_noticia').innerHTML = string[2];
			document.getElementById('texto_noticia').innerHTML = string[3];
			
		}
	}	
	xmlhttp.send(null);*/
}

function historyChange(newLocation, historyData) {	
	carrega_conteudo(newLocation);
}