// JavaScript Document
var oProducto = new function(){
	var oEle = null;
	var iframe = null;
	var accion = "";
	//OBJs
	var req = new Request();
	var descargaFicha = null;
	
	req.listener = function(){
		var d = req.respuestaXML;
		switch(accion){
			case 'categoria':

				$('categoriaFichaLoader').style.display = 'none';
		
				if(!d) alert(req.respuestaHTML);
				//
	
				else $('prodLista').innerHTML = (Nav.esIE)? d.firstChild.text : d.firstChild.textContent;
			
			break;
			case 'cambiarPagina':

				this.loaderPagina.style.display = 'none';
		
				if(!d) alert(req.respuestaHTML);
				//
	
				else this.prodFicha.innerHTML = (Nav.esIE)? d.firstChild.text : d.firstChild.textContent;

			break;
			default :
				this.loader.style.display = 'none';
		
				if(!d) alert(req.respuestaHTML);
				//
				else{
					$('notas').innerHTML = (Nav.esIE)? d.firstChild.text : d.firstChild.textContent;
					$('galeria').innerHTML = (Nav.esIE)? d.childNodes[1].text : d.childNodes[1].textContent;
				}
				oTam = new agrandarLetra("bajadaNoticia,cuerpoNoticia",11, 2, 11, 20,"agrandar","achicar");			
			break;
			
		}

	}.closure(this);
	
	//METs
	var setEle = function(i){
		
		if(!!oEle){
			if(oEle.className == 'btnCatOn')oEle.className = 'btnCat';
			if(oEle.className == 'btnCatCProdOn')oEle.className = 'btnCatCProd';			
			else oEle.className = 'btnSCat';
		
		}
		oEle = $('categoriaProducto' + i);
		if(oEle){
			if(oEle.className == 'btnCat')oEle.className = 'btnCatOn';
			else if(oEle.className == 'btnCatCProd')oEle.className = 'btnCatCProdOn';
			else oEle.className = 'btnSCatOn';
		}
	}



	this.verCategorias = function(i, e,pagina){
		var o = null;
		setEle(i);
		//
		accion = "categoria";
		if(e == 'init') return true;
		//
		o = $('categoriaFichaLoader');
		o.style.height = o.style.lineHeight = o.parentNode.offsetHeight + 'px';
		o.style.width = o.style.lineWidth = o.parentNode.offsetWidth + 'px';

		o.style.display = 'block';
		
		var anex = "";
		if(pagina)anex = "&pagina="+pagina;
		req.pedir(URL_ROOT+'requests/cargar.php?idC='+i+anex, 'file|=|productos.php|&|');
		//
		if(e) StopEvent(e);
	}

	this.cambiarPaginas = function(i, e,pagina){
		setEle(i);

		//
		accion = "cambiarPagina";
		if(e == 'init') return true;
		//
		var loader = $('categoriaFichaLoader'+i);
		if(!loader){
			loader = $('categoriaFichaLoader');
			loader.style. height = loader.style.lineHeight = loader.parentNode.offsetHeight + 'px';
			loader.style.display = 'block';
		}
		else{ loader.style.display = 'inline'; }

		this.prodFicha = $('prodFicha'+i);
		if(!this.prodFicha)this.prodFicha = $('prodLista');

		
		this.loaderPagina = loader;
		this.elePag = i;
		var anex = "";
		if(pagina)anex = "&pagina="+pagina;
		req.pedir(URL_ROOT+'requests/cargar.php?idC='+i+anex, 'file|=|productosPaginados.php|&|');
		//
		if(e) StopEvent(e);
	}	
	
	this.verFichaCompleta = function(i,e){
		setEleFicha(i);
		accion = "ficha";
		if(e == 'init') return true;
		//
		$('FichaLoader').style.display = 'block';
		var anex = "";
		req.pedir(URL_ROOT+'requests/cargar.php', 'file|=|cargarHTMLNota.php|&|fileCargar|=|../noticias/' + i + 'Ficha.html|&|idRegistro|=|'+i+"|&|campoSesion|=|antSigNot|&|funcion|=|oProducto.verFichaCompleta|&|"+'file2|=|../noticias/' + i +'Galeria.html|&|');
		if($('flechaAnterior'))FireEvent($('flechaAnterior'),'mouseout');
		if($('flechaSiguiente'))FireEvent($('flechaSiguiente'),'mouseout');		
		//
		if(e) StopEvent(e);
	}

	this.antSig = function(o, i, e){
		if(e){ StopEvent(e); }
		
		oCookie.set('ind', i);
		document.location.href = o.href;
	}


	this.mostrarVideo = function(url,e){
		
		//'http://www.youtube.com/v/'+obj.codigo+'&rel=1&border=0'
		var p = new FlashObject(url, "videoDin", "356", "300", "8", "");
		p.addParam("contVideo","false");
		if(Nav.esIE){ p.addParam("wmode","opaque"); }
		p.write("contVideo");
		MostrarContenido($('contenedorVideo'));
		mostrarBlockeador(true);
		if(e)StopEvent(e);
	}
	this.ocultarVideo = function(e){
		$('contVideo').innerHTML = '';
		OcultarContenido($('contenedorVideo'));
		mostrarBlockeador();
		if(e)StopEvent(e);	
	}
	this.mostrarDescarga = function(e){

		MostrarContenido($('descargasFicha'));
		mostrarBlockeador(true);
		if(e)StopEvent(e);
		
	}
	this.cerrarCuadro = function(e){
		OcultarContenido($('descargasFicha'));
		mostrarBlockeador(false);
		StopEvent(e);
	}
	this.mostrarTrans = function(div){
		$(div).style.display = 'block';
	}
	this.ocultarTrans = function(div){
		$(div).style.display = 'none';
	}

	this.mostrarLetra = function(letra,e){
		if($(letra)){
			if($(letra).style.display != 'table-row'){
				$(letra).style.display = $('comodinPistas').style.display;				
			}
			else{
				$(letra).style.display = 'none';
			}
		}
		if(e)StopEvent(e);
	}
	
	
	this.reproducirMP3 = function(file,titulo,blur,idPista,e){
		
		this.iniciarReproductor();		
		if(idPista != oConfRep.pistaActual){

			if(oConfRep.pistaActual){
				$('lineaPista' + oConfRep.pistaActual).className = '';
				$('playPista' + oConfRep.pistaActual).className = 'btnPlay';
				$('playPista' + oConfRep.pistaActual).pausado = false;
			}
			oConfRep.pistaActual = idPista;
			$('lineaPista' + idPista).className = 'on';
			this.oReproductor.activarEventos();
			this.oReproductor.cargarArchivo(file,titulo,blur);
		}
		else{
			
			if($('playPista' + idPista).className == 'btnPause'){
				$('playPista' + idPista).className = 'btnPlay';
				$('playPista' + idPista).pausado = true;
				this.oReproductor.mPause();
			}
			else{
				this.oReproductor.mPlay();
				$('playPista' + idPista).pausado = false;
				$('playPista' + idPista).className = 'btnPause';				
			}

		}
	}
	
	this.iniciarReproductor = function(){
		if(!this.oReproductor){
			oConfRep = {
				getFlashObj: function(){
					
				if(!$('playPista' + this.pistaActual).pausado){
					$('playPista' + this.pistaActual).style.display = 'none';
					$('loaderPista' + this.pistaActual).style.display = 'block';
				}
					
					return swfobject.getObjectById("music_player2")
				},
				anteriorOn: function(){
					alert('anterior');
				},
				siguienteOn: function(){
					alert('siguiente');
				},
				soundLoaded: function(){
					if($('loaderPista' + this.pistaActual)){
						$('loaderPista' + this.pistaActual).style.display = 'none';
						$('playPista' + this.pistaActual).className = 'btnPause';
						$('playPista' + this.pistaActual).style.display = 'block';
					}
				}, 
				soundFalied: function(){
					//eventosLog('eventosLog','soundFalied');
				},
				soundComplete: function(){
					alert('completado');
				}
			}
			this.oReproductor = new Reproductor(oConfRep);
		}
	}
	
	var oConfRep = null;
	this.oReproductor = null;
	
	
}

