var fontSize = 12;
var h2Size = 16;
var notAtual = 1;
var notPause = 'N';

// funcoes que depende do jquery.js
$(function() {
	// corrige bug de imagens de fundo do ie
	try {
	  document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}
	
	// desabilita links com #
	$('a[@href=#]').click(function(){ return false; });
	
	// previsao do tempo 
	$('#topo1 p a[@href=#tempo]').click(function(){
		window.open('http://www.blumenau.sc.gov.br/defesa/boletimnivel.asp','boletim','width=620,height=550,scrollbars=yes,top=10,left=100')
		return false;
	});
	
	// patrocinadores
	$('#patrocinador').cycle({ fx:'fade', timeout:3000, next:'#patNext', prev:'#patPrev' });
	
	// menu dropdown show
	$('#menu>ul>li>a').hover(function(){
		$('#menu ul li ul').hide();
		$(this).parent('li').children('ul').show();
	},function(){ 
		return false;
	});
	
	// menu dropdown hide
	$('#menu ul li ul').hover(
		function(){
			$('#conteudo select').hide();
			$(this).parent('li').children('a').addClass('hover');
		},function(){
			$('#conteudo select').show();
			$(this).parent('li').children('a').removeClass('hover');
			$(this).hide();
		}
	);
	$('*').not('#menuh').not('#menu').not('ul').not('li').not('a').hover(
		function(){
			$('#conteudo select').show();
			$('#menu ul li ul:visible').hide();
		},function(){
			return false;
		}
	);
	
	// menu sanfona
	$('#menuv>ul>li>a').click(function() {
		if( $(this).parent('li').children('ul').html() != null) {
			if ($(this).parent('li').children('a').attr('class') == 'ativo') {
				$(this).parent('li').children('a').attr('class','inativo');
				$(this).parent('li').children('ul').slideUp('fast');
			} else {
				$('#menuv ul li a').attr('class','inativo');
				$('#menuv ul li ul:visible').slideUp('fast');
				$(this).parent('li').children('ul').slideDown('fast');
				$(this).parent('li').children('a').attr('class','ativo');
			}
		}
	});
	
	// tamanho da fonte
	$('#aumFonte').click(function(){
		fontSize++; 
		h2Size++;
		$('#conteudo').css({ 'font-size':fontSize });
		$('#conteudo h2').css({ 'font-size':h2Size });
		$('#conteudo font').css({ 'font-size':fontSize });
		return false;
	});
	$('#dimFonte').click(function(){
		fontSize--; 
		h2Size--;
		$('#conteudo').css({ 'font-size':fontSize });
		$('#conteudo h2').css({ 'font-size':h2Size });
		$('#conteudo font').css({ 'font-size':fontSize });
		return false;
	});
	
	// esconde uls sem conteudo
	$('#conteudo ul').each(function(){
		if($(this).children('li').children('a').html()==''){
			$(this).hide();
		}
	});
	
	// sites do municipio target=_blank
	$('#mv8 ul li a').attr('target','_blank');

	// busca agencias
	$('#formAgenciasBusca select[@name=estado]').change(function(){
		estado = $(this).val();
		$('#agencia').html('carregando...');
		//$('#agencia').load('agencias_busca_action.php', {estado:estado});
		$.get('agencias_busca_action.php?estado='+estado,function(data){
			$('#agencia').html(data);
		});
	});
	
	$('#home #noticias div.item').click(function(){
		location.href = $(this).children('a').attr('href');
	});
	$('#home #noticias div.item').hover(function(){
		$('#home #noticias div.item').removeClass('hover');
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	});
	
});

// carrega noticias da home
function slideshow(objID, transicao, total) {
	notAtual = objID;

	if (transicao) {
		anterior = objID -1;
		if (anterior <=0) anterior=total;
		$('#not' + anterior).slideUp(200);
	}
	
	proximo = objID + 1;
	if (proximo > total) proximo=1;
	$('#not' + objID).slideDown(500);
	notCont = setTimeout('slideshow('+ proximo  +', 1, '+total+')', 8000);
}

// agencias locais
function agenciaLocal(c) {
	estado = $('#formAgenciasBusca select[@name=estado]').val();
	local  = c.value;
	$('#agencia').html('carregando...');
	$.get('agencias_busca_action.php?estado='+estado+'&CHAVE_LOCAL='+local,function(data){
		$('#agencia').html(data);
	});
}

// abre zoom para fotos
function zoom(pImg) {
	window.open('../upl/_zoom.php?foto='+pImg, 'zoom', 'top=160, left=252, width=510, height=410, status=yes');
}

// valida endereco de e-mail
function checkMail(mail){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(typeof(mail) == "string"){
		if(er.test(mail)){ return true; }
	}else if(typeof(mail) == "object"){
		if(er.test(mail.value)){
			return true;
		}
	}else{
		return false;
	}
}
