$(document).ready(function() {

    $(document).mousemove(function(e) {
        $("#float").css('left' , (e.pageX - 200) + 'px');
        $("#float").css('top' , e.pageY +'px');

        $("#info-container").css('left' , (e.pageX - 300) + 'px');
        $("#info-container").css('top' , (e.pageY + 10) +'px');
    });


    $(".info").mouseover(function() {
        $("#info-container").html( ' <table><tr><td><span class="ui-icon ui-icon-info left info-container-icone "></span></td><td>' +  $(this).html() + '</td></tr></table>');
        $("#info-container").css('display' , 'block');
    });

    $(".info").mouseout(function() {
        $("#info-container").html('');
        $("#info-container").css('display' , 'none');
    });


    $("#topo-animacao-esquerda").cycle(
    {
        fx : "fade" ,
        pager : "#paginacao-animacao"
    }
    );

    $("#input-news-email").click(function() {
        $(this).val("");
    });


    $("div#paginacao-animacao a:eq(0)").html('<img src="../web/media/images/site/pag1.png" alt="pag1" title="1" /><br />');
    $("div#paginacao-animacao a:eq(1)").html('<img src="../web/media/images/site/pag2.png" alt="pag1" title="2" /><br />');
    $("div#paginacao-animacao a:eq(2)").html('<img src="../web/media/images/site/pag3.png" alt="pag1" title="3" /><br />');


    $("div#paginacao-animacao a:eq(0) img").mouseover(function() {
        $(this).attr('src', '../web/media/images/site/pag1-hover.png');
    });

    $("div#paginacao-animacao a:eq(0) img").mouseout(function() {
        $(this).attr('src', '../web/media/images/site/pag1.png');
    });

    $("div#paginacao-animacao a:eq(1) img").mouseover(function() {
        $(this).attr('src', '../web/media/images/site/pag2-hover.png');
    });

    $("div#paginacao-animacao a:eq(1) img").mouseout(function() {
        $(this).attr('src', '../web/media/images/site/pag2.png');
    });

    $("div#paginacao-animacao a:eq(2) img").mouseover(function() {
        $(this).attr('src', '../web/media/images/site/pag3-hover.png');
    });

    $("div#paginacao-animacao a:eq(2) img").mouseout(function() {
        $(this).attr('src', '../web/media/images/site/pag3.png');
    });

    $("#input-topo-busca").click(function() {
        if($(this).val() == "Buscar") {
            $(this).val("");
        }
    });

    $("span.hover").mouseover(function() {
        $(this).addClass('span-hover');
    });

    $("span.hover").mouseout(function() {
        $(this).removeClass('span-hover');
    });

    $(".lista-item").mouseover(function() {
        $(this).addClass('lista-hover');
    });
    $(".lista-item").mouseout(function() {
        $(this).removeClass('lista-hover');
    });

    $(".submit").mouseover(function() {
        $(this).addClass('submit-hover');
    });

    $(".submit").mouseout(function() {
        $(this).removeClass('submit-hover');
    });

    $(".select-redirect").change(function() {
        document.location.href = $(this).val();
    });

    $("#fonte-menor").click(function() {
        fonteMenor();
    });
    $("#fonte-maior").click(function() {
        fonteMaior();
    });
    $("#fonte-normal").click(function() {
        fonteNormal();
    });
    $("#fonte-destaque").click(function() {
        fonteDestaque();
    });


});

function showImgPreview(foto , elemento) {

    $("#float").stop(true,true);

    $('#float').css('display' , 'block');
    $('#float').css('opacity' , '0');

    $('#float').html('<img src="'+foto+'" alt="" />');

    $('#float').animate({
        opacity : 1
    } , 200 , '' , function() {

        });

    $(elemento).mouseout(function() {
        
        $('#float').animate({
            opacity : 0
        } , 200 , '' , function() {
            $('#float').html('');
            $('#float').css('display' , 'none');
        });
        
    });


}

function fecharJanela() {
    $("#janela").slideUp("fast");
}

function enviarParaUmAmigo() {
    exibirJanela();

    sf.ajaxLoad("ajax/enviar_para_um_amigo", "janela-conteudo");
}

function exibirJanela() {
    $("#janela").slideDown("fast");
}

function amplFotoImg(obj) {
    amplFoto($(obj).attr("alt") , "");
}


function getURL(href) {
    document.location.href= href;
}

function getUrl(href) {
    getURL(href);
}

function hide(element) {
    $(element.id).hide("slow");
}


function down(element) {
    $(element).slideDown("slow");
}

function up(element) {
    $(element).slideUp("slow");
}


function fecharFoto() {
    $("#cobreTudo").animate( {
        opacity :0,
        borderWidth :1
    }, 500, function() {
        $("#cobreTudo").hide();
    });

    $("#amplFotoDiv").animate({
        opacity:0
    } , 500 , 'linear' , function() {
        $("#amplFotoDiv").css("display" , "none");

    });

}



function validarContato() {
    var retorno = false;
    retorno =  validarFormulario( new Array('nome' , 'email' , 'mensagem'));
    return retorno;
}

function validarEnquete() {
    var retorno = false;
    retorno =  validarFormulario( new Array('nome' , 'email'));

    if(retorno) {
        if(!validarEmail($("#email").val())) {
            alert("Preencha um email válido");
            retorno = false;
        }
    }


    return retorno;
}


function  validarFormulario (campo) { //campo tem as IDs dos campos obrigatorios
    tamanho =  campo.length;
    var camp = campo;

    for(i=0;i<camp.length ; i++) {
        if(document.getElementById(camp[i]).value=='' || document.getElementById(camp[i]).value==null) {
            window.alert("Preencha o campo "+ camp[i].toUpperCase() );
            document.getElementById(camp[i]).style.border = "1px solid #C75F4E";
            document.getElementById(camp[i]).focus();

            return false;
        }
    }

    return true;
}

function validarBusca() {
    if($("#topo-form-busca").val() == "" || $("#topo-form-busca").val() == null) {
        $("#topo-form-busca").after().html("<div class='form-busca-erro'>Preencha um termo para busca</div>");
        return false;
    } else {
        return true;
    }

}

function enviarBusca() {
    if($("#topo-form-busca").val() != "buscar") {
        $("#form-busca").submit();
    } else {
        $("#topo-form-busca").focus();
        alert("Selecione algum termo para busca");
    }
    
}

function validarEmail(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;
    }
    return false;
}


function carregarCidades(estado) {

    $("#cidade").attr("disabled", "disabled");
    $("#cidade").html(
        "<option style='color: silver'>Carregando as cidades....</option>");

    $.post("carregar_cidades.ajax.php", {
        estado :estado
    }, function(data) {
        var valores = data.split(",");
        $("#cidade").html("");
        $("#cidade").attr("disabled", "");

        $("#cidade").append(
            "<option value=''>..:: Selecione uma Cidade ::..</option>");

        for (i = 0; i < valores.length; ++i) {

            nome = valores[i];
            i++;
            id = valores[i];

            $("#cidade").append(
                "<option value='" + id + "'>" + nome + "</option>");
        }
    

    });
}

/**
* Retorna TRUE caso value seja vazio
* 
* @param value String
* @return boolean
*/
function isEmpty(value) {
    
    var emptyCases = new Array("" , undefined , null);
    for(var i=0 ; i<emptyCases.length ; ++i) {
        if(value==emptyCases[i]) {
            return true;
        }
    }

    return false;

}


amplFotoArray = new Array();
amplFotoFotoAtual = 0;

function fotoProxima() {
    amplFotoFotoAtual = amplFotoFotoAtual + 1;

    if(amplFotoFotoAtual > amplFotoArray.length) {
        amplFotoFotoAtual = 0;
    }

    amplFoto(amplFotoArray[amplFotoFotoAtual][0] , amplFotoArray[amplFotoFotoAtual][1]);
}

function fotoAnterior() {

    if(amplFotoFotoAtual < 0) {
        amplFotoFotoAtual =  amplFotoArray.length;
    }

    amplFotoFotoAtual = amplFotoFotoAtual - 1;
    amplFoto(amplFotoArray[amplFotoFotoAtual][0] , amplFotoArray[amplFotoFotoAtual][1]);
}

function amplFotoGaleria(foto , legenda , index ) {
    amplFotoFotoAtual = index;
    amplFoto(foto , legenda )
}




var atualFonteSize = 13;
var defaultFonteSize = 12;
var maxFontSize = 24;

function fonteMaior() {
    atualFonteSize = atualFonteSize + 2;

    if(atualFonteSize >= maxFontSize) {
        atualFonteSize = maxFontSize;
    }

    $("Body , div , span , p , a , label , td , tr , th , h1 , h2 , h3 , h4").css("font-size", (atualFonteSize)+ "px");
    $('#alterarFontes div').css('fontSize' , defaultFonteSize);
}

function fonteNormal() {
    atualFonteSize = 13;
    $("Body , div , span , p , a , label , td , tr , th , h1 , h2 , h3 , h4").css("font-size", "");
    $('#alterarFontes div').css('fontSize' , defaultFonteSize);
}

function fonteMenor() {
    atualFonteSize = atualFonteSize - 2;
    $("Body , div , span , p , a , label , td , tr , th , h1 , h2 , h3 , h4").css("font-size", (atualFonteSize)+ "px");
    $('#alterarFontes div').css('fontSize' , defaultFonteSize);
}

function fonteDestaque() {
    $("#root *").css('background-color' , '#000');
    $("#root *").css('color' , '#fff');
}
