 	  	

	/*
	 * Clase campañas
	 * ---------------
	 *  - Almacena los datos de las noticias recibiendo un JSON a traves de PHP.
	 *  - Añade funcionalidades de visualizacion
	 * 
	 */
  
  	var Campana = new Class({
  		initialize : function(objeto){
  			this.id = objeto.id;
  			this.titulo = objeto.titulo;
  			this.cuerpo	= $ZVK.sinQuots(objeto.cuerpo);
  			this.fecha = objeto.fecha;
  			this.referencia = objeto.referencia;
  			if(objeto.foto){
  				this.foto = objeto.foto;
  				this.copy = objeto.copy;
  				}
  			this.categoria = objeto.categoria;
  			},
  		
  		extracto : function(){
			if(this.cuerpo.length<400){return this.cuerpo; }
			else { return this.cuerpo.substr(0,400)+'[...]';}
  			},
  			
  		verFecha : function(){
			var fecha = this.fecha;
			arrayfecha_hora= fecha.split(" ");
			arrafecha = arrayfecha_hora[0].split('-');
			
			ano = arrafecha[0];
			
			mes = arrafecha[1];
			if (mes[0]=='0') mes = mes[1];
			
			mes = arraymeses[mes];				
			dia = arrafecha[2];
			if (dia[0]=='0') dia = dia[1];
					
			fecha = dia+' de '+mes+' de '+ano;
			return fecha;
			}
  			
  		});
	
	
	/********************************************/
	/* Carga de datos							*/
	/*											*/
	
	arraycampanas = $ZVK.toJason(arraynoticias);
  	principal = new Campana(principal);
  	
  	
  	
  	/********************************************/
	/* On load									*/
	/*											*/
		
	window.addEvent('domready', function() {
		
		
		/* 
		 *  1 - Carga el listado de noticias en memoria 
		 *  2 - Despliega los accesos a las noticias anterios.
		 *  3 - Carga los comportamientos de lacciones Imprimir, ver listado y leer completa
		 * 
		 */

		/* -- 1 -- */
		if (principal.foto==null){
			$('foto_principal').setStyle('display','none');
		}
				
		
		
		/* -- 2 -- */
					 
		$$('#anteriores li a').addEvent('click',function(event){
				event.preventDefault();
				var id = this.getProperty('id');
				id = id.substr(4);
				var litem = this.getParent();
				principal = new Campana(arraycampanas[id]);
					$('fecha').innerHTML = principal.verFecha();
					$('categoria').innerHTML = principal.categoria;
				
				if (principal.foto==undefined){
						if($('foto_principal')!= null){$('foto_principal').setStyle('display','none')}
					} else {
						var estado = $('foto_principal').getStyle('display');
						if(estado=='none'){
							$('foto_principal').setStyle('display','block');
							}
						$('foto_principal').setProperty('src','img/news/'+principal.foto);
						}
					
				if (principal.copy==undefined){
						if($('copyright')!= null){$('copyright').setStyle('display','none')};
					} else {
						var estado = $('copyright').getStyle('display');
						if(estado=='none'){
							$('copyright').setStyle('display','block');
							}
						$('copyright').innerHTML = principal.copy;
						}
						
				if (principal.referencia==null||principal.referencia==""){
						$('webmas').setStyle('display','none');
						} else {
						$('webref').set('href',principal.referencia);
						$('webmas').setStyle('display','inline');
						}
					$('n1_titulo').innerHTML = principal.titulo;
					$('texto_des').innerHTML = principal.extracto();
					
					
					$ZVK.subir('noticia');
					$('leermas').innerHTML = 'Leer más';
					estado_leermas = true;
				});	
				
		/* -- 3 -- */
		
		$ZVK.leermas();
				
		$('listar').addEvent('click',function(event){
			event.preventDefault();
			$ZVK.subir('anteriores');
			});
			
		$('imprimir').addEvent('click',function(event){
			event.preventDefault();
			window.print();
			});
		
		$('webmas').addEvent('click',function(event){
			event.preventDefault();
			var ref =  this.get('href');
			var nueva = window.open(ref);
			});
		
		});