$(document).ready(function () {
	

    // -------------------------------------------------------------------------------------------
    // Highlights
    // -------------------------------------------------------------------------------------------	
	try { $(".smart #smartbar").tabs({ event: 'mouseover' }).tabs('rotate', 6000);
	} catch (e) { }
	
    
    // -------------------------------------------------------------------------------------------
    // Agenda
    // -------------------------------------------------------------------------------------------	
    try {
        $('#agenda').jcarousel({ vertical: true, scroll: 1 });
    } catch (e) { }


    // -------------------------------------------------------------------------------------------
    // Newsletters
    // -------------------------------------------------------------------------------------------	
    try {
        $('div.boletim_gallery img:first').addClass("start");
        $('div.boletim_gallery img').slidingGallery({ container: $('div.boletim_gallery'), 'Pheight': '90', 'Pwidth': '62', 'slideSpeed': 'normal' });
    } catch (e) { }


    // -------------------------------------------------------------------------------------------
    // Menu Horizontal
    // -------------------------------------------------------------------------------------------  	
    $('ul.menu li.btn').hover(
        function () {
            $(this).addClass('hover');
            $id = $(this).attr('id');
            $('#' + $id).parent().find('#sub' + $id).stop().delay(200).fadeTo(300, 1);
        },
        function () {
            $(this).removeClass('hover');
            $(this).parent().find('.submenu').stop().fadeTo(0, 0).removeClass('block').hide();
        }
    );
    $('.submenu ul li a').hover(
        function () {
            $(this).prev('div').toggleClass('color');
        }
    );


    // -------------------------------------------------------------------------------------------
    // Images 
    // -------------------------------------------------------------------------------------------  
    /*$('a img, input[type="submit"], .zoomtext a, .mod_boletim img').hover(
		function () {
		    $(this).stop().fadeTo(300, 0.7);
		}, function () {
		    $(this).stop().fadeTo(500, 1);
		}
	);*/


    // -------------------------------------------------------------------------------------------
    // Menu Horizontal - Submenu  
    // ------------------------------------------------------------------------------------------- 
    $num_submenus = $('.submenu').length;
    $count = 1;
    for ($count = 1; $count <= $num_submenus; $count++) {
        $num_links = $('#submenu_' + $count + ' li').length;
        $larg_btn = $('li#menu_' + $count).width();
        if ($num_links < 8) {
            $('#submenu_' + $count).addClass('onecol');
        }
        if ($num_links > 8 && $num_links < 16) {
            $('#submenu_' + $count).addClass('twocol');
        }
        if ($num_links > 16 && $num_links < 24) {
            $('#submenu_' + $count).addClass('threecol');
        }
    }


    // -------------------------------------------------------------------------------------------
    // Childs
    // ------------------------------------------------------------------------------------------- 
    function getChild($class, $pos, $add, $clear) {
        $num_divs = $class.length;
        $i = 1;
        for ($i = 0; $i <= $num_divs; $i++) {
            if ($i % $pos == 0) {
                $($class).eq($i - 1).addClass($add);
                if ($clear == 1) {
                    $('<div class="clear"></div>').insertAfter($($class).eq($i - 1));
                }
            }
        }
    }
    getChild('.newsletters_content ul li', 5, 'nomargin', 1);
    getChild('.tourism .tourism_content ul li.thumb', 4, 'lasttur', 1);
    getChild('.mod_videos_content li', 4, 'lastvideo', 1);    
	getChild('.layout_6 .mod_menu', 2, 'nomarginright', 1);    
    $("ul.highlight_item:last-child").css('border-bottom', 'none');
    $("ul.highlight_item:last-child").addClass('lasthighlight');
    $('.search_content ul li:last').addClass('nomargin');
    $('.list_agenda > ul:last').css({ 'border-bottom': 'none', 'margin-bottom': '0' });



    // -------------------------------------------------------------------------------------------
    // Vertical Menu
    // ------------------------------------------------------------------------------------------- 
    $(".mod_links_top").click(function () {
        $(this).toggleClass('open');
        if (!$(this).parent().hasClass("open"))
            $(this).parent().find(".mod_links_content,.mod_links_footer").slideToggle();
        else
            $(this).parent().find(".mod_links_content").slideToggle();
        return false;
    });
    $("li.parent a.children").click(function () {
        $(this).parent().siblings().find("li").hide();
        $(this).parent().children().find("li").toggle();
        return false;
    });

    $(".show_link").click(function () {
        $(this).parent().prev().find("ul li.parent:gt(2)").show();
        $(this).parent().children('p.show_link').hide();
        $(this).parent().children('p.hide_link').show();
        return false;
    });
    $(".hide_link").click(function () {
        $(this).parent().prev().find("ul li.parent:gt(2)").hide();
        $(this).parent().children('p.hide_link').hide();
        $(this).parent().children('p.show_link').show();
        return false;
    });
    $(".mod_links_content").each(function () {
        $(this).find("ul li.parent:gt(2)").hide();
        $(".hide_link").hide();
    });


    // -------------------------------------------------------------------------------------------
    // Template Menu
    // ------------------------------------------------------------------------------------------- 
    $('.mod_menu_top').click(function () {
        $(this).parent().find('.mod_menu_content').toggle();
        $(this).parent().find('h2').toggleClass('open');
    });


    // -------------------------------------------------------------------------------------------
    // Mascara Password
    // -------------------------------------------------------------------------------------------                       
    $('#password-clear').show();
    $('#password-password').hide();
    $('#password-clear').focus(function () {
        $('#password-clear').hide();
        $('#password-password').show();
        $('#password-password').focus();
    });
    $('#password-password').blur(function () {
        if ($('#password-password').val() == '') {
            $('#password-clear').show();
            $('#password-password').hide();
        }
    });


    // -------------------------------------------------------------------------------------------
    // Fav
    // ------------------------------------------------------------------------------------------- 
    try {
        $('#fav').jFav();
    } catch (e) { }


    // -------------------------------------------------------------------------------------------
    // Font Resize
    // ------------------------------------------------------------------------------------------- 
    $(".zoomtext a").click(function () {
		try{
        var $speech = $('.list_agenda, .download_content, .albuns_content, .mod_menu p, .news .news_content ul.news_item li, .mod_highlights .mod_highlights_content ul.highlight_item li, .mod_videos .mod_videos_content ul li, .layout_text');
        var currentSize = $speech.css('font-size');
        var num = parseFloat(currentSize, 10);
        var unit = currentSize.slice(-2);
        if (this.id == 'plus' && num <= 16) { num += 1; }
        else if (this.id == 'minus' && num >= 10) { num -= 1; }
        $speech.css('fontSize', num + unit);
        $speech.css('line-height', (num + 6) + unit);
        return false;
		}catch(e){}
    });


    // -------------------------------------------------------------------------------------------
    // Calendar
    // ------------------------------------------------------------------------------------------- 					   
    var meses = new Array(12);
    meses[0] = "Janeiro";
    meses[1] = "Fevereiro";
    meses[2] = "Março";
    meses[3] = "Abril";
    meses[4] = "Maio";
    meses[5] = "Junho";
    meses[6] = "Julho";
    meses[7] = "Agosto";
    meses[8] = "Setembro";
    meses[9] = "Outubro";
    meses[10] = "Novembro";
    meses[11] = "Dezembro";
    var data = new Date();
    var dia = data.getDate();
    var mes = data.getMonth();
    var ano = data.getFullYear();
    var min = data.getMinutes();
    var sec = data.getSeconds();
    var hrs = data.getHours();
    var min = data.getMinutes();
    var sec = data.getSeconds();
    var _data = dia + " de " + meses[mes] + " de " + ano;
    var time;
    $('span.date').append(_data);


    // -------------------------------------------------------------------------------------------
    // Print
    // ------------------------------------------------------------------------------------------- 
    $('div.social li.print').prepend('<a class="print" href="#print" title="Imprimir">Imprimir</a>');
    $('a.print').click(function () {
        window.print();
        return false;
    });


    // -------------------------------------------------------------------------------------------
    // Go To
    // ------------------------------------------------------------------------------------------- 
    $('li.top a').click(function () {
        pmag.goTop();
        return false;
    });


    // -------------------------------------------------------------------------------------------
    // Target Blank
    // ------------------------------------------------------------------------------------------- 
    $(function () {
        /*
		$("a[href^='http']").attr('target','_blank');
        $("a[href^='.pdf']").attr('target','_blank');	  
        $("a[href^='http://app.readspeaker.com']").attr('target','_blank');	  
		*/
    });


    // -------------------------------------------------------------------------------------------
    // Readspeaker
    // ------------------------------------------------------------------------------------------- 
    $('a#rs_button').each(function () {
        $(this).click(function () {
            openAndRead(this.href); return false;
        });
    });
	

    // -------------------------------------------------------------------------------------------
    // History Back
    // ------------------------------------------------------------------------------------------- 
    /*$('li.back a').click(function(){
    parent.history.back(); 
    return false;							   
    });*/


    // -------------------------------------------------------------------------------------------
    // Poll
    // ------------------------------------------------------------------------------------------- 
    /*
    $('.mod_poll_footer .poll_results a').click(function(){
    $max_value = 0;						
    $max_class = 0;														
    $('li.graph').each(function(i) {															
    $percentage = $(this).html(); 
    $percentageclass = $(this).attr('class'); 
    $graph = 0.4 * $percentage;   
    if($percentage > $max_value){
    $max_value = $percentage;									
    $max_class = $(this).attr('class');							
    $max_class = $max_class.slice(6);
    }								
    $(this).css({width: "0"}).animate({width: $graph}, 'slow');});																				
    $('.'+$max_class).addClass('color');  		
    $(this).attr('href','javascript:void(0)');
    $('.mod_poll_answers, .mod_poll_footer .poll_results, .mod_poll_footer .poll_vote').hide();	
    $('.mod_poll_results, .poll_total_votes').fadeIn('fast');		
    });
    */


    // -------------------------------------------------------------------------------------------
    // Zebra Tables
    // ------------------------------------------------------------------------------------------- 
    $(".mod_menu_content").each(function () {
        $(this).find("li:odd").addClass('zebra_odd');
        $(this).find("li:even").addClass('zebra_even');
    });
    $('.download_content ul:odd').addClass('zebra_odd');
    $('.download_content ul:even').addClass('zebra_even');


    // -------------------------------------------------------------------------------------------
    // Pagination
    // ------------------------------------------------------------------------------------------- 
    $('.pagination span:first').addClass('prev');
    $('.pagination span:last').addClass('next');
    $('.pagination span').each(function () {
        if ($(this).attr('class') == "") {
            $(this).addClass('number');
        }
        if ($(this).html() == "") {
            $(this).hide();
        }
    });
	
	//$("#column_center div[class^='layout']:first").addClass('titlemargin');	

});


// -------------------------------------------------------------------------------------------
// Clear Inputs
// ------------------------------------------------------------------------------------------- 
function _clear(t) {
    if (t._Temp == "" || t._Temp == null || t._Temp == undefined)
        t._Temp = t.value;
    if (t.value == t._Temp)
        t.value = "";
    removeClass(t, "Form_error");
}
function _check(t) {
    if (t.value == "" || t.value == null && t.value != t._Temp)
        t.value = t._Temp;
}
function hasClass(ele,cls) {
    return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function removeClass(ele,cls) {
    if (hasClass(ele,cls)) {
        var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
        ele.className=ele.className.replace(reg,' ');
   }
}
function isEmail(email) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if (reg.test(email) == false) {
        return false;
    }
    else
        return true;
}


// -------------------------------------------------------------------------------------------
// Scroll
// ------------------------------------------------------------------------------------------- 
(function() {
    function $(id) {
        return document.getElementById(id);
    }
    function setStyleDisplay(id, status) {
        $(id).style.display = status;
    }
    function goTop(acceleration, time) {
        acceleration = acceleration || 0.1;
        time = time || 16;
        var dx = 0;
        var dy = 0;
        var bx = 0;
        var by = 0;
        var wx = 0;
        var wy = 0;
        var wx = window.scrollX || 0;
        var wy = window.scrollY || 0;
        var x = Math.max(wx, Math.max(bx, dx));
        var y = Math.max(wy, Math.max(by, dy));
        var speed = 1 + acceleration;
        window.scrollTo(Math.floor(x / speed), Math.floor(y / speed));
        if (x > 0 || y > 0) {
            var invokeFunction = "pmag.goTop(" + acceleration + ", " + time + ")"
            window.setTimeout(invokeFunction, time);
        }
    }
    window['pmag'] = {};
    window['pmag']['$'] = $;
    window['pmag']['setStyleDisplay'] = setStyleDisplay;
    window['pmag']['goTop'] = goTop;
})();


// -------------------------------------------------------------------------------------------
// Fav
// ------------------------------------------------------------------------------------------- 
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
eval(function(p, a, c, k, e, r) { e = function(c) { return (c < a ? '' : e(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36)) }; if (!''.replace(/^/, String)) { while (c--) r[e(c)] = k[c] || e(c); k = [function(e) { return r[e] } ]; e = function() { return '\\w+' }; c = 1 }; while (c--) if (k[c]) p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]); return p } ('(7($){$.8.9=7(d){g e=$.v({},$.8.9.k,d);g f=e.l;2.w(7(){5(!$(2).3(\'4\')||$(2).3(\'4\')=="#"){$(2).3(\'4\',j.x.4)}5(!$(2).3(\'6\')){$(2).3(\'6\',y.6)}5($.h.z){$(2).3(\'m\',$(2).3(\'4\')).3(\'4\',\'\').3(\'4\',\'A:B(0)\').3(\'C\',\'$.8.9.n(2,"\'+$(2).3(\'6\')+\'","\'+$(2).3(\'m\')+\'")\')}i{$(2).o(p)}});7 p(a){g b=$(2).3(\'4\');g c=$(2).3(\'6\');b=b.E("q:///","F://q/");5($.h.G){j.H.I(b,c)}i 5($.h.J){j.r.K(c,b,\'\')}i 5(L.M.N().O(\'P\')>-1){s(f)}i 5($.h.Q){s(f)}a.R()};t 2};$.8.9.k={l:\'S "T + D" U "V + D" W X, u Y 2 Z u 10 11.\'};$.8.9.n=7(e,a,b){e.12="r";e.6=a;e.4="";e.4=b;e.o();t 13}})(14);', 62, 67, '||this|attr|href|if|title|function|fn|jFav|||||||var|browser|else|window|defaults|msg|link|OperaBookmark|click|addToFavorites|file|sidebar|alert|return|to|extend|each|location|document|opera|javascript|void|onClick||replace|http|msie|external|AddFavorite|mozilla|addPanel|navigator|userAgent|toLowerCase|indexOf|chrome|safari|preventDefault|Press|Ctrl|or|CMD|for|MAC|add|page|your|bookmarks|rel|false|$'.split('|'), 0, {}))


// -------------------------------------------------------------------------------------------
// Multimedia
// ------------------------------------------------------------------------------------------- 
$(document).ready(function(){
	$('a.multimedia').click(function(){
		$largura_popup = $('.pp_hoverContainer').width();
		if(	$largura_popup < 100) {			
			$('.pp_nav').addClass('none');
		}else{
			$('.pp_nav').removeClass('none');
		}		
	});	
});


// -------------------------------------------------------------------------------------------
// Vertical Align
// ------------------------------------------------------------------------------------------- 
(function ($) {
$.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = Math.ceil((ph-ah) / 2);
	$(this).css('margin-top', mh);
	});
};
})(jQuery);
$(document).ready(function(){
	$('.tourism .tourism_content ul li.section div').vAlign();
});


$(window).load(function(){
	$('.teaser .teaser_content').show();
});



