﻿var Site = {
    Init: function() {

        var areaAtiva;

        $('#header .holder .links-bar ul li:last').css('border', 0);

        $('#header .holder a.we-do-big-things').pulse({ speed: 1000, opacityRange: [0.6, 1] });

        openHeader = function(area) {
            areaAtiva = area;
            $('#header .holder .links-bar').slideUp(500, function() {
                $('#header .holder .close').show().animate({ top: '0px' }, { queue: false, duration: 700, easing: "swing" });
            });
            if(area == 'clientes'){
                $('#header').animate({ height: '563px' }, { queue: false, duration: 700, easing: "swing" });
            }else{
                $('#header').animate({ height: '260px' }, { queue: false, duration: 700, easing: "swing" });
            }
            setTimeout(function() { $('#header .holder #paginas #' + area).fadeIn(700); if (areaAtiva == "contato") { $('table.ajax__validatorcallout_popup_table').show(); } }, 1000);
        };

        closeHeader = function() {
            $('#header .holder .close').animate({ top: '-26px' }, 500, function() {
                $('#header .links-bar').slideDown(500);
            });
            $('table.ajax__validatorcallout_popup_table').hide();
            $('#header .holder #paginas #' + areaAtiva).fadeOut(500, function() {
                $('#header').animate({ height: '45px' }, { queue: false, duration: 700, easing: "swing" });
            });
        }

        $('#header .holder .close').click(function(event) {
            event.preventDefault();
            closeHeader();
        });

        $('#header .holder a.pngfix').click(function(event) {
            event.preventDefault();

            var openPage = $(this).attr('href');

            if (openPage == '#/Contato') {
                openHeader('contato');
            } else {
                if (openPage == '#/We-do-big-things') {
                    openHeader('things');
                } else {
                    if (openPage == '#/Sobre-a-Tribo-Interactive') {
                        openHeader('sobre');
                    } else {
                        if (openPage == '#/O-que-fazemos') {
                            openHeader('fazemos');
                        } else {
                            if (openPage == '#/Clientes') {
                                openHeader('clientes');
                            }
                        }
                    }
                }
            }

            return false;

        });

        //Busca por todos os links que possuem a classe '.external-modal' para abrir janela modal
        $('.external-modal').click(function() {
            var id = $(this).attr('id');
            var source = $(this).attr('href');
            var dimensoes = $(this).attr('rel');
            dimensoes = dimensoes.split('x');
            var w = dimensoes[0];
            var h = dimensoes[1];
            Site.Generics.OpenExternalModal(id, source, w, h);
            return false;
        });

        //String Format
        function _StringFormatInline() {
            var txt = this;
            for (var i = 0; i < arguments.length; i++) {
                var exp = new RegExp('\\{' + (i) + '\\}', 'gm');
                txt = txt.replace(exp, arguments[i]);
            }
            return txt;
        }
        function _StringFormatStatic() {
            for (var i = 1; i < arguments.length; i++) {
                var exp = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
                arguments[0] = arguments[0].replace(exp, arguments[i]);
            }
            return arguments[0];
        }
        if (!String.prototype.format) {
            String.prototype.format = _StringFormatInline;
        }
        if (!String.format) {
            String.format = _StringFormatStatic;
        }
    },
    Generics: {
        OpenExternalModal: function(id, source, w, h) {
            ModalWindow.windowId = id;
            ModalWindow.width = w;
            ModalWindow.height = h;
            ModalWindow.content = '<iframe width=\"' + w + '\" height=\"' + h + '\" frameborder=\"0\" scrolling=\"no\" allowtransparency=\"true\" src=\"' + source + '\"></iframe>';
            ModalWindow.Open();
        },
        FormsEffects: function() {
            $('input[type=text], textarea, select').focus(function() {
                $(this).addClass('on');
            });
            $('input[type=text], textarea, select').blur(function() {
                $(this).removeClass('on');
            });
        },
        Texts: {

    }
},
Home: function() {

    $('#projetos').anythingSlider({
        delay: 6000,
        animationTime: 1200
    }); /*

                    .find('.panel')
                    .find('div[class*=caption]').css({ position: 'absolute' }).end()
                    .hover(function() { showCaptions($(this)) }, function() { hideCaptions($(this)); });

            showCaptions = function(el) {
                var $this = el;
                if ($this.find('.caption-top').length) {
                    $this.find('.caption-top')
                            .show()
                            .animate({ top: 0, opacity: 1 }, 400);
                }
            };

            hideCaptions = function(el) {
                var $this = el;
                if ($this.find('.caption-top').length) {
                    $this.find('.caption-top')
                            .stop()
                            .animate({ top: -50, opacity: 0 }, 350, function() {
                                $this.find('.caption-top').hide();
                            });
                }
            };

            hideCaptions($('#slider1 .panel'));
        */
}
}
