// JavaScript Document

function rnd() {
	return "&rnd=" + Math.random();
}


Effect.Transitions.slowstop = function(pos) {
  return 1-Math.pow(0.5,20*pos);
}

function scroll_up(theParent, theDiv, offLineHeight) {
	
	var olh = offLineHeight!=undefined ? offLineHeight : 15;

	theDiv = $(theDiv);
	theParent = $(theParent);
	var divTop = parseInt(theDiv.style.top)
	var divHeight = Element.getHeight(theDiv);
	
	var parentHeight = Element.getHeight(theParent);
	
	if((divTop) < 0) {
		new Effect.MoveBy(theDiv, parentHeight-olh, 0 , {duration: 0.3});
	}		
}

function scroll_down(theParent, theDiv, offLineHeight) {
	
	var olh = offLineHeight!=undefined ? offLineHeight : 15;
	
	theDiv = $(theDiv);
	theParent = $(theParent);	
	var divTop = parseInt(theDiv.style.top)
	var divHeight = Element.getHeight(theDiv);
	var parentHeight = Element.getHeight(theParent);

	if(divTop + (divHeight - parentHeight) > 0) {
		new Effect.MoveBy(theDiv, -(parentHeight-olh), 0 , {duration: 0.3});
	}
}

var current_zindex = 10;

var PanelManager = Class.create();
PanelManager.prototype = {
	initialize: function() {
		this.czIndex = 10;
		this.panels = new Hash();
	},
	addPanel: function (main_div, panel_div, direction) {
		var nPanel = new Panel(this, main_div, panel_div, direction);
		this.panels[main_div] = nPanel;
	},
	closeAll: function () {
		this.panels.each(
			function(p) {
				if(!p.value.collapsed) {
					p.value.close();
				}
			});
	}
}
var pm = new PanelManager();

var Panel = Class.create();
Panel.prototype = {
	initialize: function (panel_manager, main_div, panel_div, direction) {
		this.name = main_div;
		this.manager = panel_manager;
		this.main_div = $(main_div);
		this.panel_div = $(panel_div);
		this.tgt_pos = direction * (Element.getWidth(this.panel_div));
		this.direction = direction;
		this.collapsed = true;
		
	},
	toFront: function () {
		this.main_div.style.zIndex = ++this.manager.czIndex;
	},
	open: function () {
		if(!this.collapsed) { return false }
		this.toFront();	
		this.manager.closeAll();
		this.collapsed = false;
		new Effect.Move(this.panel_div, { x: this.tgt_pos, y:3 , mode: 'absolute'});
	},
	close: function () {
		this.collapsed = true;
		//Element.setStyle(this.panel_div, {left:'0px', top: '0px'});
		new Effect.Move(this.panel_div,{ x:0, y:3 , mode: 'absolute'});
	}
	
}


// paginas estaticas
function show_static_right(page) {
	$('right_content_content').hide();
	$('right_content_content').innerHTML="";
	$('right_content_loading').show();
	pm.panels['right'].open();
	
	var url = "pages/"+page+".php";
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('right_content_loading').hide();			
			$('right_content_content').innerHTML=req.responseText;
			$('right_content_content').show();
		 }
 	}; 	
	new Ajax.Request(url, args);
}

function show_static_left(page) {
	$('left_overlay').style.height= '680px';
	$('left_content_content').hide();
	$('left_content_content').innerHTML="";
	$('left_content_loading').show();
	pm.panels['left'].open();
	
	var url = "pages2/"+page+".php?rnd=" + Math.random();
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('left_content_loading').hide();			
			$('left_overlay').style.height= '54px';
			$('left_content_content').innerHTML=req.responseText;
			$('left_content_content').show();
		 }
 	}; 	
	new Ajax.Request(url, args);
}

function close_popups() {
	$('popups').hide();
	$('popup_contenido').innerHTML = "";
}

// -- trailer -- //
function ver_trailer() {
	check_plugins();
	var url = "pages2/ver_trailer.php?";
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('popup_contenido').innerHTML = req.responseText;
			ver_trailer_cb();
		 }
 	}; 	
	new Ajax.Request(url, args);	
}


function ver_trailer_cb(id) {
	
	$('player2').innerHTML = "";
	if(id==undefined) {id=10}
	
	var so = new SWFObject("video/flvplayer.swf", "player", "400", "290", "9", "#FFFFFF");
	so.addParam("allowfullscreen","true");
	so.addVariable("file","../video/trailer_"+id+".flv");
	so.addVariable("autostart","true");
	so.addVariable("backcolor","0x000000");
	so.addVariable("frontcolor","0xCCCCCC");
	so.addVariable("lightcolor","0x557722");
	so.addParam("wmode", "opaque");	

	so.write("player2");	

	$('popups').show();	
}

function show_galeria() {
	var url = "pages2/galeria.php?";
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('popup_contenido').innerHTML = req.responseText;
			$('popups').show();	
		 }
 	}; 	
	new Ajax.Request(url, args);	
}

function show_musica() {
	var url = "pages2/musica.php?";
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('popup_contenido').innerHTML = req.responseText;
			$('popups').show();	
		 }
 	}; 	
	new Ajax.Request(url, args);	
}

var mp3on= false;
var currentmp3='';
function playmp3(file,id) {
	
	$('mp3player').innerHTML = "";
	if(mp3on && currentmp3==id) {
		mp3on = false;
		return false;
	}
	mp3on = true;
	currentmp3 = id;
	
	var so = new SWFObject("video/flvplayer.swf", "player", "200", "20", "9", "#FFFFFF");
	so.addParam("allowfullscreen","true");
	so.addVariable("file","musica/"+ file);
	so.addVariable("autostart","true");
	so.addParam("wmode", "opaque");	

	so.write("mp3player");	
}
// -- registracion -- //
function show_registrarse() {
	$('right_content_content').hide();
	$('right_content_content').innerHTML="";
	$('right_content_loading').show();
	pm.panels['right'].open();
	
	var url = "pages/registrarse.php";
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('right_content_loading').hide();			
			$('right_content_content').innerHTML=req.responseText;
			//$('right_content_content').show();
			new Effect.Appear('right_content_content');
			//new Effect.Fade($('right_content_content'), {duration:1});
		 }
 	};
	new Ajax.Request(url, args);
}

function toogle(chk, npt) {
	$(npt).value = $F(npt)==0 ? 1 : 0;
	chk.className = $F(npt)==1 ? "chk_red" : "chk_unchecked";
}

arr_como = new Array('como_1','como_2','como_3','como_4','como_5','como_6','como_7')
function set_como(chk, value) {
	
	for (var i = 0; i < arr_como.length; i++) {
		$(arr_como[i]).className  = "chk_unchecked";
	}
	$('enteraste').value = value;
	chk.className = "chk_red"
}

function registrarse() {
	if(!validar_registro()) {return false}
	
	if($F('mexicano')==1) {$('nacionalidad').value= 'mexicano'; }
	
	var frm = $('frm_registrarse');
	frm.request({
				onComplete: function (req) {
					//alert(req.responseText);
					var obj = req.responseText.evalJSON();
					if(obj.has_errors==1) {
						alert( obj.message);
					} else {
						alert("Se te ha enviado un email para confirmar la inscripcion");
						pm.panels['right'].close();
					}
				}
			});

}

function validar_registro() {
	sv.reset();
	sv.required('nombre',"Debes completar tu nombre");
	sv.required('apellido',"Debes completar tu apellido")
	sv.test(function() {return $('nacionalidad').value == "" && $('mexicano').value == 0}, 'nacionalidad',"Debes completar tu nacionalidad")
	sv.required('estado',"Debes completar tu estado")
	sv.required('pais',"Debes completar tu pais de residencia")
	sv.numbers('edad',"Debes completar  tu edad")
	sv.email('mail', "Debes proporcionar un email válido");
	sv.required('enteraste',"Debes completar como te enteraste");

	if(sv.hasErrors()) {alert(sv.getErrors())}

	return !sv.hasErrors();
}


// -- login -- //
function login(ntp) {
	
	var pars = "mail="+ $F(ntp) + rnd();
	new Ajax.Request("funciones/login.php",{parameters:pars, method:'post',
					 onComplete:function(req) {
						 //alert(req.responseText)
						 var jsn = req.responseText.evalJSON();
						 if(jsn.has_errors) {
							 alert(jsn.message);
						 } else {
							 $('username').innerHTML = jsn.usuario;
							 $('logout').show();
							 if(jsn.prev_req){eval(jsn.prev_req)(); return false}
							 document.location.replace("index.php");
						 }
					 }});
}

function show_login() {
	$('right_content_content').hide();
	$('right_content_content').innerHTML="";
	$('right_content_loading').show();
	pm.panels['right'].open();
	
	var url = "pages/login.php";
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('right_content_loading').hide();			
			$('right_content_content').innerHTML=req.responseText;
			$('right_content_content').show();
		 }
 	}; 	
	new Ajax.Request(url, args);
}


// -- upload corto -- //
function subir_corto() {
	$('right_content_content').hide();
	$('right_content_content').innerHTML="";
	$('right_content_loading').show();
	pm.panels['right'].open();
	
	var url = "pages/inscribir_corto.php";
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('right_content_loading').hide();			
			$('right_content_content').innerHTML=req.responseText;
			$('right_content_content').show();
		 }
 	}; 	
	new Ajax.Request(url, args);
}

function update_name() {
	var nfile = $F('archivo');
	var arr_file = nfile.split("\\");
	if(arr_file.length==1) {
		var arr_file = nfile.split("/");
	}
	$('file_show').innerHTML = arr_file[arr_file.length-1];
}

function validar_corto() {
	sv.reset();
	sv.required('titulo',"Debes completar el titulo del corto");
	sv.required('anio',"Debes completar el año de realización")
	sv.required('duracion',"Debes completar la duración del corto")
	//sv.required('sinopsis',"Debes completar la sinopsis")
	sv.required('formato',"Debes completar el formato del corto")
	sv.required('archivo', "Debes elegir un archivo para enviar");
	sv.extension('archivo', new Array('.avi', '.mpg', '.mov', '.jpg'), "El archivo debe tener extensión mov, avi o mpg");

	if(sv.hasErrors()) {alert(sv.getErrors()); return false;}
	$('acuerdo_enviar').hide();
	mostrar_acuerdo();
	
}

function mostrar_acuerdo() {
	var url = "pages/acuerdo.php?corto=" + $F('titulo') + rnd();
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('popup_contenido').innerHTML = req.responseText;
			$('popups').show();
		 }
 	}; 	
	new Ajax.Request(url, args);	
}
arr_acuerdo = new Array('acuerdo_si','acuerdo_no')

function set_acuerdo(chk, value) {
	
	for (var i = 0; i < arr_acuerdo.length; i++) {
		$(arr_acuerdo[i]).className  = "chk_unchecked";
	}
	$('acuerdo_accept').value = value;
	chk.className = "chk_black"
}

function acuerdo_continuar() {
	$('acuerdo_continuar').hide();
	if($F('acuerdo_accept') == 'si') {upload_corto(); return false}
	$('acuerdo_enviar').show();
	$('popups').hide();
}

function upload_corto() {
		$('acuerdo_aceptar').hide();
		$('acuerdo_subiendo').show();
		//$('popups').hide();
		var frm = $('frm_inscribir_corto');
		frm.target = "corto_upload_iframe";
		frm.submit();		
}
	
function onClipUpload(flg) {
	
	if(flg!="1") {
		$('popups').hide();
		alert("Caramba!!! hubo un problema con tu corto.\nPor favor, revisa que no exceda los 90MB");
		return false;
	}
	//alert(flg);
	var url = "http://www.elviajedelanonna.com/pages/corto_uploaded.php";
	//var url = "http://192.168.2.2:8078/pages/corto_uploaded.php";
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('right_content_content').innerHTML=req.responseText;
			$('right_content_content').show();
			$('popups').hide();
		 }
	}; 	
	var aj = new Ajax.Request(url, args);
	// agregar 
}


// -- tu cuenta -- //
function show_cuenta() {
	$('right_content_content').hide();
	$('right_content_content').innerHTML="";
	$('right_content_loading').show();
	pm.panels['right'].open();
	
	var url = "pages/tu_cuenta.php";
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('right_content_loading').hide();			
			$('right_content_content').innerHTML=req.responseText;
			$('right_content_content').show();
		 }
 	}; 	
	new Ajax.Request(url, args);
}

function show_tus_cortos() {
	$('right_content_content').hide();
	$('right_content_content').innerHTML="";
	$('right_content_loading').show();
	pm.panels['right'].open();
	
	var url = "pages/tu_cuenta_cortos.php";
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('right_content_loading').hide();			
			$('right_content_content').innerHTML=req.responseText;
			$('right_content_content').show();
		 }
 	}; 	
	new Ajax.Request(url, args);
}

function invitar_corto(id) {
	alert("Se ha enviado un email a todos tus contactos\ninvitándolos a ver tu corto.\n\nRecuerda que cuantos más invitados tengas\nmás posibilidades tienes de ganar")
	var url = "funciones/invitacion_corto_fn.php?id="+id;
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
		 }
 	}; 	
	new Ajax.Request(url, args);	
}

function recomendar_corto(id) {
	alert("Se ha enviado un email a todos tus contactos\ninvitándolos a ver este corto.")
	var url = "funciones/recomendar_corto_fn.php?id="+id;
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
		 }
 	}; 	
	new Ajax.Request(url, args);	
}

function show_tus_invitados() {
	$('right_content_content').hide();
	$('right_content_content').innerHTML="";
	$('right_content_loading').show();
	pm.panels['right'].open();
	
	var url = "pages/tu_cuenta_invitados.php";
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('right_content_loading').hide();			
			$('right_content_content').innerHTML=req.responseText;
			$('right_content_content').show();
		 }
 	}; 	
	new Ajax.Request(url, args);
}

function show_tus_favoritos() {
	$('right_content_content').hide();
	$('right_content_content').innerHTML="";
	$('right_content_loading').show();
	pm.panels['right'].open();
	
	var url = "pages/tu_cuenta_favoritos.php";
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('right_content_loading').hide();			
			$('right_content_content').innerHTML=req.responseText;
			$('right_content_content').show();
		 }
 	}; 	
	new Ajax.Request(url, args);
}

function invitado_agregar() {
	sv.reset();
	sv.required('invitado_name',"Debes completar el nombre de tu invitado");
	sv.email('invitado_email', "Debes proporcionar un email válido");

	if(sv.hasErrors()) {alert(sv.getErrors()); return false;}	
	
	
	var pars = "nombre=" + $F('invitado_name') + "&email=" + $F('invitado_email') + rnd();
	
	$('right_content_content').hide();
	$('right_content_content').innerHTML="";
	$('right_content_loading').show();
	
	var url = "funciones/invitacion_fn.php";
	var args = {
		parameters: pars,
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('right_content_loading').hide();			
			$('right_content_content').innerHTML=req.responseText;
			$('right_content_content').show();
		 }
 	}; 	
	new Ajax.Request(url, args);	
}

function invitado_quitar(id, nombre) {
	
	if(!confirm("Estás seguro de que quieres quitar a " + nombre + " de tu lista de invitados?")) {
		return false;
	}
	
	
	var pars = "id_related=" + id + rnd();
	
	$('right_content_content').hide();
	$('right_content_content').innerHTML="";
	$('right_content_loading').show();
	
	//alert(pars);
	//return false;
	
	var url = "funciones/invitacion_del_fn.php";
	var args = {
		parameters: pars,
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('right_content_loading').hide();			
			$('right_content_content').innerHTML=req.responseText;
			$('right_content_content').show();
		 }
 	}; 	
	new Ajax.Request(url, args);	
}

// -- clip play -- //
function ver_clip(id) {
	check_plugins();
	var url = "pages/ver_clips.php?id_clip=" + id + rnd();
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('popup_contenido').innerHTML = req.responseText;
			ver_clip_cb(id);
		 }
 	}; 	
	new Ajax.Request(url, args);	
	
}

function ver_clip_cb(id) {

	//var so = new SWFObject("http://192.168.2.2:8078/video/player.swf", "player", "400", "340", "9", "#FFFFFF");
	var so = new SWFObject("video/flvplayer.swf", "player", "320", "240", "9", "#FFFFFF");
	so.addParam("allowfullscreen","true");
	so.addVariable("file","../video/vid_"+ id + ".flv");
	so.addVariable("image","video/pica_"+id+".jpg");
	so.addVariable("backcolor","0x000000");
	so.addVariable("frontcolor","0xCCCCCC");
	so.addVariable("lightcolor","0x557722");
	so.addParam("wmode", "transparent");	

	so.write("player");	

	$('popups').show();	
}
function ver_clip2(id) {
	
	var url = "pages/ver_clips2.php?id_clip=" + id + rnd();
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('popup_contenido').innerHTML = req.responseText;
			$('popups').show();
			//ver_clip_cb(id);
		 }
 	}; 	
	new Ajax.Request(url, args);	
	
}

function agregar_favorito(id) {
	var flg = eval($('cuenta_favoritos'));
	if(flg) { // nos aseguramos que haya que refrescar
		$('right_content_content').hide();
		$('right_content_content').innerHTML="";
		$('right_content_loading').show();
	}
	
	var url = "funciones/agregar_favorito_fn.php?id_clip=" + id + rnd();
	
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			if(flg) {
				$('right_content_loading').hide();
				$('right_content_content').innerHTML=req.responseText;
				$('right_content_content').show();
			}
			alert("Este corto se ha agregado a tus favoritos en Tú Cuenta");
		 }
 	};
	new Ajax.Request(url, args);	
}

function remover_favorito(id) {
	
	if(!confirm("¿Estás seguro de quitar este corto de tus favoritos?")) {return false;}
	$('right_content_content').hide();
	$('right_content_content').innerHTML="";
	$('right_content_loading').show();
	
	var url = "funciones/remover_favorito_fn.php?id_clip=" + id + rnd();
	
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('right_content_loading').hide();			
			$('right_content_content').innerHTML=req.responseText;
			$('right_content_content').show();
		 }
 	};
	new Ajax.Request(url, args);	
}

function votar_corto(cid, uid) {
	if(!confirm("Estás seguro de que quieres votar por este corto?\nRecuerda que sólo puedes votar una vez!")) {return false;}
	
	$('btn_votar').hide();
	var url = "funciones/votar_fn.php?cid=" + cid + "&uid=" + uid + rnd();
	
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			var obj = req.responseText.evalJSON();
			alert(obj.message);
		 }
 	}; 	
	new Ajax.Request(url, args);	
}

function send_invitacion_clip(id_clip) {
	
}


// -- compartir sitio --//
function compartir_sitio() {
	var url = "pages/compartir_sitio.php?";
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('popup_contenido').innerHTML = req.responseText;
			$('popups').show();
		 }
 	}; 	
	new Ajax.Request(url, args);
}

function enviar_compartir() {
	sv.reset();
	sv.required('nombre',"Debes completar el nombre de tu invitado");
	sv.email('mail', "Debes proporcionar un email válido");
	sv.required('host',"Debes completar tu nombre");
	
	if(sv.hasErrors()) {alert(sv.getErrors()); return false}
	
	var frm = $('frm_compartir');
	frm.request({
				onComplete: function (req) {
					//alert(req.responseText);
					$('popups').hide();
				}
			});	
}

// -- busquedas -- //
function show_busqueda(bus) {
	
	$('right_content_content').hide();
	$('right_content_content').innerHTML="";
	$('right_content_loading').show();
	pm.panels['right'].open();
	
	var url = "pages/resultado_busqueda.php";
	var args = {
		method: 'post',
		parameters: 'txt='+bus+rnd(),
		onComplete: function (req) {
			//alert(req.responseText);
			$('right_content_loading').hide();			
			$('right_content_content').innerHTML=req.responseText;
			$('right_content_content').show();
		 }
 	}; 	
	new Ajax.Request(url, args);
}

function cortos_por(page, letra) {
	
	$('right_content_content').hide();
	$('right_content_content').innerHTML="";
	$('right_content_loading').show();
	pm.panels['right'].open();
	
	var url = "pages/por_parametros.php";
	var args = {
		method: 'post',
		parameters: 'page='+ page + "&letra="+ letra + rnd(),
		onComplete: function (req) {
			//alert(req.responseText);
			$('right_content_loading').hide();			
			$('right_content_content').innerHTML=req.responseText;
			$('right_content_content').show();
		 }
 	}; 	
	new Ajax.Request(url, args);	
}

function check_plugins() {
	var userAgent = navigator.userAgent.toLowerCase();
	if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
		document.location.href = "plugins.php";
	}	
	  
	if(deconcept.SWFObjectUtil.getPlayerVersion().major < 9) {
		document.location.href = "plugins.php";
	}
	
}


var gal_min = 1;
var gal_max = 16;
var gal_current = 1;

function gal_left() {
	id = Math.max(gal_min, gal_current-1);
	zoompic(id);
}

function gal_right() {
	id = Math.min(gal_max, gal_current+1);
	zoompic(id);
}
	
function zoompic(id) {
	gal_current = id;
	$('gal_down2').href = "funciones/download_file.php?folder=/fotos/200_dpi/&file=foto"+id+".jpg";
	var pic = $('gal_pic');
	pic.style.display = "none";
	pic.onload = function () {pic.style.display = "";}
	pic.src = "fotos/72_dpi/foto"+id+"_72.jpg";
	$('gal_show').style.display = "block";
}

var dragging_id = 0;
function show_votar() {
	var url = "pages/votar.php?";
	var args = {
		method: 'post',
		onComplete: function (req) {
			
			if(req.responseText == "not_logged_in") {
				show_login();
				return false;	
			}
			//alert(req.responseText);
			$('popup_contenido').innerHTML = req.responseText;
			var dg = null; 
			
			//dg = new Draggable($('div_draggable'),{revert:true, onEnd:function() {}});
			//alert($('drop_1'));
			Droppables.add('drop_1', {accept: "div_dg",hoverclass:'votar_hover', onDrop:function(el) {
					//alert("hola");
					$('pic_1').src = $('votar_pic_' + dragging_id).src;
					$('titulo_1').innerHTML = $('votar_titulo_' + dragging_id).innerHTML;
					$('autor_1').innerHTML = $('votar_participante_' + dragging_id).innerHTML;
					$('voto_1').value = dragging_id;
				}
			});
			
			Droppables.add('drop_2', {accept: "div_dg",hoverclass:'votar_hover', onDrop:function(el) {
					//alert("hola");
					$('pic_2').src = $('votar_pic_' + dragging_id).src;
					$('titulo_2').innerHTML = $('votar_titulo_' + dragging_id).innerHTML;
					$('autor_2').innerHTML = $('votar_participante_' + dragging_id).innerHTML;
					$('voto_2').value = dragging_id;
				}
			});
			
			Droppables.add('drop_3', {accept: "div_dg",hoverclass:'votar_hover', onDrop:function(el) {
					//alert("hola");
					$('pic_3').src = $('votar_pic_' + dragging_id).src;
					$('titulo_3').innerHTML = $('votar_titulo_' + dragging_id).innerHTML;
					$('autor_3').innerHTML = $('votar_participante_' + dragging_id).innerHTML;
					$('voto_3').value = dragging_id;
				}
			});			
			
			
			var votables = $$(".votable");
			votables.each(function(el) {
				Event.observe(el, "mousedown", function(ev) {
					dragging_id = el.id;
					$('div_draggable').update(el.cloneNode(true))
					$('div_draggable').clonePosition(el);
					$('div_draggable').show();
					
					dg = new Draggable($('div_draggable'),{revert:true, onEnd:function() {$('div_draggable').update(); $('div_draggable').hide()}});
					//alert(ev);
					dg.initDrag(ev);
					}			  
				)

			})
 
			$('popups').show();	
		 }
 	}; 	
	new Ajax.Request(url, args);	
}

function votar() {

	var v1 = $("voto_1").value;
	var v2 = $("voto_2").value;
	var v3 = $("voto_3").value;	
	
	if (v1==0 || v2==0 || v3==0) {
		if(!confirm("No has votado por 3 candidatos.\n Puedes dejar puestos vacantes pero\n ¿Estás seguro de que deseas esto?")) {
			return false;	
		}
	}
	
	if ((v1==v2 && v1!=0) || (v2==v3 && v2!=0) || (v3==v1 && v3!=0)) {
		alert("Debes votar por diferentes clips para cada puesto");
		return false;
	}
	
	if(!confirm("SEGURISIMO??????\nMEDITALO, RECUERDA QUE NO PUEDES CAMBIAR TU VOTO.")) {return false}
	
	$('popups').hide();
	
	var frm = $('frm_votar');
	frm.action = "funciones/votar_fn.php";
	frm.request({
		onComplete: function (req) {
			var obj = req.responseText.evalJSON();
			alert(obj.message);
		}
	})
	
}

function limpiar_voto() {
	new Ajax.Request("funciones/limpiar_voto.php", {onComplete:function() {alert("OK")}});
}

function ver_cartelera() {
	check_plugins();
	var url = "pages2/cartelera.php?"+ rnd();
	var args = {
		method: 'post',
		onComplete: function (req) {
			//alert(req.responseText);
			$('popup_contenido').innerHTML = req.responseText;
			$('popups').show();	
		 }
 	}; 	
	new Ajax.Request(url, args);	
	
}