var oVideo = new function Video(){
	//PROPs
	var eBg = $('videoBg');
	var eBgLoad = $('videoBgLoad');
	var ePrev = $('videoPrev');
	var eLoad = $('videoLoad');
	var eEpi = $('videoEpi');
	var eInfo = $('videoInfo');
	var eVerEpi = $('videoVerEpi');
	var eCerrar = $('videoCerrar');
	//
	var eVotCont = $('videoVotCont');
	var eEst = $('videoEst');
	var eVot = $('videoVot');
	var eEst1 = $('videoEst1');
	var eEst2 = $('videoEst2');
	var eEst3 = $('videoEst3');
	var eEst4 = $('videoEst4');
	var eEst5 = $('videoEst5');
	var eRatCont = $('videoVotRating');
	var eRatTxt = $('videoVotRatTxt');
	//
	var bOpen = false;
	var eDoc = null;
	var eDivAct = null;
	var wVideo = 425;
	var hVideo = 366;
	var iTime = 0;
	//
	var bVerEpi = false;
	var iIdVideo = 0;
	var sAction = '';
	var oInfoVideo = null;
	var bReady = true;
	var bVotAct = false;
	
	
	//OBJs
	var req = new Request();
	
	
	//METs
	this.abrir = function(id, e){
		bOpen = true;
		if(!!e) StopEvent(e);
		//
		AddEvent(window, 'resize', this.acomodar);
		AddEvent(window, 'scroll', this.acomodar);
		//
		this.acomodar();
		//
		eLoad.style.display = ePrev.style.display = eCerrar.style.display = eBg.style.display = eBgLoad.style.display = 'block';//eVerEpi.style.display = 
		//
		this.cargar(id);
	}.closure(this);
	
	this.cerrar = function(){
		bOpen = false;
		RemEvent(window, 'resize', this.acomodar);
		RemEvent(window, 'scroll', this.acomodar);
		
		ePrev.style.display = eCerrar.style.display = eBg.style.display = eLoad.style.display = eBgLoad.style.display = 'none';//eVerEpi.style.display = 
		this.verVotacion(false);
		
		eDoc = oInfoVideo = null;
		iIdVideo = 0;
		ePrev.innerHTML = '';
	}.closure(this);
	
	this.acomodar = function(){
		ePrev.style.top = (Math.floor((HScreen() - hVideo) / 2) + YPos()) + 'px';
		eBgLoad.style.top = (Math.floor((HScreen() - parseInt(eBgLoad.style.height)) / 2) + YPos()) + 'px';
		eBg.style.top = YPos() + 'px';
		//eVerEpi.style.top = (Math.floor(HScreen() / 2) + YPos()) + 'px';
		eLoad.style.top = (Math.floor((HScreen() - 98) / 2) + YPos()) + 'px';
		eCerrar.style.top = (YPos() + 8) + 'px';
		//
		ePrev.style.left = (Math.floor((WScreen() - wVideo) / 2) + XPos()) + 'px';
		eBgLoad.style.left = (Math.floor((WScreen() - parseInt(eBgLoad.style.width)) / 2) + XPos()) + 'px';
		eBg.style.left = XPos() + 'px';
		//eVerEpi.style.left = (8 +  XPos()) + 'px';
		eLoad.style.left = (Math.floor(WScreen() / 2) + XPos() - 107 + ((Nav.esIE || Nav.esSa)? 50 : 40)) + 'px';
		eCerrar.style.left = (WScreen() + XPos() - ((Nav.esIE || Nav.esSa)? 40 : 56)) + 'px';
		//
		eBg.style.height = HScreen() + 'px';
		//
		this.verVotacion(true);
	}.closure(this);
	
	this.cargar = function(id){
		if(!bReady) return false;
		bReady = false;
		
		sAction = 'cargar';
		iIdVideo = id;
		req.pedir('requests/infoVideo.php', 'id|=|'+iIdVideo+'|&|', 'POST');
	};
	//acciones
	this.verEpigrafe = function(e){
		if(!!e){
			if(bVerEpi){
				bVerEpi = false;
				eVerEpi.className = '';
			}
			else{
				bVerEpi = true;
				eVerEpi.className = 'videoOcuEpi';
			}
		}
		
		if(bVerEpi && eEpi.firstChild.innerHTML != '') eEpi.style.display = (Nav.esIE || Nav.esOp)? 'inline-block' : '-moz-inline-box';
		else eEpi.style.display = 'none';
	}.closure(this);
	//votacion
	this.buscarVotacion = function(){
		if(!bReady) return false;
		bReady = false;
		
		eVotCont.style.display = 'none';
		sAction = 'imgInfo';
		oInfoVideo = null;
		req.pedir('requests/infoImagen.php', 'id' + '|=|' + iIdVideo + '|&|', 'POST');
	}
	
	this.verVotacion = function(si, mousemove){
		if(!bVotAct) return false;
		
		if(si == true && oInfoVideo != null){
			if(!mousemove){
				eVotCont.style.top = (Math.floor((HScreen() - hVideo) / 2) + 10 + YPos()) + 'px';
				eVotCont.style.left = (Math.floor((WScreen() - wVideo) / 2) + wVideo - ((Nav.esOp)? 150 : 135)) + 'px';
				//
				eEst.style.width = ((oInfoVideo['v'] > 0)? (Math.round((oInfoVideo['p'] / oInfoVideo['v']) * 20)) : '0') + '%';
				eVot.innerHTML = oInfoVideo['s'];
				eRatTxt.innerHTML = (oInfoVideo['v'] > 0)? (oInfoVideo['p'] / oInfoVideo['v']).toString().replace('.',',').substr(0, 4) : 0;
			}
			//
			if(bVerEpi){
				//eEpi.firstChild.style.paddingRight = '125px';
				//if(Nav.esIE6) eEpi.style.width = (wVideo - 120 - ((Nav.esIE6)? 15 : 4)) + 'px';
			}
			//
			eVotCont.style.display = 'block';
		}
		else{
			eVotCont.style.display = 'none';
			//eEpi.firstChild.style.paddingRight = '';
			//if(Nav.esIE6 && wVideo > 0) eEpi.style.width = (wVideo - ((Nav.esIE6)? 15 : 4)) + 'px';
		}
	}
	
	this.dejarVotar = function(){
		if(oInfoVideo && oInfoVideo['c'] == 0){
			eEst.parentNode.style.display = 'none';
			eEst1.parentNode.style.display = 'block';
		}
		this.verRating(true);
	}.closure(this);
	
	this.verEstrellas = function(){
		eEst1.parentNode.style.display = 'none';
		eEst.parentNode.style.display = 'block';
		eEst.style.width = eEst.style.width;
		this.verRating(false);
	}.closure(this);;
	
	this.pintarEstrellas = function(i){
		if(Nav.esIE6){
			if(i > 0) eEst1.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=img/galeria/estrellaOn.png,sizingMethod=scale)';
			else eEst1.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=img/galeria/estrellaOff.png,sizingMethod=scale)';
			if(i > 1) eEst2.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=img/galeria/estrellaOn.png,sizingMethod=scale)';
			else eEst2.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=img/galeria/estrellaOff.png,sizingMethod=scale)';
			if(i > 2) eEst3.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=img/galeria/estrellaOn.png,sizingMethod=scale)';
			else eEst3.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=img/galeria/estrellaOff.png,sizingMethod=scale)';
			if(i > 3) eEst4.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=img/galeria/estrellaOn.png,sizingMethod=scale)';
			else eEst4.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=img/galeria/estrellaOff.png,sizingMethod=scale)';
			if(i > 4) eEst5.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=img/galeria/estrellaOn.png,sizingMethod=scale)';
			else eEst5.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=img/galeria/estrellaOff.png,sizingMethod=scale)';
		}
		else{
			if(i > 0) eEst1.style.backgroundImage = 'url(img/galeria/estrellaOn.png)';
			else eEst1.style.backgroundImage = 'url(img/galeria/estrellaOff.png)';
			if(i > 1) eEst2.style.backgroundImage = 'url(img/galeria/estrellaOn.png)';
			else eEst2.style.backgroundImage = 'url(img/galeria/estrellaOff.png)';
			if(i > 2) eEst3.style.backgroundImage = 'url(img/galeria/estrellaOn.png)';
			else eEst3.style.backgroundImage = 'url(img/galeria/estrellaOff.png)';
			if(i > 3) eEst4.style.backgroundImage = 'url(img/galeria/estrellaOn.png)';
			else eEst4.style.backgroundImage = 'url(img/galeria/estrellaOff.png)';
			if(i > 4) eEst5.style.backgroundImage = 'url(img/galeria/estrellaOn.png)';
			else eEst5.style.backgroundImage = 'url(img/galeria/estrellaOff.png)';
		}
	}
	
	this.votar = function(p){
		if(!bReady) return false;
		bReady = false;
		this.verRating(false);
		
		eVotCont.style.display = 'none';
		sAction = 'imgInfo';
		req.pedir('requests/votarVideo.php', 'id' + '|=|' + iIdVideo + '|&|' + 'pts' + '|=|' + p + '|&|', 'POST');
	}
	
	this.verRating = function(si){
		if(si === true) eRatCont.style.display = 'block';
		else eRatCont.style.display = 'none';
	}
	
	this.activarVotacion = function(){
		bVotAct = true;
	}
	
	
	//EVENTs
	AddEvent(eCerrar, 'click', this.cerrar);
	AddEvent(eVerEpi, 'click', this.verEpigrafe);
	//
	req.listener = function(){
		var d = req.respuestaXML, o = null, p = null;
		bReady = true;
		//
		if(!d) alert(req.respuestaHTML);
		//
		else{
			if(sAction == 'cargar'){
				p = new FlashObject((Nav.esIE)? d.firstChild.text : d.firstChild.textContent, "videoObj", wVideo, hVideo, "5", "#000000");
				p.addParam("menu","false");
				p.addParam("wmode","transparent");
				p.write(ePrev.id);
			}
			
			o = new Object;
			o['v'] = parseInt(d.getAttribute('v'));
			o['p'] = parseInt(d.getAttribute('p'));
			o['s'] = d.getAttribute('s');
			o['c'] = parseInt(d.getAttribute('c'));
			oInfoVideo = o;
			
			if(bOpen) this.verVotacion(true);
			o = p = null;
		}
		//
	}.closure(this);
	//
	AddEvent(eEst.parentNode, 'mouseover', this.dejarVotar);
	AddEvent(eEst1.parentNode, 'mouseover', this.dejarVotar);
	AddEvent(eEst1, 'mouseover', this.dejarVotar);
	AddEvent(eEst2, 'mouseover', this.dejarVotar);
	AddEvent(eEst3, 'mouseover', this.dejarVotar);
	AddEvent(eEst4, 'mouseover', this.dejarVotar);
	AddEvent(eEst5, 'mouseover', this.dejarVotar);
	AddEvent(eEst1.parentNode, 'mouseout', this.verEstrellas);
	AddEvent(eEst.parentNode, 'mouseout', this.verEstrellas);
	//
	AddEvent(eEst1, 'mouseover', function(){ this.pintarEstrellas(1); }.closure(this));
	AddEvent(eEst2, 'mouseover', function(){ this.pintarEstrellas(2); }.closure(this));
	AddEvent(eEst3, 'mouseover', function(){ this.pintarEstrellas(3); }.closure(this));
	AddEvent(eEst4, 'mouseover', function(){ this.pintarEstrellas(4); }.closure(this));
	AddEvent(eEst5, 'mouseover', function(){ this.pintarEstrellas(5); }.closure(this));
	//
	AddEvent(eEst1, 'click', function(){ this.votar(1); }.closure(this));
	AddEvent(eEst2, 'click', function(){ this.votar(2); }.closure(this));
	AddEvent(eEst3, 'click', function(){ this.votar(3); }.closure(this));
	AddEvent(eEst4, 'click', function(){ this.votar(4); }.closure(this));
	AddEvent(eEst5, 'click', function(){ this.votar(5); }.closure(this));
	
}
