/**
 * @author jk
 */

window.onload = function(){
    if (!document.getElementsByTagName) {
        return;
    }
	paginainicial="pagina3.php";
    rehacerenlaces();
	rehacerscrollbars();
	inithistorial();
};

function rehacerenlaces(){
	var anchors = document.getElementsByTagName('a');
    for (var i = 0; i < anchors.length; i++) {
        var anchor = anchors[i];
        
        var relAttribute = String(anchor.getAttribute('rel'));       
        
        if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('akload'))) {
				anchor.onclick = function(){
				var pagina=this.href.split("/");
				window.location.hash=pagina[pagina.length-1];
				if (isIE) {
					document.getElementById("ifriesux").src = this.href;
				}
				paginaanterior=pagina[pagina.length-1];
				eval(this.rel.toLowerCase().replace("akload:",""));
				 return false;
            }
        }
    }
}

function rehacerscrollbars(){
	var scrollers = document.getElementsByTagName('div');
	scrollbarsloaded=new Array();
    for (var i = 0; i < scrollers.length; i++) {
        var scroller = scrollers[i];
        
        var relAttribute = String(scroller.getAttribute('rel'));       
        
        if (relAttribute.toLowerCase().match('akscroller')) {
			var scrAk=new AKscrollbar();
				scrAk.hallarbarra(relAttribute.toLowerCase().replace('akscroller:',''));
        }
    }
}




function borrarnodos(){
    while (document.getElementById("contenedores").hasChildNodes()) {
        document.getElementById("contenedores").removeChild(document.getElementById("contenedores").lastChild);
    }
}

function crearsuperior(){
    borrarnodos();
    
    var seccionsuperior = document.createElement("div");
    seccionsuperior.id = "seccionsuperior";
    document.getElementById("contenedores").appendChild(seccionsuperior);
}

function plantilla1dest(){

    crearsuperior();
    
    var destadossuperior = document.createElement("div");
    destadossuperior.id = "destadossuperior";
    
    var destacado31up = document.createElement("div");
    destacado31up.id = "destacado31up";
    destacado31up.className = "undestacadoup";
    destadossuperior.appendChild(destacado31up);
    
    document.getElementById("contenedores").appendChild(destadossuperior);
    
    var destacados = document.createElement("div");
    destacados.id = "destacados";
    
    var undestacadoinit = document.createElement("div");
    undestacadoinit.id = "undestacadoinit";
    undestacadoinit.className = "undestacadoinit";
    destacados.appendChild(undestacadoinit);
    
    document.getElementById("contenedores").appendChild(destacados);
    
    var pie1dest = document.createElement("div");
    pie1dest.id = "pie1dest";
    document.getElementById("contenedores").appendChild(pie1dest);
    
}

function plantilla2dest(){

    crearsuperior();
    
    var destadossuperior = document.createElement("div");
    destadossuperior.id = "destadossuperior";
    
    var destacado21up = document.createElement("div");
    destacado21up.id = "destacado21up";
    destacado21up.className = "dosdestacadosup";
    destadossuperior.appendChild(destacado21up);
    
    var destacado22up = document.createElement("div");
    destacado22up.id = "destacado22up";
    destacado22up.className = "dosdestacadosup";
    destadossuperior.appendChild(destacado22up);
    
    document.getElementById("contenedores").appendChild(destadossuperior);
    
    var destacados = document.createElement("div");
    destacados.id = "destacados";
    
    var dosdestacadosinit = document.createElement("div");
    dosdestacadosinit.id = "dosdestacadosinit";
    dosdestacadosinit.className = "dosdestacadosinit";
    destacados.appendChild(dosdestacadosinit);
    
    var dosdestacadosresto = document.createElement("div");
    dosdestacadosresto.id = "dosdestacadosresto";
    dosdestacadosresto.className = "dosdestacadosresto";
    destacados.appendChild(dosdestacadosresto);
    
    document.getElementById("contenedores").appendChild(destacados);
    
    var pie2dest = document.createElement("div");
    pie2dest.id = "pie2dest";
    document.getElementById("contenedores").appendChild(pie2dest);
    
}

function plantilla3dest(){

    crearsuperior();
    
    var destadossuperior = document.createElement("div");
    destadossuperior.id = "destadossuperior";
    
    var destacado1up = document.createElement("div");
    destacado1up.id = "destacado1up";
    destacado1up.className = "tresdestacadosup";
    destadossuperior.appendChild(destacado1up);
    
    var destacado2up = document.createElement("div");
    destacado2up.id = "destacado2up";
    destacado2up.className = "tresdestacadosup";
    destadossuperior.appendChild(destacado2up);
    
    var destacado3up = document.createElement("div");
    destacado3up.id = "destacado2up";
    destacado3up.className = "tresdestacadosup";
    destadossuperior.appendChild(destacado3up);
    
    document.getElementById("contenedores").appendChild(destadossuperior);
    
    var destacados = document.createElement("div");
    destacados.id = "destacados";
    
    var tresdestacadosinit = document.createElement("div");
    tresdestacadosinit.id = "tresdestacadosinit";
    tresdestacadosinit.className = "tresdestacadosinit";
    destacados.appendChild(tresdestacadosinit);
    
    var tresdestacadosresto = document.createElement("div");
    tresdestacadosresto.id = "tresdestacadosresto1";
    tresdestacadosresto.className = "tresdestacadosresto";
    destacados.appendChild(tresdestacadosresto);
    
    var tresdestacadosresto = document.createElement("div");
    tresdestacadosresto.id = "tresdestacadosresto2";
    tresdestacadosresto.className = "tresdestacadosresto";
    destacados.appendChild(tresdestacadosresto);
    
    document.getElementById("contenedores").appendChild(destacados);
    
    var pie3dest = document.createElement("div");
    pie3dest.id = "pie3dest";
    document.getElementById("contenedores").appendChild(pie3dest);
    
}

function plantillaseccion(){
    borrarnodos();
    
    var seccion = document.createElement("div");
    seccion.id = "seccion";
    document.getElementById("contenedores").appendChild(seccion);
    
    var pieseccion = document.createElement("div");
    pieseccion.id = "pieseccion";
    document.getElementById("contenedores").appendChild(pieseccion);
}

function pagina1(){
    plantilla1dest();
    AKajaxload(Array('seccionsuperior', 'undestacadoinit'), Array('web/1.html', 'web/2.html'))
}

function pagina2(){
    plantilla2dest();
    AKajaxload(Array('seccionsuperior', 'dosdestacadosinit', 'dosdestacadosresto'), Array('web/1.html', 'web/2.html', 'web/3.html'))
}

function pagina3(){
    plantilla3dest();
    AKajaxload(Array('seccionsuperior', 'tresdestacadosinit', 'tresdestacadosresto1', 'tresdestacadosresto2'), Array('web/1.html', 'web/2.html', 'web/3.html', 'web/4.html'))
}

function pagina4(){
    plantillaseccion();
    AKajaxload(Array('seccion'), Array('web/1.html'))
}

