﻿ // @Bruno Rodrigues da silva - Desenvolvedor Front-end
// @QUAY - Menu control - Static Version 1.0

(function ($) {
    $.fn.QUAY_navbar = function () {

        //configs
        var qnt = $(".lista > li").size();
        var element = $(this);
        var switcher_FW;
        var elementos;
        var sobraWindow;
        var calculations;

        var elementos_uso = Array;

        $(".banner-box").before("<div class='aqui'>");
        $(".aqui").css({ 'position': 'absolute', 'width': '100%' });
   

        //ajuste do tamanho do menu

        menuWidth(qnt);

        //criar botoes

        createButtons();

        //creiar os efeitos de bortão

        windowReference();

        function createButtons() {


            $(".aqui").html("<div class='btAfter left'></div><div class='btBefore right'></div>");


            //$('.centered').before('<li class="btAfter"></>');
//            $('.centered').after('<li class=""></>');

            //FORÇAR AS CONFIGURAÇÕES PARA IE7
            /* aqui
            $('btAfter').css("margin","176px -37px");
            $('btBefore').css("margin","176px -37px");
            */
            eventButtons();
        }


        function eventButtons() {



            $('.btAfter').click(function () {

                switcher_FW = element.children('.lista').children('li').eq(qnt - 1);

                //windowReference(switcher_FW);
                switchButtons('before', 'fim', element.children('.lista').children('.centered').index());


                elementos_uso[0] = element.children('.lista').children('li').eq(0).width();
                elementos_uso[1] = element.children('.lista').children('li').eq(1).width();
                elementos_uso[2] = element.children('.lista').children('li').eq(2).width();

                //soma dos tamanhos para usar como referência

                elementos = elementos_uso[0] + elementos_uso[1] + (elementos_uso[2] / 2);

                //encontra a diferença dos elementos a esquerda ocultos subtraídos ao tamanho da tela 

                elementos = ((elementos * 2) - $(window).width()) / 2;

                //prepara espaço para carregamento e ajuste de posição do meio

                element.animate({ marginLeft: [-(elementos), 'easeInOutQuad'] }, 1000, function () {


                    element.css('margin-left', parseInt(element.css('margin-left')) - (switcher_FW.width()));

                    element.children('.lista').children('li').eq(qnt).detach();

                    element.children('.lista').children('li').eq(0).before(switcher_FW);

                    createButtons();

                });
            });


            //fim do evento para esquerda 

            //função para troca de botões



            $('.btBefore').click(function () {


                switcher_FW = element.children('.lista').children('li').eq(0);

                switchButtons('after', 'inicio', element.children('.lista').children('.centered').index());


                elementos_uso[0] = element.children('.lista').children('li').eq(0).width();
                elementos_uso[1] = element.children('.lista').children('li').eq(1).width();
                elementos_uso[2] = element.children('.lista').children('li').eq(2).width();
                elementos_uso[3] = element.children('.lista').children('li').eq(3).width();
                elementos_uso[4] = element.children('.lista').children('li').eq(4).width();

                //soma dos tamanhos para usar como referência

                elementos = elementos_uso[0] + elementos_uso[1] + elementos_uso[2] + elementos_uso[3] + (elementos_uso[4] / 2);

                //encontra a diferença dos elementos a esquerda ocultos subtraídos ao tamanho da tela 

                elementos = ((elementos * 2) - $(window).width()) / 2;



                element.animate({ marginLeft: [(elementos * -1), 'easeInOutQuad'] }, 1000, function () {
                    

                    element.css('margin-left', (parseInt(element.css('margin-left')) + (switcher_FW.width())));

                    element.children('.lista').children('li').eq(0).detach();

                    element.children('.lista').children('li').eq(qnt - 2).after(switcher_FW);

                    createButtons();

                });

            });

        }

        function switchButtons(pos, eventBt, elementoAtual) {


            element.children('.lista').children('li').eq(elementoAtual).removeClass('centered');

            $('.btAfter').die('click');
            $('.btBefore').die('click');
            //retira os botões mantendo a lista certa
            $('.btAfter').detach();
            $('.btBefore').detach();


            if (eventBt == 'inicio') {
                element.children('.lista').children('li').eq(4).addClass('centered');
            }
            if (eventBt == 'fim') {
                element.children('.lista').children('li').eq(2).addClass('centered');
            }
        }

        function windowReference() {



            //Valor inicial da posição do banner

            elementos = element.children('.lista').children('li').eq(0).width() + element.children('.lista').children('li').eq(1).width() + element.children('.lista').children('li').eq(2).width() + (element.children('.lista').children('li').eq(4).width() / 2);
            elementos = ((elementos * 2) - $(window).width()) / 2;
            $('.menuBanner').css("margin-left", -elementos);
        }

        $(window).resize(function () {

            windowReference();

        });

        function menuWidth(qnt) {
            var newWidth = 0;
            var margins;
            for (itens = 0; itens <= qnt; itens++) {
                newWidth = newWidth + element.children('.lista').children('li').eq(itens).width();

            }

            //margens

            newWidth = newWidth + (qnt * 13);

            //seta tamanho das boxes de acordo com o que é necessário para o menu

            element.css('width', newWidth);

        }


        //carrega videos



        function carregaFilme(qual, quem, width, height) {

            //usar isto:

            /*<object width="199" height="1500" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
            <param name="Movie" value="/Files/Equipe.swf">
            <param name="play" value="true">
            <param name="quality" value="high">
            <param name="wmode" value="transparent">
            <param name="loop" value="false">
            <param name="menu" value="false"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" height="1500" width="199">
            <param name="Movie" value="/Files/Equipe.swf">
            <param name="play" value="true">
            <param name="quality" value="high">
            <param name="wmode" value="transparent">
            <param name="loop" value="false">
            <param name="menu" value="false"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" align="top" height="1500" width="199">
            <param name="Movie" value="/Files/Equipe.swf">
            <param name="play" value="true">
            <param name="quality" value="low">
            <param name="wmode" value="transparent">
            <param name="loop" value="false">
            <param name="menu" value="false">
            <param name="align" value="top"><embed style="vertical-align: top;" src="/Files/Equipe.swf" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="low" wmode="transparent" loop="false" menu="false" height="1500" width="199"><br>
            </object></object></object>
            */

            var playerContent = "<object width=" + width + " height=" + height + " data=/files/player.swf type=application/x-shockwave-flash id=f4Player><param name=wmode value=opaque /><param name=quality value=high /><param name=menu value=false /><param name=allowFullScreen value=true /><param name=scale value=noscale /><param name=allowScriptAccess value=always /><param name=swLiveConnect value=true /><param name=flashVars value=skin=/files/skins/mySkin.swf&thumbnail=video-thumbnail.jpg&video=" + qual + "&autoplay=1/></object>";

            $(quem).children(".contentMovie").html(playerContent);


            $(quem).animate({ opacity: 1 }, "fast");
            $(quem).parent().animate({ marginTop: -440 }, 'slow', function () {


                $(quem).children(".btCloseMovie").animate({ opacity: 1 }, "slow");

                $(quem).children(".btCloseMovie").click(function () {



                    $(this).animate({ opacity: 0 }, "slow");

                    $(quem).animate({ opacity: 0 }, "fast");

                    $(quem).parent().animate({ marginTop: 0 }, 'slow', function () {

                        $(quem).children('.contentMovie').html("");
                        if ($(quem).parent().hasClass("BannerMenu_CorretorGlobal")) {
                            $(".BannerMenu_CorretorGlobal").animate({ width: 294 }, '100', function () {
                                if ($(this).hasClass("centered")) {
                                    $(".menuBanner").animate({ marginLeft: (parseInt($(".menuBanner").css("margin-left")) + 200) }, 'slow')
                                }
                            });
                        }

                    });


                });


            });


        }

        $(".video3").live("click", function () {


            $(".BannerMenu_CorretorGlobal").animate({ width: 600 }, '100', function () {


                carregaFilme("/files/corretorGlobal.flv", ".player3", 600, 428);

                if ($(this).hasClass("centered")) {

                    $(".menuBanner").animate({ marginLeft: (parseInt($(".menuBanner").css("margin-left")) - 200) }, 'slow')
                }

            });

            return false;
        });

        $(".video2").live("click", function () {
            carregaFilme("/files/Mosarte.flv", ".player2", 656, 428);
            return false;
        });

        $(".video1").live("click", function () {


            carregaFilme("/files/Redimob.flv", ".player", 600, 428);


            return false;
        });


        //facebook like
        //www.google.com.br&layout=standard&locale=en_US&node_type=link&sdk=joey&send=false&show_faces=false&width=450

        $(".LikearButton").live("click", function () {


            $(this).html("<div class=Likearpopup><iframe src=" + $(this).attr("href") + "&show_faces=false width=275 frameborder=0></iframe></div>");
            $(this).children().delay(5000).fadeOut(500, function () {

                $(this).remove();

            });


            return false;

        });


        //google plus +1 futuramente forçar renderização póstuma


        gapi.plusone.render("plusone-redimob", { "size": "standard", "count": "false", "href": "http://www.quay.com.br/Solucoes/redessociaistematicas.aspx" });
        gapi.plusone.render("plusone-mosarte", { "size": "standard", "count": "false", "href": "http://www.quay.com.br/Solucoes/Casos_de_sucesso/mosarte/portais/website.aspx" });
        gapi.plusone.render("plusone-corretorGlobal", { "size": "standard", "count": "false", "href": "http://www.redimob.com.br/CorretorGlobal/" });
        gapi.plusone.render("plusone-Marisol", { "size": "standard", "count": "false", "href": "http://www.quay.com.br/Solucoes/Casos_de_sucesso/Marisol/portais/intranet.aspx" });
        gapi.plusone.render("plusone-Tractebel", { "size": "standard", "count": "false", "href": "http://www.quay.com.br/Solucoes/Casos_de_sucesso/Tractebel/portais/website.aspx" });
        gapi.plusone.render("plusone-Bardella", { "size": "standard", "count": "false", "href": "http://www.quay.com.br/Solucoes/Casos_de_sucesso/Bardella/portais/Website.aspx" });
        gapi.plusone.render("plusone-Bunge", { "size": "standard", "count": "false", "href": "http://www.quay.com.br/Solucoes/Casos_de_sucesso/bunge/portais/intranet.aspx" });

    };
})(jQuery)
