function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


var live=4;

function live_more(limit){
	old=live-4;
	live++;	
	$('live_'+old).hide();
	$('live_'+(live-1)).show();
	if(live>4)
		$('flecha_iz').show();
	
	if(live==limit)
		$('flecha_de').hide();
}

function live_less(limit){
	old=live;
	live--;
	
	$('live_'+(old-1)).hide();
	$('live_'+(live-4)).show();
	if(live<=4)
		$('flecha_iz').hide();
	
	if(live<limit)
		$('flecha_de').show();
}

var live2=7;

function live_more2(limit){
	old=live2-7;
	live2++;	
	$('live_'+old).hide();
	$('live_'+(live2-1)).show();
	if(live2>7)
		$('flecha_iz').show();
	
	if(live2==limit)
		$('flecha_de').hide();
}

function live_less2(limit){
	old=live2;
	live2--;
	
	$('live_'+(old-1)).hide();
	$('live_'+(live2-7)).show();
	if(live2<=7)
		$('flecha_iz').hide();
	
	if(live2<limit)
		$('flecha_de').show();
}

var live3=6;

function live_more3(limit){
	old=live3-6;
	live3++;	
	$('live_'+old).hide();
	$('live_'+(live3-1)).show();
	if(live3>6)
		$('flecha_iz').show();
	
	if(live3==limit)
		$('flecha_de').hide();
}

function live_less3(limit){
	old=live3;
	live3--;
	
	$('live_'+(old-1)).hide();
	$('live_'+(live3-6)).show();
	if(live3<=6)
		$('flecha_iz').hide();
	
	if(live3<limit)
		$('flecha_de').show();
}




var candidata=7;

function candidata_more(limit){
	old=candidata-7;
	candidata++;	
	$('candidata_'+old).hide();
	$('candidata_'+(candidata-1)).show();
	if(candidata>7)
		$('flecha_iz').show();
	
	if(candidata==limit)
		$('flecha_de').hide();
}

function candidata_less(limit){
	old=candidata;
	candidata--;
	
	$('candidata_'+(old-1)).hide();
	$('candidata_'+(candidata-7)).show();
	if(candidata<=7)
		$('flecha_iz').hide();
	
	if(candidata<limit)
		$('flecha_de').show();
}

var video=3;

function video_more(limit){
	old=video-3;
	video++;	
	$('video_'+old).hide();
	$('video_'+(video-1)).show();
	if(video>3)
		$('flecha1_iz').show();
	
	if(video==limit)
		$('flecha1_de').hide();
}

function video_less(limit){
	old=video;
	video--;
	
	$('video_'+(old-1)).hide();
	$('video_'+(video-3)).show();
	if(video<=3)
		$('flecha1_iz').hide();
	
	if(video<limit)
		$('flecha1_de').show();
}

function inicio(){
	rotativo=setInterval("cambiar()",espera*1000);
}

function inicio_carrusel(seg){
	carrusel=setInterval("cambiar_carrusel()",seg*1000)
	
}

function rotativa_appear(name){
	clearInterval(rotativo);
	new Effect.Appear(name);
	for(var i=0;i<3;i++){
		if(name != 'content_'+i){
			new Effect.Fade('content_'+i);
			var el = document.getElementById('mn_'+i);
			el.className= "noticia_portada";
		}
		else{
			var el = document.getElementById('mn_'+i);
			el.className= "noticia_portada_selected";
			next=i;
			rotativo=setInterval("cambiar()",espera*1000);
		}
	}
}

function change_video(id){
	$('video_principal').innerHTML='<object width="430" height="225"><param name="movie" value="'+id+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+id+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="430" height="225"></embed></object>';
}

function cambiar_foto(contenedor,foto,galeria,foto_galeria,nombre, titulo){
	document.getElementById(contenedor).innerHTML='<img src="'+foto+'" width="300" /><a href="'+galeria+'" rel="lightbox['+nombre+']" title="'+titulo+'" onClick="myLightbox.start(this); return false;"><img  border=0 src="'+foto_galeria+'"/></a>';
}

function cambiar_nombre(nombres,apellidos,provincia){
	$('cnombre').innerHTML='<span style="color:#958144; font-size:25px; font-family:Arial;">'+nombres+' '+apellidos+'<br/></span><span style="color:black; font-size:15px; font-family:Arial;">'+provincia+'</span>';
}


function cambiar_video(url){
	new Ajax.Updater('principal_video', url,
			{
				evalScripts:true,
				onLoading: function(request){ 
					document.getElementById('principal_video').innerHTML='<div id="principal_video" style="width:500px; height:340px;"><br/><br/><center>Cargando...</center></div>';
				}
			});
}

function votar(url,voto,usuario_id,candidata_id,puntos_id){
	new Ajax.Updater('puntajes', url+voto+'/'+usuario_id+'/'+candidata_id+'/'+puntos_id, 
			{
				evalScripts:true,
				onLoading: function(request){ 
					document.getElementById('puntajes').innerHTML='<center>Cargando...</center>';
				}
			});
}

function cambio_galeria_social(url,galeria){
	new Ajax.Updater('galeria_social', url+galeria,
			{
				evalScripts:true,
				onLoading: function(request){ 
		document.getElementById('galeria_social').innerHTML='<center>Cargando...</center>';
				}
			});
} 


function login_member(current_url){ 
	
	FB.ensureInit(function(){
        FB.Facebook.apiClient.users_hasAppPermission('publish_stream', function(result1){
            FB.Facebook.apiClient.users_hasAppPermission('email', function(result2){
                    if(result1 == 0 || result2 == 0 ){
                        FB.Connect.showPermissionDialog("publish_stream,email",function(perms) {
                        	   if (!perms) {
                        		   	   redir_fblogin(current_url);
                        		   } else {
                        			   redir_fblogin(current_url);
                        		   }
                        		 });
                    }
                    else
                    	redir_fblogin(current_url);
                })
            })
        });
   }


function redir_fblogin(res){
	document.location.href = '/users/fblogin';

}
