﻿$(document).ready(function () {
    if ($("._LabelImput").length > 0) {
        $("._LabelImput input").each(function () {
            if ($(this).val().length == 0)
                $(this).closest('._LabelImput').find('span').fadeIn('fast');

            $(this).bind({
                focus: function () {
                    $(this).closest('._LabelImput').find('span').fadeOut('fast');
                },
                blur: function () {
                    if ($(this).val().length == 0)
                        $(this).closest('._LabelImput').find('span').fadeIn('fast');
                }
            });
        });

        $("._LabelImput span").click(function () {
            $(this).fadeOut('fast');
            $(this).closest('._LabelImput').find('input').focus();
        });
    }

    $('._DisableEnter').keydown(function (e) {
        if (e.keyCode == 13) {
            return false;
        }
    });

    $(".Legenda").legenda({ cssout: false, cora: "" });

    if ($('#slider').length) {
        $('#slider').s3Slider({
            timeOut: 6000
        });
    }

    // Botão excluir
    if ($("._excluir").length > 0) {
        $("._excluir").click(function () {
            return confirm("VOCÊ REALMENTE QUER EXCLUIR ESSE(S) ITEM(NS)");
        });
    }

    // Checa formulario
    var Tipos = {
        branco: { retorno: function () { return (arguments[0].length > 0 ? true : false) } },
        email: { retorno: function () { return ValidaMail(arguments[0]); } },
        data: { retorno: function () { return ValidaData(arguments[0]); } },
        cpf: { retorno: function () { return ValidaCpf(arguments[0]); } },
        senha: { retorno: function () { return (arguments[0].length > 5 ? true : false); } },
        confirma: { retorno: function () { return (arguments[0] != $("._senha").val() ? false : true); } },
		Verifica: { retorno: function () { return (arguments[0] != $("._txtTelefone1").val() ? true : false); } },
        inscricao: { retorno: function () { return ($('._Enabled:checked').length ? true : false) } }
    };

    function ValidaRetorno() {
        var Lab = arguments[1]["id"];
        Lab = Lab.substring(Lab.lastIndexOf("_") + 1);

        if (arguments[0]) {
            $(".lbl_" + Lab).fadeOut();
            $("#lbl_" + Lab).fadeOut();
            $('#' + arguments[1]["id"]).css('border', '#CCCCCC solid 1px').removeClass('_Err');
        } else {
            $(".lbl_" + Lab).fadeIn();
            $("#lbl_" + Lab).fadeIn();
            $('#' + arguments[1]["id"]).css('border', '#ff0000 solid 1px').addClass('_Err');
            GotoErr();
        }
    }

    function GotoErr() {

        var target_offset = $("._Err").offset();
        var target_top = (target_offset.top);

        if ((target_top - $(window).scrollTop()) < 0)
            $('html, body').animate({ scrollTop: target_top - 35 }, 10);
    }

    if ($("._ValidaForm").length > 0) {
        $("._ValidaForm").ValidaForm({ validar: Tipos, retorno: ValidaRetorno });
    }

    if ($("._ValidaForm2").length > 0) {
        $("._ValidaForm2").ValidaForm({ validar: Tipos, retorno: ValidaRetorno });
    }

    if ($("._LstAbas").length > 0) {
        $("._LstAbas").each(function () {

            if ($(this).find("._Abas > li._Ativo").length == 0)
                $(this).find("._Abas > li:eq(0)").addClass("_Ativo");

            $(this).find("._Conteudo > li:eq(" + $(this).find("._Abas > li._Ativo").index() + ")").css('display', 'block');


            $(this).find("._Abas li").click(function () {
                if ($(this).attr("class").indexOf("_Ativo") == -1) {

                    $(this).closest("._Abas").find("li").removeClass("_Ativo");
                    $(this).addClass("_Ativo");

                    var IndexClick = $(this).index();
                    $(this).closest("._LstAbas").find("._Conteudo > li").css('display', 'none')
                    $(this).closest("._LstAbas").find("._Conteudo > li:eq(" + IndexClick + ")").css('display', 'block');


                }
            });
        });
    }

    $('.goTo').click(function () {
        var Go = $(this).attr('href');
        $(Go).fadeIn('slow', function () {
            var target_offset = $(this).offset();
            var target_top = (target_offset.top);
            $('html, body').animate({ scrollTop: target_top - 35 }, 500);
        });
        return false;
    });

    //Avaliação
    if ($('.StarCount').length > 0) {
        var Pts = new Array('Péssimo', 'Ruim', 'Regular', 'Bom', 'Ótimo');
        var Estrela = {
            Ativa: "2",
            Inativa: "1"
        };

        $('.StarCount').each(function () {
            var BlocoId = $(this).attr('id');

            $(this).append('<span style="margin-left:5px;color:#AA78B1"></span>')
            $(this).append('<input type="hidden" name="txt' + BlocoId + '" id="txt' + BlocoId + '" value="-1">');

            $('#' + BlocoId + ' img').bind({
                load: function () {
                    $(this).css('cursor', 'pointer');
                    $('#' + BlocoId + ' img').each(function (i) {
                        $(this).attr('alt', Pts[i]);
                        $(this).attr('title', Pts[i]);
                    });
                },
                mouseover: function () {
                    var Pos = $(this).index();
                    $(this).parent().find('span').html($(this).attr('title'));

                    $('#' + BlocoId + ' img').each(function (i) {
                        if (i <= Pos)
                            $(this).attr('src', $(this).attr('src').replace(Estrela.Ativa, Estrela.Inativa));
                    });
                },
                mouseout: function () {
                    var Cmp = $(this).parent().find('input').val();
                    var StarSet = (Cmp != undefined ? Cmp : -1);

                    if (StarSet < 0)
                        $(this).parent().find('span').html('');

                    $('#' + BlocoId + ' img').each(function (i) {
                        if (i > StarSet) {
                            $(this).attr('src', $(this).attr('src').replace(Estrela.Inativa, Estrela.Ativa));
                            $(this).parent().find('span').html(Pts[StarSet]);
                        }
                    });
                },
                click: function () {
                    $(this).parent().find('input').val($(this).index());
                }
            });
        });
    }

    /* Carrocel */
    if ($(".Carrocel").length > 0) {
        $(".Carrocel").jcarousel({
            visible: 3,
            scroll: 1,
            animation: 500,
            wrap: 'last',
            initCallback: mycarousel_initCallback,
            // This tells jCarousel NOT to autobuild prev/next buttons
            buttonNextHTML: null,
            buttonPrevHTML: null
        });
    }

    if ($(".Carrocel2").length > 0) {
        $(".Carrocel2").jcarousel({
            visible: 4,
            scroll: 1,
            animation: 500,
            wrap: 'last',
            initCallback: mycarousel_initCallback2,
            // This tells jCarousel NOT to autobuild prev/next buttons
            buttonNextHTML: null,
            buttonPrevHTML: null
        });
    }

    if ($(".Carrocel3").length > 0) {
        $(".Carrocel3").jcarousel({
            visible: 3,
            scroll: 1,
            animation: 500,
            wrap: 'last',
            initCallback: mycarousel_initCallback3,
            // This tells jCarousel NOT to autobuild prev/next buttons
            buttonNextHTML: null,
            buttonPrevHTML: null
        });
    }

    $('.gallery').lightBox();
    $('.galleryX').lightBox();
});

function mycarousel_initCallback(carousel) {
    jQuery('.Carrocel_next').bind('click', function () {
        carousel.next();
        return false;
    });

    jQuery('.Carrocel_prev').bind('click', function () {
        carousel.prev();
        return false;
    });
};

function mycarousel_initCallback2(carousel) {
    jQuery('.Carrocel_next2').bind('click', function () {
        carousel.next();
        return false;
    });

    jQuery('.Carrocel_prev2').bind('click', function () {
        carousel.prev();
        return false;
    });
};

function mycarousel_initCallback3(carousel) {
    jQuery('.Carrocel_next3').bind('click', function () {
        carousel.next();
        return false;
    });

    jQuery('.Carrocel_prev3').bind('click', function () {
        carousel.prev();
        return false;
    });
};

function ValidaAvaliacao() {
    var Arg = arguments
    var Retorno = true;
    for (var i in Arg) {
        if ($("#" + Arg[i]).length > 0)
            if ($("#" + Arg[i] + " > #txt" + Arg[i]).val() < 0)
                Retorno = false;
    }

    if (!Retorno)
        alert("Selecione uma avalaiação");

    return Retorno;
}

function AbaMove() {
    var Ths = arguments[0];
    var Pos = arguments[1];
    var tp = arguments[2];
    if ($(tp + Ths).length > 0) {
        $(tp + Ths).find("._Abas > li").removeClass("_Ativo");
        $(tp + Ths).find("._Abas > li:eq(" + Pos + ")").addClass("_Ativo");
        $(tp + Ths).find("._Conteudo > li").fadeOut(function () {
            $(tp + Ths).find("._Conteudo > li:eq(" + Pos + ")").fadeIn();
        });
    }
}
function toggle(div) {
    var maisinfo = document.getElementById(div);
    var video = document.getElementById("Video");

    switch (maisinfo.style.display) {
        case "none":
            maisinfo.style.display = "";
            video.style.display = "none";
            break;
        default:
            maisinfo.style.display = "none";
            video.style.display = "";
            break;
    }
    return false;
}

// MENU LATERAL
function menuShow(id) {
    var li = document.getElementById("mn" + id);
    switch (li.style.display) {
        case "none":
            li.style.display = "";
            break;
        default:
            li.style.display = "none";
            break;
    }
    return false;
}


var Ajax = {
    Request: function () {
        var valor = $.ajax({
            type: "POST",
            url: "server.aspx",
            dataType: "text",
            data: arguments[0],
            global: true,
            async: false,
            cache: false
        }).responseText;
        return valor;
    },
    ValidaCep: function () {
        var ret = eval('(' + this.Request({ tipo: "cep", cep: arguments[0] }) + ')');

        if (ret["RESULTADO"] == "0") {
            $('._cep').val('');
            alert('Cep Invalido!');
        }
        else {
            $('._endereco').val(ret['ENDERECO']);
            $('._bairro').val(ret['BAIRRO']);
            $('._cidade').val(ret['CIDADE']);
            $('._estado').val(ret['UF']);
        }
    }
};
   
