//Aqui cambia el numero de filas que quieras en los EVENTOS (Agenda)
var filaseventos = 8;
var AGENDA = "EVENTOS-VERACRUZ";
//Aqui cambia el numero de filas que quieras en las noticias (abajo de Agenda)
var filas = 3;
var portal = "VERACRUZ";

function IniciaNoticiasEventos(){
	/* Se carga el panel de noticias */
	$.ajax({
        type: "GET",
        url: "../noticiasuv/PrincipalNoticias.aspx",
        data: "filas=" + filas + "&imgfolder=" + portal + "&ms="+new Date().getTime(),
        success: function(datos){
			$("#noticias").hide();
			$("#noticias").html(datos);
			$("#noticias").fadeIn(500);
        },		
		error: function(obj1, e, obj2){
			CambiaPaginaNoticias(1);
		}
	});
	$.ajax({
		type: "GET",
        url: "../noticiasuv/PrincipalEventos.aspx",
		contentType: "charset=ISO-8859-1",
		data: "IDAGENDA=" + AGENDA + "&filas=" + filaseventos + "&ms="+new Date().getTime(),
        success: function(datos){
        	$("#agendauv").hide();
			$("#agendauv").html(datos);
			$("#agendauv").fadeIn(500);
        },		
		error: function(obj1, e, obj2){			
			CambiaMes();
		}
	});
}

function CambiaPaginaNoticias( pag )
{
	/* Se carga el panel de noticias */
	$.ajax(
	{
        type: "GET",
        url: "../noticiasuv/PrincipalNoticias.aspx",
        data: "filas=" + filas + "&imgfolder=" + portal + "&pag=" + pag + "&ms="+new Date().getTime(),
        success: function(datos)
		{
			$("#noticias").hide();
			$("#noticias").html(datos);
			$("#noticias").fadeIn(500);
        },
		error: function(obj1, e, obj2)
		{
			CambiaPaginaNoticias( 1 );
		}
	});
}

/*Función para cambiar el mes del calendario*/
function CambiaMes( url )
{
	$.ajax(
	{
        type: "GET",
        url: "../noticiasuv/PrincipalEventos.aspx",
        data: "IDAGENDA=" + AGENDA + "&filas=" + filaseventos + "&ms="+new Date().getTime(),
		
        success: function(datos)
		{        	
			$("#agendauv").hide();
			$("#agendauv").html(datos);
			$("#agendauv").fadeIn(500);
        },				
		
		error: function(obj1, e, obj2)
		{
			CambiaMes();
		}
	});
}

/*Función para abrir un evento seleccionado */
function abredetalles( idevento, f, b )
{
	if( b != null )
		window.open("eventos/detalles.php?eventoid=" + idevento + "&fecha=" + f + "&busca=" + b,"evento" + idevento,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=700");
	else
		window.open("eventos/detalles.php?eventoid=" + idevento + "&fecha=" + f,"evento" + idevento,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=700");
}

/*Función para que no salga la liga en la status bar*/
function StatusTexto( texto ){
  window.status=texto;
  return true;
}

/* Todo esto es para el aviso importante */
var delayLength = 5000;
var no_current_slide = 0;
var no_panels = 0;
var sliderIntervalID;

$("#AvisoImp").ready(function(){
	try
	{
		//Esconde todos los paneles
		$("#ImagenesAviso img").eq(0).show();
		no_panels = $("#ImagenesAviso img").length;
		$("#AvisoImpNumero").html("1/"+no_panels);
		if( no_panels > 1 ){
			sliderIntervalID = setInterval(function(){
				CambiaSlide(++no_current_slide);
			}, delayLength);
		}
	}
	catch(e)
	{
	}
	
	$("#btnAvisoAdelante img").click(function(){
		try
		{
			clearInterval(sliderIntervalID);
			if( no_panels > 1 ){
				CambiaSlide(++no_current_slide);
				sliderIntervalID = setInterval(function(){
					CambiaSlide(++no_current_slide);
				}, delayLength);
			}
		}
		catch(e)
		{
		}
	});
	
	$("#btnAvisoAtras img").click(function(){
		try
		{
			clearInterval(sliderIntervalID);
			if( no_panels > 1 ){
				CambiaSlide(--no_current_slide);
				sliderIntervalID = setInterval(function(){
					CambiaSlide(--no_current_slide);
				}, delayLength);
			}
		}
		catch(e)
		{
		}
	});
	
	$("#ImagenesAviso img").hover(function(){
		clearInterval(sliderIntervalID);
	},
	function(){
		try
		{
			if( no_panels > 1 ){
				sliderIntervalID = setInterval(function(){
					CambiaSlide(++no_current_slide);
				}, delayLength);
			}
		}
		catch(e)
		{
		}
	});
	
	$("#AvisoImp").hover(
	function(){
		$("#btnAvisoAtras img, #btnAvisoAdelante img, #AvisoImpNumero").css('visibility','visible');
	},
	function(){
		$("#btnAvisoAtras img, #btnAvisoAdelante img, #AvisoImpNumero").css('visibility','hidden');
	});
});

function CambiaSlide(no_slide) {
	try
	{
		if( no_slide >= no_panels ){
			no_current_slide = 0;
			no_slide = 0;
		}
		else if( no_slide < 0 ){
			no_current_slide = no_panels - 1;
			no_slide = no_panels - 1;
		}
		var $slide = $("#ImagenesAviso img").eq(no_slide);
		$("#ImagenesAviso img").hide();
		$slide.fadeIn();
		$("#AvisoImpNumero").text((no_slide+1)+"/"+no_panels);
	}
	catch(e)
	{
	}
}
