var GL_PREVG=0;
var GL_PREVMSG;
var GL_STEP=0;

/*
var GL_CACHE_TAM=8;
var GL_CACHE_MAX=7;
var GL_CACHE_MIN=0;
*/
var GL_CACHE_TAM=16;
var GL_CACHE_MAX=15;
var GL_CACHE_MIN=0;

var GL_CACHE_POS=-1;
var GL_CACHE=new Array();

var GL_CACHE_HOME;
var GL_PREV_ONLOAD;	//Por ahora no modificamos el onload

function saveHome(){
	GL_CACHE_HOME=getSnapshoot();
}
function malert(cadena){
	//document.getElementById("TxTDebug").value=document.getElementById("TxTDebug").value+"\n"+cadena;
}
function getSnapshoot(reloadIsNeed){
	malert("getSnapshoot :: ");
	var aTmp=new Array();
	aTmp["content"]=new Array();
	aTmp["content_player"]=new Array();
	aTmp["region_playerlogin"]=new Array();
	aTmp["reloadIsNeed"]=reloadIsNeed;	
	aTmp["nav"]=new Array();
	aTmp["ruta"]=new Array();
	aTmp["locationHash"]=new Array();
	aTmp["documentTitle"]=new Array();
	if(typeof getSkinCurrent!="undefined")
		aTmp["currentSkin"]=getSkinCurrent();
	else
		aTmp["currentSkin"]="";
	if(document.getElementById("content")){
		aTmp["content"]["innerHTML"]=document.getElementById("content").innerHTML;
		aTmp["content"]["display"]=document.getElementById("content").style.display;	
	}
	if(document.getElementById("content_player")){
		aTmp["content_player"]["display"]=document.getElementById("content_player").style.display;	
	}
	if(document.getElementById("region_playerlogin")){
		aTmp["region_playerlogin"]["innerHTML"]=document.getElementById("region_playerlogin").innerHTML;
		aTmp["region_playerlogin"]["display"]=document.getElementById("region_playerlogin").style.display;
	}
	if(document.getElementById("nav")){
		aTmp["nav"]["innerHTML"]=document.getElementById("nav").innerHTML;
		aTmp["nav"]["display"]=document.getElementById("nav").style.display;
	}
	if(document.getElementById("ruta")){
		aTmp["ruta"]["innerHTML"]=document.getElementById("ruta").innerHTML;
		aTmp["ruta"]["display"]=document.getElementById("ruta").style.display;
	}	
	if(window.location.hash){
		aTmp["locationHash"]=top.location.hash;
	}else{
		aTmp["locationHash"]="";
	}
	if(document.title){
		aTmp["documentTitle"]=top.document.title;
	}else{
		aTmp["documentTitle"]="";
	}	
	return aTmp;
}
function loadSnapshoot(aTmp){
	malert("loadSnapshoot :: aTmp:"+(typeof aTmp));
	if(aTmp){
		if(typeof player_Stop!="undefined"){
			player_Stop();
		}
		if(aTmp["currentSkin"]){
			if(typeof onSkinChange!="undefined"){
				onSkinChange(aTmp["currentSkin"]);
			}
		}
		if(aTmp["content"]){
			malert("loadSnapshoot contentDisplay "+aTmp["content"]["display"]);
			if(document.getElementById("content")){
				document.getElementById("content").innerHTML=aTmp["content"]["innerHTML"];
				document.getElementById("content").style.display=aTmp["content"]["display"];	
			}
		}
		if(aTmp["content_player"]){
			malert("loadSnapshoot contentplayerDisplay "+aTmp["content_player"]["display"]);
			if(document.getElementById("content_player")){
				document.getElementById("content_player").style.display=aTmp["content_player"]["display"];	
			}
		}
		if(aTmp["region_playerlogin"]){
			malert("loadSnapshoot regionplayerloginDisplay "+aTmp["region_playerlogin"]["display"]);
			if(document.getElementById("region_playerlogin")){
				document.getElementById("region_playerlogin").innerHTML=aTmp["region_playerlogin"]["innerHTML"];
				document.getElementById("region_playerlogin").style.display=aTmp["region_playerlogin"]["display"];
			}	
		}
		if(aTmp["nav"]){
			malert("loadSnapshoot navDisplay "+aTmp["nav"]["display"]);
			if(document.getElementById("nav")){
				document.getElementById("nav").innerHTML=aTmp["nav"]["innerHTML"];
				document.getElementById("nav").style.display=aTmp["nav"]["display"];
			}	
		}
		if(aTmp["ruta"]){
			malert("loadSnapshoot rutaDisplay "+aTmp["ruta"]["display"]);
			if(document.getElementById("ruta")){
				document.getElementById("ruta").innerHTML=aTmp["ruta"]["innerHTML"];
				document.getElementById("ruta").style.display=aTmp["ruta"]["display"];
			}	
		}			
		if(aTmp["locationHash"]){
			var sUrl="";
			if(parent){
				sUrl=parent.top.location.pathname+parent.top.location.search;
			}else{
				sUrl=top.location.pathname+parent.top.location.search;
			}
			/*
			alert("alf1:"+aTmp["locationHash"]);
			if(parent)
				alert("alf2:"+parent.top.location);
			alert("alf3:"+top.location);
			*/
			if(parent)
			parent.top.location.replace(sUrl+aTmp["locationHash"]);
			else
			top.location.replace(sUrl+aTmp["locationHash"]);
		}else{
			var sUrl="";
			if(parent){
				sUrl=parent.top.location.pathname+parent.top.location.search;
			}else{
				sUrl=top.location.pathname+parent.top.location.search;
			}
			if(parent)
			parent.top.location.replace(sUrl+("#"+new Date().getTime()));
			else
			top.location.replace(sUrl+("#"+new Date().getTime()));			
		}
		if(aTmp["documentTitle"]){
			top.document.title=aTmp["documentTitle"];
		}		
	}
}
function saveSnapshoot(reloadIsNeed){		
	GL_CACHE_POS++;
	if(GL_CACHE_POS<=GL_CACHE_MAX&&GL_CACHE_POS>=GL_CACHE_MIN){
		GL_CACHE[GL_CACHE_POS-GL_CACHE_MIN]=getSnapshoot();
		malert("saveSnapshootMode :: Usa: "+(GL_CACHE_POS-GL_CACHE_MIN));
	}else{
		malert("saveSnapshootMode :: Push");
		GL_CACHE.push(getSnapshoot());
	}
	if(GL_CACHE.length>GL_CACHE_TAM){
		GL_CACHE_MIN=GL_CACHE_POS-(GL_CACHE_TAM-1);
		GL_CACHE_MAX=GL_CACHE_POS;
		GL_CACHE.shift();
	}
	malert("saveSnapshootEnd :: "+", GL_CACHE_MIN:"+GL_CACHE_MIN+",GL_CACHE_POS:"+GL_CACHE_POS+",GL_CACHE_MAX:"+GL_CACHE_MAX);		
	/*
	//GL_CACHE.push(getSnapshoot());
	GL_CACHE[GL_CACHE_POS-GL_CACHE_MIN]=getSnapshoot(reloadIsNeed);
	if(GL_CACHE_POS-GL_CACHE_MIN>GL_CACHE_MAX){
		GL_CACHE_MIN=GL_CACHE_POS-GL_CACHE_MAX;
		//GL_CACHE.shift(); //elimino el primer elemento
	}
	malert("saveSnapshoot "+", GL_CACHE_MIN:"+GL_CACHE_MIN+",GL_CACHE_POS:"+GL_CACHE_POS);	
	*/
}
function restoreSnapshoot(vpos){
	malert("restoreSnapshoot :: vpos:"+vpos+", GL_CACHE_MIN:"+GL_CACHE_MIN+",GL_CACHE_POS:"+GL_CACHE_POS+",GL_CACHE_MAX:"+GL_CACHE_MAX);
	if(vpos<=GL_CACHE_MAX&&vpos>=GL_CACHE_MIN){
		loadSnapshoot(GL_CACHE[vpos-GL_CACHE_MIN]);
		GL_CACHE_POS=vpos;
	}else{
		manageHome();
	}
}
function manageStep(i,test){
	if(i<GL_CACHE_MIN){
		manageHome();
	}else{
		GL_STEP=i;
		//document.getElementById("paso_actual").value=GL_STEP;
		restoreSnapshoot(parseInt(i));
		GL_STEP=i+1;
	}
	
}
function manageHome(){
	//alert("VOY A HOME");
	if(GL_CACHE_HOME){
		loadSnapshoot(GL_CACHE_HOME);
	}else{
		treeOnStart();
	}
}

function getNotifyBack(mensaje,i){
	malert("getNotifyBack :: mensaje:"+mensaje+" i:"+i);
	var vstep;
	if(i){
		GL_PREVMSG=mensaje;
	}else{
		if(GL_PREVMSG){
		vstep=mensaje.replace(/[^_]+_/,"");
		if(parseInt(vstep)){
			malert("restoreSnapshoot :: vstep:"+parseInt(vstep)+"-gl_prevmsg:"+GL_PREVMSG+",mensaje:"+mensaje);
			manageStep(parseInt(vstep)-1,"backbrowser");
		}else{
			malert("restoreSnapshoot :: NaN");	
			manageStep(-1,"backbrowser");
		}
		}
		GL_PREVMSG="";
	}
	/*
	if(i){
		vstep=mensaje.replace(/[^_]+_/,"");
		if(parseInt(vstep)){
			manageStep(parseInt(vstep)-1,1);
		}
	}
	*/
	/*
	var vstep;
	if(GL_PREVG){
		if(mensaje){
			if(mensaje=="firstload"){
				manageStep(0);
				if(window.frames["frm_all_back"]){
					window.frames["frm_all_back"].nobubble=false;
				}				
			}else{
			vstep=mensaje.replace(/[^_]+_/,"");
			if(vstep){
				if(parseInt(vstep)){
					manageStep(parseInt(vstep));
					if(window.frames["frm_all_back"]){
						window.frames["frm_all_back"].nobubble=false;
					}
				}
			}
			}
		}
		GL_PREVG=0;
	}else{
		if(i){
			GL_PREVG=1;
		}
	}
	*/
}
function sendNotifyBack(mensaje){
	if(typeof mensaje=="undefined"){
		GL_STEP++
		mensaje=GL_STEP;
	}
	malert("sendNotifyBack :: mensaje:"+mensaje);
	saveSnapshoot();
	//document.getElementById("paso_actual").value=mensaje;
	var rand=new Date().getTime();
	if(mensaje!="firstload"){
		if(window.frames["frm_all_back"]){
			window.frames["frm_all_back"].nobubble=true;
			window.frames["frm_all_back"].document.location="/backload.html?random="+rand+"&stepactual="+mensaje;
		}
	}
}

/*
function treeOnStart(){
	malert("VOLVI A LA HOME");
}
function mostrarLogin(nro){
	if(document.getElementById("region_playerlogin")){
		document.getElementById("region_playerlogin").innerHTML=document.getElementById("region_playerlogin").innerHTML.replace(/X[0-9]*X/,"X"+nro+"X");
		document.getElementById("region_playerlogin").style.display="block";
	}
	document.getElementById("content").style.display="none";
	document.getElementById("content_player").style.display="none";
}
function mostrarHome(nro){
	if(document.getElementById("content")){
		document.getElementById("content").innerHTML=document.getElementById("content").innerHTML.replace(/X[0-9]*X/,"X"+nro+"X");
		document.getElementById("content").style.display="block";
	}
	document.getElementById("region_playerlogin").style.display="none";
	document.getElementById("content_player").style.display="none";
}
function mostrarPlayer(nro){
	if(document.getElementById("content_player")){
		document.getElementById("content_player").innerHTML=document.getElementById("content_player").innerHTML.replace(/X[0-9]*X/,"X"+nro+"X");
		document.getElementById("content_player").style.display="block";
	}
	document.getElementById("region_playerlogin").style.display="none";
	document.getElementById("content").style.display="none";
}
function malert(cadena){
	document.getElementById("TxTDebug").value=document.getElementById("TxTDebug").value+"\n"+cadena;
	alert(cadena);
}

function refrescarMolesto(nro){
	window.frames["molesto"+nro].location="blank.html?rnd="+(new Date().getTime());
}
*/