// JavaScript Document
$(document).ready(function() {  // jQuery

	// Altura da Div container
	$('#container').height($(document).height());

	// fix for target="_blank"
	$("a[rel*='external']").click(function(){
		window.open($(this).attr("href"), 'janela','scrollbars=yes,resizable=yes,width=850,height=600');
		return false;
	});

	// Imagens rollover
	$('.over').hover(
		function() { this.src = this.src.replace("_off","_on");  },
		function() {  this.src = this.src.replace("_on","_off"); }  
	)
	
	// LightBox
	if($("a[rel^='prettyPhoto']").length>0) {
		$("a[rel^='prettyPhoto']").prettyPhoto();
	}
	
	// Tips (alt)
	$(function() {
    	$('[title]').tip()
	});
	
	// Agenda da home
	control_calend = function() {
		$('<span id="cal_btprox">></span>').prependTo('#cal_titulo');
		$('<span id="cal_btante"><</span>').prependTo('#cal_titulo');
		//$('#cal_btprox').attr('title','Próximo');
		//$('#cal_btante').attr('title','Anterior');
	}
	ativa_calend = function() {
		control_calend();
		$('[title]').tip();
		$("a[rel^='prettyPhoto']").prettyPhoto();
		
		// Botão 'anterior'
		$('#cal_btante').bind('click', function() {
			var cp_mes = parseInt($('#cp_mes').val())-1;
			var cp_ano = parseInt($('#cp_ano').val());
			if(cp_mes<1) {
				cp_mes=12;
				cp_ano-=1;
			}
			params="mes="+cp_mes+"&ano="+cp_ano;
			muda_calend();
		});
		// Botão 'próximo'
		$('#cal_btprox').bind('click', function() {
			var cp_mes = parseInt($('#cp_mes').val())+1;
			var cp_ano = parseInt($('#cp_ano').val());
			if(cp_mes>12) { 
				cp_mes=1;
				cp_ano+=1;
			}
			params="mes="+cp_mes+"&ano="+cp_ano;
			muda_calend();
		});
	}
	
	muda_calend = function() {
			 $.ajax({
				 type: "GET",
				 url: 'agenda/index.php',
				 data: params,
				 dataType: "html",
				 contentType: "application/x-www-form-urlencoded;charset=ISO-8859-1", 
				 async: false,
				 beforeSend: function(xhr) {
					 xhr.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
					 xhr.setRequestHeader("Pragma", "no-cache");
				 },
				 success: function(htm) {
					 $('#bx_calendario').empty().html(htm);
					 ativa_calend();
				 },
				 error: function(xml) { alert('Erro de acesso ao arquivo: agenda/index.php'); } 
			})
	}
	
	if($('#bx_calendario').length > 0) {
		ativa_calend();
	}
	
	// Sombra dos telefones topo
	if($('#bx_fones_sombra').length > 0) {
		$('#bx_fones_sombra').html($('#bx_fones').html());
	}

	// Zebra tabelas índices econômicos
	$("#bx_indicadores tr:odd td").addClass("odd");
	$(".bx_tabelas1 tr:odd td").addClass("odd");
	
	// Limpa form home
	$("#WebMatic").submit(function() {
		comando="window.document."+$(this).attr('name')+".reset()";
		setTimeout("eval(comando)",4000);
	})

});

