//javascript

//JQUERYS RUN AT STARTUP.
//=================================================================================================
jQuery.noConflict();

jQuery(document).ready(function() {
    if (location.href.indexOf("home") > 0){
         jQuery("body").addClass('bgHome');
    }


    try {

        jQuery('#mycarousel').jcarousel({
            //scroll:7
            visible: 7
        });

        jQuery('#mycarousel_IndiceHidrologico').jcarousel({
            //scroll:7
            visible: 3
        });
    }
    catch (e) { } 
	
	
	jQuery(".meio .tamanho-letra .medio").click(function(){
	
	var font = jQuery("p.txt").css("font-size").replace("px", "");
	var fontSize = new Number(font);

	    if(fontSize < 18){
	        fontSize = fontSize + 2;
	        jQuery("p.txt, p.txt a").css("font-size", fontSize + "px");
	    }

	    
	});
	
	jQuery(".meio .tamanho-letra .grande").click(function(){
	
	var font = jQuery("p.txt").css("font-size").replace("px", "");
	var fontSize = new Number(font);

	    if(fontSize > 8){
	        fontSize = fontSize - 2;
	        jQuery("p.txt, p.txt a").css("font-size", fontSize + "px");
	    }
	});
	
	
	jQuery(".box_festival_item .tamanho-letra .medio").click(function(){
	
	var font = jQuery(".box_festival_item p").css("font-size").replace("px", "");
	var fontSize = new Number(font);

	    if(fontSize < 18){
	        fontSize = fontSize + 2;
	        jQuery(".box_festival_item p, .box_festival_item p. a").css("font-size", fontSize + "px");
	    }

	    
	});
	
	jQuery(".box_festival_item .tamanho-letra .grande").click(function(){
	
	var font = jQuery(".box_festival_item p").css("font-size").replace("px", "");
	var fontSize = new Number(font);

	    if(fontSize > 8){
	        fontSize = fontSize - 2;
	        jQuery(".box_festival_item p, .box_festival_item p a").css("font-size", fontSize + "px");
	    }
	});
	
	var qtd = 0;
	jQuery(".boxRevista").each(function(){
	    qtd++;
	    if(qtd % 2 == 0)
	    {
	        jQuery(this).addClass("addCor");
	    }
	
	});
	

});
//=================================================================================================

//FUNÇÃO PARA EXIBIR FLASHS.
//=================================================================================================
function GetEmbFlash(pathSWF, flashVars, width, height)
{
    var absPathSWF = window.location.href.split("/");
        absPathSWF = "http://" + absPathSWF[2] + "/" + pathSWF;
    var strEmbled;
    
    strEmbled = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0'";
    strEmbled += "width='" + width + "' height='" + height + "' id='main' align='middle'>";
    strEmbled += "<param name='allowScriptAccess' value='sameDomain' />";
    strEmbled += "<param name='allowFullScreen' value='false' />";
    strEmbled += "<param name='movie' value='" + absPathSWF + "' />";
    strEmbled += "<param name='quality' value='high' />";
    strEmbled += "<param name='wmode' value='transparent' />";
    strEmbled += "<param name='flashvars' value='" + (flashVars != "=" ? flashVars : null) + "' />";
    strEmbled += "<embed src='" + absPathSWF + "' quality='high' bgcolor='#ffffff' width='" + width + "' height='" + height + "'";
    strEmbled += "name='main' wmode='transparent' align='middle' allowscriptaccess='always' allowfullscreen='false'";
    strEmbled += "type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer'";
    strEmbled += "flashvars='" + (flashVars != "=" ? flashVars : null) + "' />";
    strEmbled += "</object>";
    
    return document.write(strEmbled);
}
//=================================================================================================

//FUNÇÃO PARA EXIBIR VIDEOS DO YOUTUBE.
//=================================================================================================
function GetEmbVideo(pathSWF, flashVars, width, height) {
    var strEmbled;

    strEmbled = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0'";
    strEmbled += "width='" + width + "' height='" + height + "' id='main' align='middle'>";
    strEmbled += "<param name='allowScriptAccess' value='sameDomain' />";
    strEmbled += "<param name='allowFullScreen' value='false' />";
    strEmbled += "<param name='movie' value='" + pathSWF + "' />";
    strEmbled += "<param name='quality' value='high' />";
    strEmbled += "<param name='wmode' value='transparent' />";
    strEmbled += "<param name='flashvars' value='" + (flashVars != "=" ? flashVars : null) + "' />";
    strEmbled += "<embed src='" + pathSWF + "' quality='high' bgcolor='#ffffff' width='" + width + "' height='" + height + "'";
    strEmbled += "name='main' wmode='transparent' align='middle' allowscriptaccess='always' allowfullscreen='false'";
    strEmbled += "type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer'";
    strEmbled += "flashvars='" + (flashVars != "=" ? flashVars : null) + "' />";
    strEmbled += "</object>";

    return document.write(strEmbled);
}
//=================================================================================================


//CÓDIGOS PARA AUMENTAR E DIMINUIR O TAMANHO DA FONTE DOS TEXTOS.
//=================================================================================================

// Para usar coloque o comando: "javascript:mudaTamanho('tag_ou_id_alvo', -1);" para diminuir
// e o comando "javascript:mudaTamanho('tag_ou_id_alvo', +1);" para aumentar

var tagAlvo = new Array('p'); //pega todas as tags p//

// Especificando os possíveis tamanhos de fontes, poderia ser: x-small, small...
var tamanhos = new Array('8px', '10px', '12px', '14px', '16px', '18px');
var tamanhoInicial = 2;

function mudaTamanho(idAlvo, acao) {
    if (!document.getElementById) return
    var selecionados = null, tamanho = tamanhoInicial, i, j, tagsAlvo;
    tamanho += acao;
    if (tamanho < 0) tamanho = 0;
    if (tamanho > 6) tamanho = 6;
    tamanhoInicial = tamanho;
    if (!(selecionados = document.getElementById(idAlvo))) selecionados = document.getElementsByTagName(idAlvo)[0];

    selecionados.style.fontSize = tamanhos[tamanho];

    for (i = 0; i < tagAlvo.length; i++) {
        tagsAlvo = selecionados.getElementsByTagName(tagAlvo[i]);
        for (j = 0; j < tagsAlvo.length; j++) tagsAlvo[j].style.fontSize = tamanhos[tamanho];
    }
}
//=================================================================================================

//CÓDIGOS PARA COLOCAR O FLASH/VIDEO NA ESQUERDA OU NA DIREITA.
//=================================================================================================
function changeFloat(idObject, position)
{
    if (position == "left") {
        jQuery("#" + idObject).removeClass('flashRight');
        jQuery("#" + idObject).addClass('flashLeft');
    }
    else {
        jQuery("#" + idObject).removeClass('flashLeft');
        jQuery("#" + idObject).addClass('flashRight');
    }
}
//=================================================================================================

//CÓDIGOS PARA MOSTRAR OU ESCONDER OBJETOS
//=================================================================================================
function showHidden(idObject, action) {
    if (action == "show") {
        jQuery("#" + idObject).removeClass('hidden');
        jQuery("#" + idObject).addClass('show');
    }
    else {
        jQuery("#" + idObject).removeClass('show');
        jQuery("#" + idObject).addClass('hidden');
    }
}
//=================================================================================================


// MENU ATIVO
//======================================================================================================
function PaginaAtual(urlDestino, paginaAtual)
{
var xxx = String(window.location);

if(xxx.indexOf(urlDestino) > -1)
{
	jQuery(document).ready(function() 
	{
		jQuery(".itemMenuLateral").css("text-decoration", "none");		
		jQuery("#"+ paginaAtual).css("text-decoration", "underline");	

	});
}
}

// MODAL BOX
jQuery(document).ready(function() {	

	//select all the a tag with name equal to modal
    jQuery('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = jQuery(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = jQuery(document).height();
		var maskWidth = jQuery(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		jQuery('#mask').css({ 'width': maskWidth, 'height': maskHeight });
		
		//transition effect
		jQuery('#mask').fadeIn(1000);
		jQuery('#mask').fadeTo("slow", 0.8);	
	
		//Get the window height and width
		var winH = jQuery(window).height();
		var winW = jQuery(window).width();
              
		//Set the popup window to center
		jQuery(id).css('top',  winH/2-jQuery(id).height()/2);
		jQuery(id).css('left', winW/2-jQuery(id).width()/2);
	
		//transition effect
		jQuery(id).fadeIn(2000); 
	
	});
	
	//if close button is clicked
	jQuery('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		jQuery('#mask').hide();
		jQuery('.window').hide();
	});		
	
	//if mask is clicked
	jQuery('#mask').click(function () {
		jQuery(this).hide();
		jQuery('.window').hide();
	});			
	
});


jQuery(document).ready(function(){
	jQuery('.modalTop').click(function () {
		jQuery('html, body').animate({
			scrollTop: jQuery('body').offset().top
		}, 1000);
	});
});



/* Home --------------------------------------------------------------------------------------------------------------------------- */
// JavaScript Document

/* 0
funcao que controla a exibicao dos conteudos em lista com controle por setas
------------------------------------------------------------------------------------------------- */

var cont;
function esteira(obj,inicialLength) {
    var esteira = obj;
	
	jQuery(esteira).attr('itLn',inicialLength)
	
    //defino o tamanho da ul de acordo com o numero de lis
    jQuery(obj).find('ul').width(jQuery(obj).find('ul').find('li').length * jQuery(obj).find('ul').find('li:first').outerWidth()).attr('itLn',inicialLength + 1)
	

	//desabilito o botao anterior e ativo a 1 listagem
   jQuery(esteira).find('ul:first').addClass('active').end().parent().find('span.anterior').css('visibility', 'hidden');
	 if (jQuery(obj).find('li').length <=inicialLength)
	 	jQuery(obj).next().css('visibility', 'hidden');

    //caso clique no botao proximo
    jQuery('span.proximo').click(function() {
        //habilito o botao esquerdo
        jQuery(this).prev().prev().css('visibility', 'visible');

        if (jQuery(this).prev().find('ul').is(':not(:animated)')) {
            jQuery(this).prev().find('ul').animate({
                marginLeft: '-=' + jQuery(this).prev().find('ul').find('li:first').outerWidth()						  
			})
        }
        
       //caso o tamanho da margin left da ul seja o mesmo que a largura escondo o botao de proximo
        if ((jQuery(this).prev().find('ul').css('margin-left') == '-' + ((jQuery(this).prev().find('ul').find('li').length - (parseInt(jQuery(this).prev().attr('itLn')) + 1)) * jQuery(this).prev().find('ul').find('li:first').outerWidth()) + 'px') || (((jQuery(this).prev().find('ul').find('li').length - (parseInt(jQuery(this).prev().attr('itLn')) + 1)) * jQuery(this).prev().find('ul').find('li:first').outerWidth()) + 'px') == '0px')
		    jQuery(this).css('visibility', 'hidden');

    })


    //caso clique no botao anterior
    jQuery('span.anterior').click(function() {
        //habilito o botao esquerdo
        jQuery(this).next().next().css('visibility', 'visible');

        if (jQuery(this).next().find('ul').is(':not(:animated)')) {
            jQuery(this).next().find('ul').animate({
                marginLeft: '+=' + jQuery(this).next().find('ul').find('li:first').outerWidth()						  
			})
		}

		//caso o tamanho da margin left da ul seja o mesmo de 1 objeto li escondo o botao de anterior
        if (jQuery(this).next().find('ul').css('margin-left') == '-' + jQuery(this).next().find('ul').find('li:first').outerWidth() + 'px')
		    jQuery(this).css('visibility', 'hidden');
    })

}



/* 0
funcao que controla a exibicao dos conteudos em lista com controle por setas vertical
------------------------------------------------------------------------------------------------- */

var cont;
function esteiraVertical(obj, inicialLength) {
    var esteiraVertical = obj;

    jQuery(esteiraVertical).attr('itLn', inicialLength)

    //defino o tamanho da ul de acordo com o numero de lis
    jQuery(obj).find('ul').height(jQuery(obj).find('ul').find('li').length * jQuery(obj).find('ul').find('li:first').outerHeight()).attr('itLn', inicialLength + 1)


    //desabilito o botao anterior e ativo a 1 listagem
    jQuery(esteiraVertical).find('ul:first').addClass('active').end().parent().find('span.anteriorVertical').css('visibility', 'hidden');
    if (jQuery(obj).find('li').length <= inicialLength)
        jQuery(obj).next().css('visibility', 'hidden');

    //caso clique no botao proximo
    jQuery('span.proximoVertical').click(function() {
        //habilito o botao esquerdo
        jQuery(this).prev().prev().css('visibility', 'visible');

        if (jQuery(this).prev().find('ul').is(':not(:animated)')) {
            jQuery(this).prev().find('ul').animate({
                marginTop: '-=' + jQuery(this).prev().find('ul').find('li:first').outerHeight()
            })
        }

        //caso o tamanho da margin left da ul seja o mesmo que a largura escondo o botao de proximo
        if ((jQuery(this).prev().find('ul').css('margin-top') == '-' + ((jQuery(this).prev().find('ul').find('li').length - (parseInt(jQuery(this).prev().attr('itLn')) + 1)) * jQuery(this).prev().find('ul').find('li:first').outerHeight()) + 'px') || (((jQuery(this).prev().find('ul').find('li').length - (parseInt(jQuery(this).prev().attr('itLn')) + 1)) * jQuery(this).prev().find('ul').find('li:first').outerHeight()) + 'px') == '0px')
            jQuery(this).css('visibility', 'hidden');

    })


    //caso clique no botao anterior
    jQuery('span.anteriorVertical').click(function() {
        //habilito o botao esquerdo
        jQuery(this).next().next().css('visibility', 'visible');

        if (jQuery(this).next().find('ul').is(':not(:animated)')) {
            jQuery(this).next().find('ul').animate({
                marginTop: '+=' + jQuery(this).next().find('ul').find('li:first').outerHeight()
            })
        }

        //caso o tamanho da margin left da ul seja o mesmo de 1 objeto li escondo o botao de anterior
        if (jQuery(this).next().find('ul').css('margin-top') == '-' + jQuery(this).next().find('ul').find('li:first').outerHeight() + 'px')
            jQuery(this).css('visibility', 'hidden');
    })

}


// FOOTER CARROSSEL
jQuery(document).ready(function() {
		
	jQuery('ul.menu li.fotos a').click(function() {
		jQuery('#content .divCarrosselFooter .divFotos').show();
		jQuery('#content .divCarrosselFooter .divVideos').hide();
		jQuery('#content .divCarrosselFooter .divInfograficos').hide();
		jQuery(this).addClass('active');
		jQuery('ul.menu li.videos a').removeClass("active");
		jQuery('ul.menu li.infograficos a').removeClass("active");
	});
	
	jQuery('ul.menu li.videos a').click(function() {
		jQuery('#content .divCarrosselFooter .divFotos').hide();
		jQuery('#content .divCarrosselFooter .divVideos').show();
		jQuery('#content .divCarrosselFooter .divInfograficos').hide();
		jQuery(this).addClass('active');
		jQuery('ul.menu li.fotos a').removeClass("active");
		jQuery('ul.menu li.infograficos a').removeClass("active");
	});
	
	jQuery('ul.menu li.infograficos a').click(function() {
		jQuery('#content .divCarrosselFooter .divFotos').hide();
		jQuery('#content .divCarrosselFooter .divVideos').hide();
		jQuery('#content .divCarrosselFooter .divInfograficos').show();
		jQuery(this).addClass('active');
		jQuery('ul.menu li.videos a').removeClass("active");
		jQuery('ul.menu li.fotos a').removeClass("active");
	});
	
});
