$(function() {
    light();

    $(".carousel").jCarouselLite({
	btnNext: ".prev",
	btnPrev: ".prev",
	height: 390
    });

    $(".carouselMini").jCarouselLite({
	btnNext: ".nextAgenda",
	btnPrev: ".prevAgenda",
	height: 220
    });


    $('.btVer').live('click', function() {
	$.ajax({
	    type: 'POST',
	    url: 'index.php?action=validateEventoRestrito',
	    data: "codigo="+$("#codigo_restrito").val(),
	    success: function(msg){
		if((msg != '')&&(msg != null)&&(msg != undefined)){
		    window.location.href = 'index.php?action=eventoDestaque&codigo=' + msg
		}else{
		    alert('O código digitado não existe.');
		}
	    }
	});
    });

    pageEvento('no');
    $('#filtro_cidade').change(function(){
	pageEvento('no');
    });

    $('.setaDireita').live('click', function(){
	pageEvento('up');
    });

    $('.setaEsquerda').live('click', function(){
	pageEvento('down');
    });


});

function pageEvento(arg){
    var cidade = $('#filtro_cidade').val();

    if (cidade == 'todas'){
	cidade = '';
    }

    $.ajax({
	url: 'index.php',
	data: 'action=jsReturnEvento&page=' + arg + '&cidade=' + cidade,
	success: function(msg){
	    if (msg != '') {
		$('#agrupaEventos').css('display','none');
		$('#agrupaEventos').html(msg);
		$('#agrupaEventos').fadeIn('slow');

                light();
		setTimeout("setHeightBloco()", 200);
	    }
	}
    });
}

function setHeightBloco(){
    var getId = 0;

    getId = $('#getId').html();

    if (getId >= 1){
	var max = 0;
	var aux = 0;

	for (var s = 0; s <= getId; s++) {
	    aux = $('#jsBlocoEvento_' + s).height();
	    if (aux > max){
		max = aux;
	    }
	}

	$('.blocoEvento').height(max);
    }
}
