
function inicia(){
	
	//POPUP DE ENVIO DE NOTICIAS ////////////////////////////////////////////////////////////////////
	if($$('.popup')!=""){
		$$('.popup').addEvent('click', function(e) {
			e = new Event(e); e.stop();
			window.open(this.href, 'popup', 'width=400,height=520,scrollbars=no,noresizable');
		});
	}
	//POPUP DE CAJA DUERO ////////////////////////////////////////////////////////////////////
	if($$('.popupCajaDuero')!=""){
		$$('.popupCajaDuero').addEvent('click', function(e) {
			e = new Event(e); e.stop();
			window.open(this.href, 'Window', 'status=no,scrollbars=no,menubar=no,width=500,height=500');
		});
	}
	
	//POPUP DE ENVIO DE NOTICIAS ////////////////////////////////////////////////////////////////////
	if($$('.toolTips')!=""){
		var aTips = new Array();
		$$('.toolTips').each(function(tool, i){
			aTips[i] = new Tips(tool, {
				initialize:function(){
					this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 300, wait: false}).set(0);
				},
				onShow: function(toolTip) {
					this.fx.start(1);
				},
				onHide: function(toolTip) {
					this.fx.start(0);
				}
			});
		});		
	}
	
	//TAMANO DE LA FUENTE ////////////////////////////////////////////////////////////////////
	if($('fontResize')){
		var letra = new cambiaLetra($('fontResize'), $$('.aumLetra'), $$('.dismLetra'), $$('.reestablecer'), 25, 8);
	}

	//AMPLIAR Y REDUCIR BUSCADOR /////////////////////////////////////////////////////
	if($$('.buscadorLink')!=""){
		var ampliarBuscador = new Fx.Slide('buscador', {duration: 500}).hide();
		$$('.buscadorLink').addEvent('click', function(e) {
				e = new Event(e); e.stop();
				ampliarBuscador.toggle();
		});
	}
	 
	//AMPLIAR Y REDUCIR LA IMAGEN GRANDE /////////////////////////////////////////////////////
	if($$('.ampliaryreducir')!=""){
		var ampliaryreducir = new Fx.Slide('fotoSup', {duration: 500});
		$$('.ampliaryreducir').addEvent('click', function(e) {
				e = new Event(e); e.stop();
				ampliaryreducir.toggle();
				if(this.className=="ampliaryreducir2")	this.className = "ampliaryreducir";
				else this.className = "ampliaryreducir2";	
		});
	}
	
	//DESCARGAR AUDIO
	if($$('.descargarAudio')!=''){
		$$('.descargarAudio').addEvent('click', function(e){new Event(e).stop();
			window.open('http://www.realvalladolid.es/descargarAudio.php?ruta='+this.href, 'popupAudiodescarga', 'width=200,height=200,scrollbars=no,noresizable');
		});
	}
		
}
//MARCADOR //////////////////////////////////////////////////////////////////////////
function marcador(){
	if($$('.resulMarcador')!=""){
		var marcaNew = new Marcador($$('.resulMarcador li'), 40, 5000, 500).start();	
	}
}

//FUNCION PARA EL POPUP DE CAJA DUERO ////////////////////////////////////////////////
function MM_openBrWindow(ruta, nombre, opciones){
	window.open(ruta, nombre, opciones);
}

/* -----------------------------------------------------------------------------
MARCADOR DE RESULTADOS ---------------------------------------------------------
-------------------------------------------------------------------------------- */ 
var Marcador = new Class({
    
		initialize: function(elementos, altura, tiempo, velocidad){
			this.elem = elementos;
			this.altura = altura;
			this.tiempo = tiempo;
			this.activo = 0;
			this.velocidad = velocidad;
			this.anterior = $$('.antResul');
			this.siguiente = $$('.sigResul');
			this.pausa = $$('.pausaResul');
			
			this.elem.each(function(elemento, i){
				elemento.setStyle('position', 'absolute');
				if(i==0) elemento.setStyle('top', '0px');
				else elemento.setStyle('top', this.altura+'px');
			}.bind(this));
			
			document.addEvent('unload',function(){$clear(this.myTimer);});
    },
		
		start: function(){
			this.myTimer = this.mueve.periodical(this.tiempo, this);
			
			this.anterior.addEvent('click', function(e){new Event(e).stop(); this.irant();}.bind(this));
			this.anterior.addEvent('mouseover', function(){this.setOpacity(0.4);});
			this.anterior.addEvent('mouseout', function(){this.setOpacity(1);});
			
			this.siguiente.addEvent('click', function(e){new Event(e).stop(); this.irsig();}.bind(this));
			this.siguiente.addEvent('mouseover', function(){this.setOpacity(0.4);});
			this.siguiente.addEvent('mouseout', function(){this.setOpacity(1);});
			
			this.pausa.addEvent('click', function(e){new Event(e).stop(); this.pausar();}.bind(this));
			this.pausa.addEvent('mouseover', function(){this.setOpacity(0.4);});
			this.pausa.addEvent('mouseout', function(){this.setOpacity(1);});
		},
		
		mueve: function(){
			if(this.activo==this.elem.length-1){
				this.ver(this.activo, 'vete');
				this.activo = 0;	
			}else{
				this.ver(this.activo, 'vete');
				this.activo+=1;
			}
			this.ver(this.activo,'entra');
		},
		
		ver: function(num, sube){
			if(sube=='entra'){
				var fx = new Fx.Style(this.elem[num], 'top', {duration: this.velocidad}).start(this.altura, 0);
			}else if(sube=='vete'){
				var fx = new Fx.Style(this.elem[num], 'top', {duration: this.velocidad}).start(0, '-'+this.altura);
			}else if(sube=='entraArriba'){
				var fx = new Fx.Style(this.elem[num], 'top', {duration: this.velocidad}).start('-'+this.altura, 0);
			}else if(sube=='veteAbajo'){
				var fx = new Fx.Style(this.elem[num], 'top', {duration: this.velocidad}).start(0, this.altura);
			}
		},
		
		pausar: function(){
			$clear(this.myTimer);	
		}, 
		
		irant: function(){
			$clear(this.myTimer);	
			this.ver(this.activo, 'veteAbajo');
			if(this.activo==0){
				this.activo=this.elem.length-1;
			}else{
				this.activo-=1;
			}
			this.ver(this.activo, 'entraArriba');
			this.myTimer = this.mueve.periodical(this.tiempo, this);
		}, 
		
		irsig: function(){
			$clear(this.myTimer);	
			this.mueve();
			this.myTimer = this.mueve.periodical(this.tiempo, this);
		}

});

/* -----------------------------------------------------------------------------
FUNCIONES EXTRAS ---------------------------------------------------------------
----------------------------------------------------------------------------- */ 
var cambiaLetra = new Class({
    
		initialize: function(contenedor, aumenta, disminuye,reestablecer, maximo, minimo){
			this.contenedor = contenedor;
			this.aumenta = aumenta;
			this.disminuye = disminuye;
			this.reestablecer = reestablecer;
			this.maximo = maximo;
			this.minimo = minimo;
			this.ini = contenedor.getStyle('font-size').toInt();
			this.num = contenedor.getStyle('font-size').toInt();
			this.actual = contenedor.getStyle('font-size').toInt();
			//ruta del dominio (sin incluir el servidor)
			this.dominio = "/";
			//this.dominio = "/realvalladolid.es/";
							
			if(Cookie.get("letraTamano")){
				this.num = Cookie.get("letraTamano").toInt();
				this.compruebaMaxMin();
				this.resize(this.num);
			}
			this.disminuye.addEvent('click', function(e){
								new Event(e).stop();
                        this.dism();
                    }.bind(this)
			);
			this.aumenta.addEvent('click', function(e){
								new Event(e).stop();
                        this.aum();
                    }.bind(this)
			);
			this.reestablecer.addEvent('click', function(e){
								new Event(e).stop();
                        this.reestablece();
                    }.bind(this)
			);
			
    },
		
		resize: function(num){
			this.contenedor.effect('font-size',{duration:300,unit:'px'}).custom(num);	
			Cookie.set("letraTamano", this.num, {path: this.dominio}); 
		},
		
		compruebaMaxMin: function(){
			if(this.num==this.maximo) this.aumenta.setOpacity(0.4);
			else this.aumenta.setOpacity(1);
			
			if(this.num==this.minimo) this.disminuye.setOpacity(0.4);
			else this.disminuye.setOpacity(1);
		},
		
		dism: function(){
			if(this.num>this.minimo){
				this.num-=1; 
				this.compruebaMaxMin();
				this.resize(this.num); 	
			}
		},
		
		aum: function(){
			if(this.num<this.maximo){
				this.num+=1; 
				this.compruebaMaxMin();
				this.resize(this.num);	
			}
		},
		
		reestablece: function(){
			this.num = this.ini;
			this.resize(this.ini);
			Cookie.remove("letraTamano"); 
			this.compruebaMaxMin();
		}
		
});

/* -----------------------------------------------------------------------------
LOAD ---------------------------------------------------------------
----------------------------------------------------------------------------- */ 
window.addEvent('domready', inicia);
window.addEvent('load', marcador);