// carrossel página inicial
$(document).ready(function () {
    $('#slider').nivoSlider({
        effect: 'fade',
        animSpeed: 1000,
        pauseTime: 9000,
        directionNav: true,
        directionNavHide: false,
        controlNav: false,
        controlNavThumbs: false,
        controlNavThumbsFromRel: false,
        keyboardNav: false,
        pauseOnHover: true,
        manualAdvance: false,
        captionOpacity: 0.8
    });

    $('#search-nome-lojas').autocomplete('/Autocomplete', {
        dataType: 'json',
        width: 300,
        mustMatch: false,
        parse: function (data) {
            var rows = new Array();
            for (var i = 0; i < data.length; i++) {
                rows[i] = { data: data[i], value: data[i].slug, result: data[i].title };
            }
            return rows;
        },
        formatItem: function (row, i, n) {
            return row.title;
        }
    }).result(function (event, row) {
        location.href = "/lojas/" + row.sectionVO.slug + "/" + row.categoryVO.slug + "/" + row.slug; // navigate to the chosen URL
    });

    // destaques da capa

    $("#see-more").mouseover(function () {
        var id = $(this).attr('class');
        $('#content-' + id).show();
    });

    $(".content-highlight, #slider").mouseover(function () {
        return false;
    });

    $(document).mouseover(function (e) {
        if ($(e.target).parent("#see-more").length == 0) {
            $('.content-highlight').hide();
        }
    });

    // destaques da capa


    $(".lojas-nome").click(function () {
        $(".search-nome").toggle("fast");
    });

    if ($.browser.msie) {
        $("#destaques-splash .destaque-blog").hover(function () {
            $(".data .div-destaque-blog").hide();
            var id = $(this).attr('id');
            $("#destaque-blog-" + id).show();
        }, function () {
            var id = $(this).attr('id');
            $("#destaque-blog-" + id).hide();
        });
    } else {
        $("#destaques-splash .destaque-blog").hover(function () {
            $(".data .div-destaque-blog").hide();
            var id = $(this).attr('id');
            $("#destaque-blog-" + id).fadeIn();
        }, function () {
            var id = $(this).attr('id');
            $("#destaque-blog-" + id).fadeOut();
        });
    }

    $('.horarios').hide();
    $('#lojas').show();
    $('.local li').click(function () {
        var id = $(this).attr('href');
        $('.horarios').hide();
        $('#' + id).show();
        $('.local li').removeClass('active');
        $(this).addClass('active');
    });


    $(".bt-search-splash").mouseenter(function () {
        $(".input-search-splash").show("slow");
    });
    $("#search").mouseleave(function () {
        $(".input-search-splash").hide("slow");
    });

    $(".breve").mouseover(function () {
        $(this).show().text("EM  BREVE");
    });
    $(".vitrine").mouseout(function () {
        $(this).show().text("VITRINE IN").css("cursor", "default");
    });
    $(".clientes").mouseout(function () {
        $(this).show().text("ESPAÇO CLIENTES").css("cursor", "default");
    });

    $(".comment-post").mouseover(function () {
        $(this).css("background", "#a4bf96");
        $(this).children(".header").css("background-position", "0 -34px");
        $(this).children(".header").css("color", "#FFFFFF");
    });
    $(".comment-post").mouseout(function () {
        $(this).css("background", "none");
        $(this).children(".header").css("background-position", "0 0");
        $(this).children(".header").css("color", "#58694D");
    });

    $(".resultados-table .row").mouseover(function () {
        $(this).css("background", "#87444b");
        $(this).children(".nome").css("color", "#FFFFFF");
        $(this).children(".telefone").css("color", "#FFFFFF");
        $(this).children(".local").css("color", "#FFFFFF");
    });
    $(".resultados-table .row").mouseout(function () {
        $(this).css("background", "none");
        $(this).children(".nome").css("color", "#4C2D32");
        $(this).children(".telefone").css("color", "#454545");
        $(this).children(".local").css("color", "#454545");
    });

    $(".ficha-right .row").mouseover(function () {
        $(this).css("background", "#a4bf96");
    });
    $(".ficha-right .row").mouseout(function () {
        $(this).css("background", "none");
    });

    $(".blog .destaque-text1").mouseover(function () {
        $(this).css("background", "#723f44");
        $(this).children("a").css("color", "#FFFFFF");
        $(this).prev(".data").css("background-position", "-54px 0");
    });
    $(".blog .destaque-text1").mouseout(function () {
        $(this).css("background", "none");
        $(this).children("a").css("color", "#454545");
        $(this).prev(".data").css("background-position", "0 0");
    });

    $(".shadow-imprensa .destaque-text1").mouseover(function () {
        $(this).css("background", "#58694d");
        $(this).children("a").css("color", "#FFFFFF");
        $(this).prev(".data").css("background-position", "-54px 0");
    });
    $(".shadow-imprensa .destaque-text1").mouseout(function () {
        $(this).css("background", "none");
        $(this).children("a").css("color", "#454545");
        $(this).prev(".data").css("background-position", "0 0");
    });

    $("#destaques-splash .destaque-text").mouseover(function () {
        $(this).css("background", "#723f44");
        $(this).children("a").css("color", "#FFFFFF");
        $(this).prev(".data").css("background-position", "-54px 0");
    });
    $("#destaques-splash .destaque-text").mouseout(function () {
        $(this).css("background", "none");
        $(this).children("a").css("color", "#454545");
        $(this).prev(".data").css("background-position", "0 0");
    });

    $(".resultados .resultado").mouseover(function () {
        $(this).css("background", "#59694e");
        $(this).find(".result-section").css("color", "#FFFFFF");
        $(this).find(".result-title a").css("color", "#FFFFFF");
    });
    $(".resultados .resultado").mouseout(function () {
        $(this).css("background", "none");
        $(this).find(".result-section").css("color", "#5D6556");
        $(this).find(".result-title a").css("color", "#454545");
    });

    $("#header-top .lojas-segmento").click(function () {
        $(".busca-segmento-splash").fadeToggle("slow", "linear");
    });

    $(".close-email").click(function () {
        $(this).parent("#envio-email").hide();
    });
    $(".close-email").click(function () {
        $(this).parent("#feedback-email-ok").hide();
    });
    $(".close-email").click(function () {
        $(this).parent("#feedback-email-erro").hide();
    });
    $(".close-email").click(function () {
        $(this).parent("#newsletter-erro").hide();
    });
    $(".close-email").click(function () {
        $(this).parent("#newsletter-ok").hide();
    });

    $(".img-envio-email").live("click", function () {
        $(this).next("#envio-email").toggle();
    });

    $("#buscanome").click(function () {
        var originalValue = $(this).attr('value');
        if ($(this).val() == "BUSCA por NOME") {
            $(this).attr('value', '');
        }
        onBlur($(this), originalValue);
    });
    $("#seunome").click(function () {
        var originalValue = $(this).attr('value');
        if ($(this).val() == "Nome de quem envia") {
            $(this).attr('value', '');
        }
        onBlur($(this), originalValue);
    });
    $("#seuemail").click(function () {
        var originalValue = $(this).attr('value');
        if ($(this).val() == "E-mail de quem envia") {
            $(this).attr('value', '');
        }
        onBlur($(this), originalValue);
    });
    $("#nomeamigo").click(function () {
        var originalValue = $(this).attr('value');
        if ($(this).val() == "Nome de quem recebe") {
            $(this).attr('value', '');
        }
        onBlur($(this), originalValue);
    });
    $("#emailamigo").click(function () {
        var originalValue = $(this).attr('value');
        if ($(this).val() == "E-mail de quem recebe") {
            $(this).attr('value', '');
        }
        onBlur($(this), originalValue);
    });
    $("#nome-blog").click(function () {
        var originalValue = $(this).attr('value');
        if ($(this).val() == "Nome") {
            $(this).attr('value', '');
        }
        onBlur($(this), originalValue);
    });
    $("#email-blog").click(function () {
        var originalValue = $(this).attr('value');
        if ($(this).val() == "E-mail") {
            $(this).attr('value', '');
        }
        onBlur($(this), originalValue);
    });
    $("#comentario").click(function () {
        var originalValue = $(this).attr('value');
        if ($(this).val() == "Escreva aqui o seu comentário") {
            $(this).attr('value', '');
        }
        onBlur($(this), originalValue);
    });
    $("#comentario").attr('value', 'Escreva aqui o seu comentário');
    $("#searchblog").attr('value', 'BUSCA no BLOG');
    $("#searchimprensa").attr('value', 'BUSCA por RELEASES');
    $(".blog #nome-blog").attr('value', 'Nome');
    $(".blog #email-blog").attr('value', 'E-mail');
    $(".blog #nome-blog").click(function () {
        var originalValue = $(this).attr('value');
        if ($(this).val() == "Nome") {
            $(this).attr('value', '');
        }
        onBlur($(this), originalValue);
    });
    $(".blog #email-blog").click(function () {
        var originalValue = $(this).attr('value');
        if ($(this).val() == "E-mail") {
            $(this).attr('value', '');
        }
        onBlur($(this), originalValue);
    });
    $(".blog #comentario").click(function () {
        var originalValue = $(this).attr('value');
        if ($(this).val() == "Escreva aqui o seu comentário") {
            $(this).attr('value', '');
        }
        onBlur($(this), originalValue);
    });
    $("#searchblog").click(function () {
        var originalValue = $(this).attr('value');
        if ($(this).val() == "BUSCA no BLOG") {
            $(this).attr('value', '');
        }
        onBlur($(this), originalValue);
    });
    $("#searchimprensa").click(function () {
        var originalValue = $(this).attr('value');
        if ($(this).val() == "BUSCA por RELEASES") {
            $(this).attr('value', '');
        }
        onBlur($(this), originalValue);
    });

    function onBlur(currentInput, originalValue) {
        $(currentInput).blur(function () {
            if ($(currentInput).attr('value') == "") {
                $(currentInput).attr('value', originalValue);
            }
        });
    }

    $('.content-iguatemi-people .pictures a').lightBox({
        overlayOpacity: 0.9,
        imageLoading: '/Content/Images/lightbox-ico-loading.gif',
        imageBtnClose: '/Content/Images/close-lightbox.png',
        imageBtnPrev: '/Content/Images/left-arrow-lightbox.png',
        imageBtnNext: '/Content/Images/right-arrow-lightbox.png',
        imgIguatemiPeople: '/Content/Images/iguatemi_people_lightwindow.png',
        containerResizeSpeed: 350,
        fixedNavigation: true
    });

    $('.lightbox-loja a').lightBox({
        overlayOpacity: 0.9,
        imageLoading: '/Content/Images/lightbox-ico-loading.gif',
        imageBtnClose: '/Content/Images/close-lightbox.png',
        imageBtnPrev: '/Content/Images/left-arrow-lightbox.png',
        imageBtnNext: '/Content/Images/right-arrow-lightbox.png',
        imgIguatemiPeople: '/Content/Images/pixel.png',
        containerResizeSpeed: 350,
        fixedNavigation: true
    });
    $('.destaques-shopping a').lightBox({
        overlayOpacity: 0.9,
        imageLoading: '/Content/Images/lightbox-ico-loading.gif',
        imageBtnClose: '/Content/Images/close-lightbox.png',
        imageBtnPrev: '/Content/Images/left-arrow-lightbox.png',
        imageBtnNext: '/Content/Images/right-arrow-lightbox.png',
        imgIguatemiPeople: '/Content/Images/pixel.png',
        containerResizeSpeed: 350,
        fixedNavigation: true
    });
    $('.galeria-em-cartaz a.lightbox').lightBox({
        overlayOpacity: 1,
        imageLoading: '/Content/Images/lightbox-ico-loading.gif',
        imageBtnClose: '/Content/Images/close-lightbox.png',
        imageBtnPrev: '/Content/Images/left-arrow-lightbox.png',
        imageBtnNext: '/Content/Images/right-arrow-lightbox.png',
        imgIguatemiPeople: '/Content/Images/pixel.png',
        containerResizeSpeed: 350,
        fixedNavigation: true
    });

    // Em Cartaz
    $(".em-cartaz-list .image").mouseover(function () {
        $(this).find("p.filme-ver-detalhes").show();
    });
    $(".em-cartaz-list .image").mouseout(function () {
        $(this).find("p.filme-ver-detalhes").hide();
    });

    // Estrelas - Dê nota ao filme
    /*$(".shadow-right .estrelas img").mouseover(function() { 
    $(this).css("background-position","0px -17px");
    });
    $(".shadow-right .estrelas img").mouseout(function() { 
    $(this).css("background-position","0px 0px");
    });*/

    $("p.ver-critica").click(function () {
        $("#show-critica").show();
    });
    $(".close-critica").click(function () {
        $(this).parent("#show-critica").hide();
    });

    $(".clipping").mouseover(function () {
        $(this).css("background", "#502b32");
        $(this).children(".date").css("color", "#829b71");
        $(this).children(".title").css("color", "#FFFFFF");
        $(this).children(".title").find("a").css("color", "#FFFFFF");
    });
    $(".clipping").mouseout(function () {
        $(this).css("background", "none");
        $(this).children(".date").css("color", "#4D4F44");
        $(this).children(".title").css("color", "#4F2C32");
        $(this).children(".title").find("a").css("color", "#4F2C32");
    });

    $(".release").mouseover(function () {
        $(this).css("background", "#502b32");
        $(this).children(".date").css("color", "#829b71");
        $(this).children(".title").css("color", "#FFFFFF");
        $(this).children(".title").find("a").css("color", "#FFFFFF");
    });
    $(".release").mouseout(function () {
        $(this).css("background", "none");
        $(this).children(".date").css("color", "#4D4F44");
        $(this).children(".title").css("color", "#4F2C32");
        $(this).children(".title").find("a").css("color", "#4F2C32");
    });

    $(".filtro-select").click(function () {
        $("#show-filtro-gourmet").toggle();
    });

    var windowHeight = $('#conteiner-internas').height();
    var windowWidth = $('#conteiner-internas').width();
    $('.overlay-div').width(windowWidth).height(windowHeight).show();

    $(".overlay-div").css("display", "none");
    $("#destaques-splash .div1.darkred a").click(function () {
        $(".iframe").show();
        $(".overlay-div").show();
        $('.close-iframe').show();
    });

    $(".overlay-div").live("click", function () {
        $(this).hide();
        $(".iframe").hide();
        $('.close-iframe').hide();
        $("#regulamento-kids").hide();
    });

    $('.close-iframe').live("click", function () {
        $('.overlay-div').hide();
        $('.iframe').hide();
        $(this).hide();
    });


    $(".vagas .box-vaga").mouseover(function () {
        $(this).css("background", "#503234");
        $(this).find("p").css("color", "#FFFFFF");
        $(this).find("p.titulo-vaga").css("color", "#a3be95");
        $(this).find("p.vagas-email").css("color", "#a3be95");
        $(this).find("p.vagas-email a").css("color", "#a3be95");
    });
    $(".vagas .box-vaga").mouseout(function () {
        $(this).css("background", "none");
        $(this).find("p").css("color", "#454545");
        $(this).find("p.titulo-vaga").css("color", "#503235");
        $(this).find("p.vagas-email").css("color", "#454545");
        $(this).find("p.vagas-email a").css("color", "#454545");
    });

    /* Agenda */
    $(".agenda-select").click(function () {
        $("#show-options-agenda").toggle();
    });
    $(".close-agenda-details").click(function () {
        $(this).parent("#show-agenda-details").hide();
    });

    /* Kids */
    $(".kidss .selecione-data").click(function () {
        $("#select-kids").toggle();
    });

    $("#select-kids p").mouseover(function () {
        $(this).css("background", "#96a68b");
    });
    $("#select-kids p").mouseout(function () {
        $(this).css("background", "#6b815d");
    });

    $("a img.baixar-foto").mouseover(function () {
        $(this).next(".tip-baixar-foto").fadeIn("fast");
    });
    $("a img.baixar-foto").mouseout(function () {
        $(this).next(".tip-baixar-foto").fadeOut("fast");
    });

    $(".foto-kid .visualizar a").mouseover(function () {
        $(this).next(".foto-kid .visualizar p").fadeIn("fast");
    });
    $(".foto-kid .visualizar a").mouseout(function () {
        $(this).next(".foto-kid .visualizar p").fadeOut("fast");
    });

    $(".foto-kid").mouseover(function () {
        $(this).find(".shadow-foto-kid").show();
    });
    $(".foto-kid").mouseout(function () {
        $(this).find(".shadow-foto-kid").hide();
    });

    $(".kidss .consulte .green").click(function () {
        $("#regulamento-kids").show();
        $(".overlay-div").css("display", "block");
    });
    $(".close-regulamento").click(function () {
        $(this).parent("#regulamento-kids").hide();
        $(".overlay-div").hide();
    });

});

function _center_overlay() {
    var scroll_pos = _get_scroll();
    var contentHeight = 470;
    var contentwidth = 800;

    var windowHeight = $(window).height();
    var windowWidth = $(window).width();

    var projectedTop = (windowHeight / 2) + scroll_pos['scrollTop'];
    var projectedLeft = (windowWidth / 2) + scroll_pos['scrollLeft'];
    if (projectedTop < 0) projectedTop = 0;

    if (contentHeight > windowHeight)
        return;

    $('.show-agenda').css({
        'top': projectedTop,
        'left': projectedLeft
    });

};

function _get_scroll() {
    if (self.pageYOffset) {
        return { scrollTop: self.pageYOffset, scrollLeft: self.pageXOffset };
    } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
        return { scrollTop: document.documentElement.scrollTop, scrollLeft: document.documentElement.scrollLeft };
    } else if (document.body) {// all other Explorers
        return { scrollTop: document.body.scrollTop, scrollLeft: document.body.scrollLeft };
    };
};

