$(function(){
    $('.slideshow1').cycle({
        fx: 'turnDown',
        delay: -4000
    });
    $('.slideshow2').cycle({
        fx: 'fade',
        delay: -2000
    });
    $('.slideshow3').cycle({
        fx: 'turnUp',
        delay: -1000
    });
    $('.slideshow4').cycle({
        fx: 'curtainX',
        delay: -4000
    });
    $('.slideshow5').cycle({
        fx:     'scrollRight',
        delay:  -2000
    });
    $('.slideshowNovoAcordo').cycle({
        fx:     'shuffle',
        delay:  -1000
    });

    if ($("#frmEmail").get(0)) {
        $("#btnEnviar").click(function(){
            var valid = '';
            var isr = ' - campo obrigatório.';
            var destinatario = $("#destinatario").val();
            var remetente = $("#remetente").val();
            var assunto = $("#assunto").val();
            var mensagem = $("#mensagem").val();

            if (!remetente.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
                valid += '<br />Informe um e-mail válido.'+isr;
                $("#remetente").addClass('fundoVerm');
            }
            if (assunto.length<1) {
                valid += '<br />Assunto'+isr;
                $("#assunto").addClass('fundoVerm');
            }
            if (mensagem.length<1) {
                valid += '<br />Mensagem'+isr;
                $("#mensagem").addClass('fundoVerm');
            }
            if (valid!='') {
                $("#response").addClass('msgErro');
                //                $("#response").html("Erro: O(s) campo(s) em vermelho é(são) obrigatório(s).");
                $("#response").fadeIn(5000);
                $("#response").html("Erro: Verifique o(s) campo(s) em vermelho"+valid);
            }
            else {
                var datastr = $("#frmEmail").serialize();

                $("#response").css("display", "block");

                $("#response").removeClass('msgErro');
                $("#remetente").removeClass('fundoVerm');
                $("#assunto").removeClass('fundoVerm');
                $("#mensagem").removeClass('fundoVerm');

                $("#response").addClass('msgAtencao');
                $("#response").html("Enviando mensagem .... ");
                $("#response").fadeIn("slow");
                setTimeout("send('"+datastr+"')",2000);
            }
            return false;
        });
    }

    // Leitura
    if($("a[rel^='prettyPhoto1']").get(0)) {
        $("a[rel^='prettyPhoto1']").prettyPhoto({
            theme:'facebook',
            social_tools: false,
            show_title: false,
            slideshow: false
        });
    }

    // Bloco Vídeo
    if($("a[rel^='prettyPhoto2']").get(0)) {

        $("a[rel^='prettyPhoto2']").prettyPhoto({
            theme:'facebook',
            social_tools: false,
            show_title: true,
            slideshow: false
        });

        $("a[class^='video']").each(function(){
            $( "#dialog_"+this.id ).dialog({
                autoOpen: false,
                show: "blind",
                hide: "explode"
            });
        });

        $("a[class^='video']").hover(
            function () {
                $("#dialog_"+this.id).dialog('open');
              },
              function () {
                $("#dialog_"+this.id).dialog('close');
              }
        );
    }
    
    // Bloco Vídeo Novo Acordo
    if($("a[rel^='prettyPhoto3']").get(0)) {
        $("a[rel^='prettyPhoto3']").prettyPhoto({
            theme:'facebook',
            social_tools: false,
            show_title: true,
            slideshow: false
        });
    }
    // Bloco Vídeo Alunos
    if($("a[rel^='prettyPhoto4']").get(0)) {
        $("a[rel^='prettyPhoto4']").prettyPhoto({
            theme:'facebook',
            social_tools: false,
            show_title: true,
            slideshow: false
        });
    }

});// fecha jquery

/*
 *Função para Enviar Email
 **/
function send(datastr){
    $.ajax({
        type: "POST",
        url: "email.php",
        data: datastr,
        cache: false,
        success: function(html){
            $("#response").removeClass('msgErro');
            $("#response").removeClass('msgAtencao');
            $("#response").addClass('msgConfirma');
            $("#response").fadeIn("slow");
            $("#response").html(html);
            setTimeout('$("#response").fadeOut("slow")',2000);
            clear_form_elements('#frmEmail');
        }
    });
}

function clear_form_elements(ele) {
    $(ele).find(':input').each(function() {
        switch(this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
            case 'textarea':
                $(this).val('');
                break;
            case 'checkbox':
            case 'radio':
                this.checked = false;
        }
    });
}
