var G_SECCIONADO=false;
function ObjetoListaInteractiva(){
	this.list = new Array();
	this.listaNombres = new Array();
	this.listaCombos = new Array();
	this.listaPestanas = new Array();
    this.listaEnlaces = new Array();
	this.elementosVisibles =1;
	this.posicion=0;
	this.modoOff="";
	this.modoOn="";
	this.modoPestanaOff="";
	this.modoPestanaOn="";
	this.anadir=anadir;
	this.mostrarAnterior=mostrarAnterior;
	this.mostrarSiguiente=mostrarSiguiente;
	this.mostrarPaginaAnterior=mostrarPaginaAnterior;
	this.mostrarPaginaSiguiente=mostrarPaginaSiguiente;
	this.borrarTodos=borrarTodos;
	this.setElementosVisibles=setElementosVisibles;
	this.getElementosVisibles=getElementosVisibles;
	this.setModoOn=setModoOn;
	this.getModoOn=getModoOn;
	this.setModoOff=setModoOff;
	this.getModoOff=getModoOff;
	this.setModoPestanaOn=setModoPestanaOn;
	this.getModoPestanaOn=getModoPestanaOn;
	this.setModoPestanaOff=setModoPestanaOff;
	this.getModoPestanaOff=getModoPestanaOff;
	this.hacerInvisible=hacerInvisible;
	this.hacerVisible=hacerVisible;
	this.init=init;
	this.init2=init2;
	this.setNombre=setNombre;
	this.getNombre=getNombre;
	this.ocultarTodos=ocultarTodos;
	this.insertOption=insertOption;
	this.anadirCombo=anadirCombo;
	this.mostrarCombo=mostrarCombo;
	this.mostrarPestana=mostrarPestana;
	this.anadirPestanas=anadirPestanas;
	this.getPosicion=getPosicion;
	this.mostrarCapa=mostrarCapa;
	this.mostrarAleatorio=mostrarAleatorio;
	this.setEnlace=setEnlace;
	this.getEnlace=getEnlace;
	this.enlaceSeccion=enlaceSeccion;
	this.enlaceSeccionCategoria=enlaceSeccionCategoria;
	this.pasas=pasas;
	this.play=play;
	this.pause=pause;
	this.timerPlay=null;
	this.llamarOJD=llamarOJD;
    this.hacerVisibleElemento=hacerVisibleElemento;
	this.getIdentificador=getIdentificador;
    this.getNumeroElementos=getNumeroElementos;
}

//Devuelve el objeto por ID

function getObject(id) {
    if( window.mmIsOpera ) return(document.getElementById(id));
    if (document.all) return(document.all[id]);
    if (document.getElementById) return(document.getElementById(id));
    return(false);
}

//devuelve la posición en la que se encuentra el objeto
//Esta función se utiliza para mostrar el número de foto que se está mostrando en un album
function getPosicion(){
	//sumamos uno a la posición, porque empieza en 0.
	return this.posicion+1;
}

//devuelve el id del objeto en función de la posición que ocupa
function getIdentificador(posicion){
	//restamos 1 a la posicion, porque empieza en 0 y pediremos del 1 al n
	//actualizamos la posicion que estamos mostramos
	this.posicion=posicion-1;
	return this.list[posicion-1];
}

function anadirCombo(select){
	this.listaCombos.push(select);
}

function anadirPestanas(pestana){
	this.listaPestanas.push(pestana);
}

function insertOption(){
	for (var i = 0; i < this.list.length; i++) {
	  for (var j = 0; j < this.listaCombos.length; j++) {
		  var y=document.createElement('option');
		  y.text=this.getNombre(this.list[i]);
		  y.value=this.list[i];
		  var x=document.getElementById(this.listaCombos[j]);
		  try
		  {
		    x.add(y,null); // standards compliant
		  }
		  catch(ex)
		  {
		    x.add(y); // IE only
		  }
		}
	}
}

function mostrarPestana(id){
	
	// llamada a nielsen por si no existe el metodo en contenidos antiguos
	try{
		trac.slideEvent("galeria");
	}catch(e){}
	this.ocultarTodos();
	this.hacerVisible(id);
	//Recorremos las pestanas para ponerlas en modo off
	for (var i = 0; i < this.listaPestanas.length; i++) {
		document.getElementById(this.listaPestanas[i]).className=this.getModoPestanaOff();
	}
	//Ponemos la seleccionada en modo On
	document.getElementById("pestana"+id).className=this.getModoPestanaOn();
}

function mostrarCombo(id){
		var x=document.getElementById(id);
		//Si el seleccionado es el 0 no hacemos nada
		if (x.selectedIndex==0){
			return;
		}
		this.ocultarTodos();
		//situamos la posicion, será la seleccionada -1
		this.posicion=x.selectedIndex-1;
		this.hacerVisible(x.options[x.selectedIndex].value);
		//Recorremos los combos para seleccionar el indice seleccionado
		for (var i = 0; i < this.listaCombos.length; i++) {
			var combos=document.getElementById(this.listaCombos[i]);
			combos.options[x.selectedIndex].selected=true;
		}
}

function llamarOJD(seccion){
	var seccionado="0"
	url = "http://lavozdegalicia.ojdinteractiva.com/cgi-bin/ivw/CP/"+seccion+"?r="+escape(document.referrer);
	if (document.getElementById("ojd")!=null){
		document.getElementById("ojd").src=url;
		if (G_SECCIONADO){
			seccionado=seccion;
		}
		document.getElementById("ojd").src="//secure-uk.imrworldwide.com/cgi-bin/m?ci=es-lavozgal&cg="+ seccionado +"&cc=1";
	}
}	

function anadir(id){
	this.list.push(id);
}

function setNombre(id, nombre){
	this.listaNombres[id]=nombre;
}

function getNombre(id){
	return(this.listaNombres[id]);
}

function setEnlace(id, enlace){
	this.listaEnlaces[id]=enlace;
}

function getEnlace(id){
	return(this.listaEnlaces[id]);
}

function ocultarTodos(){
	for (var i = 0; i < this.list.length; i++) {
		this.hacerInvisible(this.list[i]);
	}
}

function mostrarPaginaAnterior(){
	for (var i = 0; i < this.getElementosVisibles(); i++) {
		this.mostrarAnterior();
	}
}

function mostrarPaginaSiguiente(){
	for (var i = 0; i < this.getElementosVisibles(); i++) {
		this.mostrarSiguiente();
	}
}

function mostrarAnterior(){
	if (this.list.length==1){
		return;
	}
    if (this.posicion==0){
        return;
    }

	if (this.list[this.posicion-1]!=null){
		this.hacerVisible(this.list[this.posicion-1]);
		this.hacerInvisible(this.list[this.posicion+(this.getElementosVisibles()-1)]);
		this.posicion=this.posicion-1;
	}else{
		//Si el salto es de uno, mostramos el ultimo 
		if (this.getElementosVisibles()==1){
			this.hacerVisible(this.list[this.list.length-1]);
			this.hacerInvisible(this.list[this.posicion]);
			this.posicion=this.list.length-1;
		}
	}
}

function mostrarSiguiente(){
	if (this.list.length==1){
		return;
	}
    if (this.posicion==this.list.length-1){
        return;
    }

	if (this.list[this.posicion+this.getElementosVisibles()]!=null){
		this.hacerVisible(this.list[this.posicion+this.getElementosVisibles()]);
		this.hacerInvisible(this.list[this.posicion]);
		this.posicion=this.posicion+1;
	}else{
		//Si el salto es de uno, empezamos de nuevo
		if (this.getElementosVisibles()==1){
			this.hacerVisible(this.list[0]);
			this.hacerInvisible(this.list[this.posicion]);
			this.posicion=0;
		}
	}
}

//funcion para contabilizar las paginas vistas piwik y nielsen
function stat_counter(){
// para hacer impactos en PIWIK
 var divCabecero = getObject("cabecero");
 try{
  if (getObject("imgpiwik")!=null){
    getObject("imgpiwik").src=_pk_getUrlLog('', 3, 'http://piwik.lavozdegalicia.es/piwik.php','');
   
  }else{
   var img = document.createElement("img");
   img.id = "imgpiwik";
   img.border = 0;
   img.width = 0;
   img.height = 0;
   img.src = _pk_getUrlLog('', 3, 'http://piwik.lavozdegalicia.es/piwik.php','');
   divCabecero.appendChild(img);
  }
 }catch(e){}
 // para hacer impactos en NIELSEN
 
 // llamada a nielsen por si no existe el metodo en contenidos antiguos
	try{
		trac.slideEvent("galeria");
	}catch(e){
		try{
			if (getObject("ojd")!=null){
			getObject("ojd").src="//secure-uk.imrworldwide.com/cgi-bin/m?ci=es-lavozgal&cg=0&cc=1&ts=noscript";
		  }else{
		   var img = document.createElement("img");
		   img.id = "ojd";
		   img.border = 0;
		   img.width = 0;
		   img.height = 0;
		   img.src = "//secure-uk.imrworldwide.com/cgi-bin/m?ci=es-lavozgal&cg=0&cc=1&ts=noscript";
		   divCabecero.appendChild(img);
		  }
		}catch(e){}
	}
}

function play(objetoID){
    getObject(objetoID + 'play').className = 'play inv';
    getObject(objetoID + 'pause').className = 'pause';
    this.timerPlay = setInterval(objetoID + '.pasas()', 5000, '1', '');
}

function pause(objetoID){
    getObject(objetoID + 'play').className = 'play';
    getObject(objetoID + 'pause').className = 'pause inv';
    clearInterval(this.timerPlay);
}

function pasas(direccion, url){
	stat_counter();
	if (direccion=="1"){
		this.mostrarSiguiente();
	}else {
		this.mostrarAnterior();
	}
}


function tratarUrl(m_url){
	var rdo=m_url;
	var pos1=m_url.indexOf("http://lavozdegalicia.ojdinteractiva.com/cgi-bin/ivw/CP/");
	var pos2 = m_url.indexOf("?r=");
	if (pos1!=-1) {
		rdo=m_url.substring(56,pos2);
	}	
	return rdo;
}


function borrarTodos(){
	for (var i = 0; i <= this.list.length; i++) {
		this.list.pop();
	}
}



function setElementosVisibles(numero){
	this.elementosVisibles=numero;
}

function getElementosVisibles(){
	return this.elementosVisibles;
}


function setModoOn(clase){
	this.modoOn=clase;
}

function getModoOn(){
	return this.modoOn;
}

function setModoOff(clase){
	return this.modoOff=clase;
}

function getModoOff(){
	return this.modoOff;
}

function setModoPestanaOn(clase){
	this.modoPestanaOn=clase;
}

function getModoPestanaOn(){
	return this.modoPestanaOn;
}

function setModoPestanaOff(clase){
	return this.modoPestanaOff=clase;
}

function getModoPestanaOff(){
	return this.modoPestanaOff;
}

function init(){
	//hacemos visible el numero de elementos visibles configurados
	for (var i = 0; i < this.getElementosVisibles(); i++) {
		this.hacerVisible(this.list[i]);
	}
	//Si tienes pestanas ponemos la primera como seleccionada
	if (this.listaPestanas.length!=0){
		document.getElementById(this.listaPestanas[0]).className=this.getModoPestanaOn();
	}
	this.insertOption();
}

function init2(){
	//hacemos visible el numero de elementos visibles configurados
	for (var i = 0; i < this.getElementosVisibles(); i++) {
		document.getElementById(this.list[i]).className=this.getModoOn();
	}
	//Si tienes pestanas ponemos la primera como seleccionada
	if (this.listaPestanas.length!=0){
		document.getElementById(this.listaPestanas[0]).className=this.getModoPestanaOn();
	}
	this.insertOption();
}

function hacerInvisible(id){
	document.getElementById(id).className=this.getModoOff();
    if (document.getElementById("pestana" + id) != null)
        document.getElementById("pestana" + id).className=this.getModoPestanaOff();
}

function hacerInvisibleTodos(id){
    capa = document.getElementById(id);
    cnjIMG = capa.getElementsByTagName('img');
    for (var i=0; i<cnjIMG.length; i++) {
        if (cnjIMG[i].attributes.getNamedItem('longdesc')!=null){
            if (cnjIMG[i].attributes.getNamedItem('longdesc').value=="cambiar"){
                cnjIMG[i].src=cnjIMG[i].attributes.getNamedItem('id').value;
            }
        }
    }
    document.getElementById(id).className=this.getModoOff();
}

function hacerVisible(id){
    capa = document.getElementById(id);
    cnjIMG = capa.getElementsByTagName('img');
    for (var i=0; i<cnjIMG.length; i++) {
        if (cnjIMG[i].attributes.getNamedItem('longdesc')!=null){
            if (cnjIMG[i].attributes.getNamedItem('longdesc').value=="cambiar"){
                cnjIMG[i].src=cnjIMG[i].attributes.getNamedItem('id').value;
            }
        }
    }
    document.getElementById(id).className=this.getModoOn();
    if (document.getElementById("pestana" + id) != null)
        document.getElementById("pestana" + id).className=this.getModoPestanaOn();
}

function mostrarCapa(id){
	this.ocultarTodos();
	this.hacerVisible(id);
}

function mostrarAleatorio (){
	var tope=this.list.length;
	var VerElemento=Math.floor(Math.random()*tope);
	this.hacerInvisible(this.list[this.posicion]);
	this.hacerVisible(this.list[VerElemento]);
	this.posicion=VerElemento;
}

function enlaceSeccion(id){
    var x=document.getElementById(id);
    //Si el seleccionado es el 0 no hacemos nada
    if (x.selectedIndex==0){
        return;
    }
    var idSeleccionado = x.options[x.selectedIndex].value;
    this.enlaceSeccionCategoria(idSeleccionado);
}

function enlaceSeccionCategoria(id){
    var enlace = this.getEnlace(id);
    if (enlace!=null){
        document.location.href=enlace;
    }
}

function hacerVisibleElemento(id,id_inv1, id_inv2){
    this.ocultarTodos();
    m_id = id + "_form";
    getObject(id_inv1).className=id_inv1;
    getObject(id_inv2).className=id_inv2;
    getObject(m_id).className=this.getModoOn();
}

function getNumeroElementos(){
    return this.list.length;
}

//************************ SCRIPT PUBLICIDAD *******************************
var server_name="publicidadinternet2.lavozdegalicia.es";

function bannerInterno(zoneId) {

	if (!document.phpAds_used) document.phpAds_used = ',';
	document.write ("<" + "script type='text/javascript' src='");
	document.write ("http://"+server_name+"/adjs.php?n=adda1f64");
	document.write ("&what=zone:"+zoneId+"&amp;target=_blank");
	document.write ("&exclude=" + document.phpAds_used);
	document.write ("'><" + "/script>");
}

var llamada = true;

function muestra(banner) {
	var caja= getObject(banner)
	if (caja) {
		var contenido=caja.innerHTML;
		if (contenido!=null && contenido!="" && !(contenido.indexOf('/default/empty.gif') != -1) && !(contenido.indexOf('-grey.gif') != -1)) {
			caja.style.display = "block";
		} else {
			caja.innerHTML = "";
			caja.style.display = "none";
		}
	}
}
// *********************************** SCRIPT ANTEVENIO ********************************

sas_tmstp=Math.round(Math.random()*10000000000);sas_masterflag=1;
function SmartAdServer(sas_pageid,sas_formatid,sas_target) {
 if (sas_masterflag==1) {
    sas_masterflag=0;sas_master='M';} else {sas_master='S';};
	document.write('<scr'+'ipt src="http://reachandrich.antevenio.com/call/pubj/' + sas_pageid + '/' + sas_formatid + '/' + sas_master + '/' + sas_tmstp + '/' + escape(sas_target) + '?"></scr'+'ipt>');
}
