// define o namespace da aplicação
Application = {};

/**
 * Retorna uma URL completa dado um caminho relativo.
 *
 * É importante que esta função seja definida antes
 * da definição das biliotecas "thickbox" e "sIFR",
 * pois alterei o código-fonte delas para que caminhos
 * relativos sejam convertidos em caminhos absolutos utilizando
 * esta função.
 *
 * @param  string url Um pedaço de URL (caminho relativo dentro do servidor)
 * @return string     Uma URL completa
 */
Application.build_url = function(url) {

    if (!Application.BASE_URL || !Application.BASE_URL.match(/^http/)) {
        Application.BASE_URL = $('meta[name=base_url]').attr('content');
    }

    return Application.BASE_URL + url; 
}


jQuery(document).ready(function($) {
    // Abre links com o rel external em novas janelas
    $("a[rel~='external']").click(function(){
        window.open($(this).attr('href'));
        return false;
    });
    
    $('#nav li').hover(function(){
        $(this).find('.sub').show();
    },function(){
        $(this).find('.sub').hide();
    });
    
    
    // Newsticker
    function newsticket_next() {
        // Anima
        $('.newsticker ul.lista li:first-child').fadeOut(200).detach().appendTo('.newsticker ul.lista');
        $('.newsticker ul.lista li:first-child').delay(200).fadeIn(200);
    }    
    $('.newsticker .previous').click(function(){
        // Limpa o intervalo e seta de novo
        clearInterval(newsticker_intervalo);
        newsticker_intervalo = setInterval(newsticket_next, 5000);
        // Anima
        $('.newsticker ul.lista li:first-child').fadeOut(200);
        $('.newsticker ul.lista li:last-child').delay(200).detach().prependTo('.newsticker ul.lista').fadeIn(200);
    });
    $('.newsticker .next').click(function(){
        // Limpa o intervalo e seta de novo
        clearInterval(newsticker_intervalo);
        newsticker_intervalo = setInterval(newsticket_next, 5000);
        // Anima
        newsticket_next();
    });
    // Seta o intervalo
    newsticker_intervalo = setInterval(newsticket_next, 5000);
    
    // Abre a descrição na Galeria de Prêmios
    $('.premio').hover(function(){
        $(this).addClass('z-index');
    }, function(){
        $(this).removeClass('z-index');
    });
    
    $('.premio img').hover(function(){
        $(this).next('.descricao').stop('true','true').fadeIn('normal');
    }, function(){
        $(this).next('.descricao').stop('true','true').fadeOut('normal');
    });
    
    $('.timeline_content .1976').show();
    $('.timeline_nav a').click(function(){
        var ano = $(this).attr('rel');
        $('.timeline_nav a').removeClass('current');
        $(this).addClass('current');
        $('.timeline_content').find('li').hide();
        $('li.' + ano).show();
    });
    
    
    
})

jQuery.fn.checkCampoPreenchido = function ( nome ) {
	if ( $(this).val()===null || $(this).val().length == 0 ) {
		$('.error').html("Campo <b>"+nome+"</b> deve ser preenchido.").show();
		$('.success').hide();
		return false;
	}
	return true;
}

function IsNumeric(input){
    var RE = /^-{0,1}\d*\.{0,1}\d+$/;
    return (RE.test(input));
}

