﻿$(document).ready(function() {

	$(".external").click(function(e) { e.preventDefault(); window.open($(this).attr("href")); });
	$(".external-link").click(function(e) { e.preventDefault(); window.open($(this).attr("href")); });
	$(".external-menu").click(function(e) { e.preventDefault(); window.open($(this).attr("href")); });

    $("#pertodevoce, #abraumgrupo, #sejaescoteiro").equalizeCols();


    $("#EscolheEstado1").change(function(){
      if($(this).val() != 0)
      {
          $("#EscolheCidade1").html('<option value="">Procurando cidades...</option>');
          $.post('busca_cidades.php', { uf : $(this).val() }, function(resposta) {
            $("#EscolheCidade1").html(resposta);
            $("#EscolheCidade1").val('');
            });
      } else {
          $("#EscolheCidade1").html('');
      }
    });

    $("#EscolheEstado2").change(function(){
      if($(this).val() != 0)
      {
          $("#EscolheCidade2").html('<option value="">Procurando cidades...</option>');
          $.post('busca_cidades.php', { uf : $(this).val() }, function(resposta) {
            $("#EscolheCidade2").html(resposta);
            $("#EscolheCidade2").val('');
            });
      } else {
          $("#EscolheCidade2").html('');
      }
    });

	//AUMENTAR E DIMINUIR FONTE
	var pc = 100;

	if (($.cookie("font-modify")) != undefined) {
		pc  = ($.cookie("font-modify"))*1;
		setFontSize(pc);
	} else {
		$.cookie('font-modify', '100', { expires: 7, path: '/', secure: true });
	}

	// Reset Font Size
	$(".fonte-menos").click(function(){
		if (pc > 90) { pc -= 10; } else { pc = 90; }
		setFontSize(pc);
		return false;
	});
	// Decrease Font Size
	$(".fonte-mais").click(function(){
		if (pc < 180) { pc += 10; } else { pc = 180; }
		setFontSize(pc);
		return false;
	});

	function setFontSize(porc) {
		$('#coluna2').css('font-size', pc+"%");
		$.cookie("font-modify",pc);
	}

    $('.styleswitch').click(function()
    {
        var estilo = this.getAttribute("rel")
        if($.cookie("style") == estilo)
        {
            switchStylestyle(estilo,'off');
        } else {
            switchStylestyle(estilo,'on');
        }
        return false;

    });
    var c = $.cookie('style');
    if (c) switchStylestyle(c);

    $('#chamadas-box-dir DIV A').mouseover(function(e)
    {
        e.preventDefault();

        $("#chamadas-box-esq").html('<a href="'+$(this).attr("href")+'" title="'+$(this).attr("title")+'"><img src="'+$(this).attr("rel")+'" width="758" height="254" alt="'+$(this).attr("title")+'" title="'+$(this).attr("title")+'" /></a><div id="legenda"><div id="legenda-mg">'+$(this).attr("title")+'</div></div>');

        $('.chamadas-box-botao-ativo').addClass('chamadas-box-botao');
        $('.chamadas-box-botao-ativo').removeClass('chamadas-box-botao-ativo');

        $(this).parent().parent().addClass('chamadas-box-botao-ativo');
        $(this).parent().parent().removeClass('chamadas-box-botao');

    });

    $(".jumplocal").change(function() {
      var val = $(this).val();
      if (val != '') { location.href = val; }
    });

    $(".jumpexternal").change(function() {
      var val = $(this).val();
      if (val != '') { window.open(val); }
    });

});


function switchStylestyle(styleName,action)
{
    //$('link[@rel*=style][title]').each(function(i){})        this.disabled = true;;

    if(action=='on')
    {
        if (this.getAttribute('title') == styleName) this.disabled = false;
        $.cookie('style', styleName, { expires: 7, path: '/', secure: true });
    } else {
        if (this.getAttribute('title') == styleName) this.disabled = true;
        $.cookie('style', styleName, { expires: 7, path: '/', secure: false });
    }


}

function estado(uf) { location.href = "estado.php?estado="+uf; }
