$(document).ready(function() {
    if ($.browser.msie && ($.browser.version < 7)) { $("body").addClass("ie"); DD_belatedPNG.fix(".fix"); }
    $("#wrapper").each(function() {
        if ($(this).height() < ($(window).height() - 96)) {
            $(this).height($(window).height() - 96);
        }
    });
    $("#footer").css("position", "relative");
    $(".equal").equalHeight();
    $("#right").contentHeight();

    $("#PassatempoCriadores_HomeMenu").each(function() {
        var userID = ($(this).attr("rel").split("|")[0]) ? $(this).attr("rel").split("|")[0] : "";
        var userImageID = ($(this).attr("rel").split("|")[1]) ? $(this).attr("rel").split("|")[1] : "";
        var swfVersionStr = "10.0.0";
        var xiSwfUrlStr = "/portalnestle/passatempo/swf/playerProductInstall.swf";
        var flashvars = {};
        var params = {};
        var attributes = {};
        var url = window.location.href;
        var menu = '';
        if (url.indexOf("/meus-passatempos/") != -1) {
            var menu = 'meuspassatempos';
        } else if ((url.indexOf("/criar-mais-um/") != -1)) {
            var menu = 'criar';
        } else if ((url.indexOf("/busca/") != -1)) {
            var menu = 'jogos';
        } else if ((url.indexOf("/ajuda/") != -1)) {
            var menu = 'ajuda';
        } else if ((url.indexOf("/mundo-dos-pais/") != -1)) {
            var menu = 'mundodospais';
        } else {
            var menu = 'home';
        }

        flashvars.basepath = "/portalnestle/passatempo/";
        flashvars.config = "{basepath}xml/home.app.xml";
        flashvars.navigateMethod = "loadContent";
        flashvars.resizeMethod = "resize";
        flashvars.completeMethod = "complete";
        flashvars.mundoDosPais = "/portalnestle/passatempo/mundo-dos-pais/Default.aspx";
        flashvars.userID = userID;
        flashvars.userImageID = userImageID;
        if (!$("body").hasClass("home")) {
            flashvars.mode = "closed";
        } else {
            flashvars.navigate = "false";
        }
        flashvars.menu = menu;
        flashvars.logMethod = "log";
        flashvars.functionTag = "gaFlash";

        params.quality = "autohigh";
        params.bgcolor = "#000000";
        params.allowscriptaccess = "sameDomain";
        params.allowfullscreen = "true";
        params.wmode = 'transparent';

        attributes.id = "PassatempoCriadores_HomeMenu";
        attributes.name = "PassatempoCriadores_HomeMenu";
        attributes.align = "middle";
        attributes.redirectURL = "http://www.nestle.com.br/";

        //$height = ($("body").hasClass("home")) ? $("#left").height() : "3000";
        swfobject.embedSWF("/portalnestle/passatempo/swf/PassatempoCriadores_HomeMenu.swf", "PassatempoCriadores_HomeMenu", "100%", "100%", swfVersionStr, xiSwfUrlStr, flashvars, params, attributes);
        SWFAddress.addId(attributes.id);
    });

    $("#flashHome").each(function() {
        $userID = ($(this).attr("rel").split("|")[0]) ? $(this).attr("rel").split("|")[0] : '';
        $userImageID = ($(this).attr("rel").split("|")[1]) ? $(this).attr("rel").split("|")[1] : '';
        $totalGames = ($(this).attr("rel").split("|")[2]) ? $(this).attr("rel").split("|")[2] : '1';
        $q = ($.getUrlVar("q")) ? $.getUrlVar("q") : '';
        $a = ($.getUrlVar("a")) ? $.getUrlVar("a") : '';
        $b = ($.getUrlVar("b")) ? $.getUrlVar("b") : '';
        $c = ($.getUrlVar("c")) ? $.getUrlVar("c") : '';
        $d = ($.getUrlVar("d")) ? $.getUrlVar("d") : '';
        $m0 = ($.getUrlVar("m0")) ? $.getUrlVar("m0") : '';
        $m1 = ($.getUrlVar("m1")) ? $.getUrlVar("m1") : '';
        $o = ($.getUrlVar("o")) ? $.getUrlVar("o") : '';
        $win = /Win/.test(navigator.platform);
        $swf = ($.browser.mozilla && $win) ? 'HomeAssets_ff.swf' : 'HomeAssets.swf';
        $(this).flash({ src: '/portalnestle/passatempo/swf/' + $swf, width: 782, height: 600, wmode: 'transparent', scale: 'noscale', quality: 'autohigh', salign: 'L',
            flashvars: {
                userID: [$userID].join(' '),
                userImageID: [$userImageID].join(' '),
                serverPath: ['/portalnestle/passatempo/'].join(' '),
                basePath: ['/portalnestle/passatempo/'].join(' '),
                busca: ['/portalnestle/passatempo/busca/Default.aspx'].join(' '),
                target: ['_top'].join(' '),
                totalGames: [$totalGames].join(' '),
                q: [unescape($q)].join(' '),
                a: [$a].join(' '),
                b: [$b].join(' '),
                c: [$c].join(' '),
                d: [$d].join(' '),
                m0: [$m0].join(' '),
                m1: [$m1].join(' '),
                o: [$o].join(' '),
                functionTag: ["gaFlash"].join(' ')
            }
        },
	{ version: 10 });
    });

    $("#flashCriar").each(function() {
        $idUser = $.trim($(this).attr("rel").split("|")[0]);
        $idGame = $.trim($(this).attr("rel").split("|")[1]);
        $.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
        $wmode = ($.browser.chrome) ? 'window' : 'transparent';
        swfobject.embedSWF("/portalnestle/passatempo/swf/CreateLoader.swf", "flashCriar", "100%", "100%", "10.0.0", "", { idUser: $idUser, idGame: $idGame, functionTag: "gaFlash" }, { wmode: $wmode, scale: 'noscale', allowfullscreen: 'true' }, {});
        swffit.fit("flashCriar", 1000, 590);
    });

    $("#flashJogar").each(function() {
        $idUser = $(this).attr("rel").split("|")[0];
        $idGame = $(this).attr("rel").split("|")[1];
        swfobject.embedSWF("/portalnestle/passatempo/swf/GameLoader.swf", "flashJogar", "100%", "100%", "10.0.0", "", { idUser: $idUser, idGame: $idGame, functionTag: "gaFlash" }, { scale: 'noscale', allowfullscreen: 'true' }, { id: 'flashJogar', name: 'flashJogar' });
        swffit.fit("flashJogar", 1000, 590);
    });

    $("#flashProdutos").flash({ src: '/portalnestle/passatempo/swf/mundodospais_obiscoito.swf', width: 770, height: 540, wmode: 'transparent' }, { version: 10 });

    //$("#flashTutorial").flash({ src: '/portalnestle/passatempo/swf/tutorialPequeno/player_rapido.swf', width: 762, height: 400, wmode: 'transparent', quality: 'autohigh' }, { version: 10 });
    $("#flashTutorial, #flashComoCriar").flash({ src: '/portalnestle/passatempo/swf/player_tutorial.swf', width: 762, height: 340, wmode: 'transparent', quality: 'autohigh', flashvars: { urlVideo: ['/portalnestle/passatempo/swf/assets/flv/tutorial_video.flv'].join(' ')} }, { version: 10 });


    $("#flashBusca").each(function() {
        $q = ($.getUrlVar("q")) ? $.getUrlVar("q") : '';
        $a = ($.getUrlVar("a")) ? $.getUrlVar("a") : '';
        $b = ($.getUrlVar("b")) ? $.getUrlVar("b") : '';
        $c = ($.getUrlVar("c")) ? $.getUrlVar("c") : '';
        $d = ($.getUrlVar("d")) ? $.getUrlVar("d") : '';
        $m0 = ($.getUrlVar("m0")) ? $.getUrlVar("m0") : '';
        $m1 = ($.getUrlVar("m1")) ? $.getUrlVar("m1") : '';
        $o = ($.getUrlVar("o")) ? $.getUrlVar("o") : '';
        $(this).flash({ src: '/portalnestle/passatempo/swf/busca_menu.swf', width: 770, height: 260, wmode: 'window', flashvars: { targetPage: ['/portalnestle/passatempo/busca/Default.aspx'].join(' '), target: ['_top'].join(' '), q: [unescape($q)].join(' '), a: [$a].join(' '), b: [$b].join(' '), c: [$c].join(' '), d: [$d].join(' '), m0: [$m0].join(' '), m1: [$m1].join(' '), o: [$o].join(' '), functionTag: ["gaFlash"].join(' ')} }, { version: 10 });
    });

    $(".flashAvatar110x230").each(function() {
        $url = $(this).attr("rel");
        $(this).flash({ src: '/portalnestle/passatempo/swf/loader.swf', width: 110, height: 230, wmode: 'transparent', flashvars: { url: [$url].join(' '), functionTag: ["gaFlash"].join(' ')} }, { version: 10 });
    });

    $(".stats .criados").each(function() {
        $valor = $(this).attr("rel");
        $urlCFJ = (window.location.href.indexOf("/meus-passatempos/Default.aspx") != -1) ? 'javascript:clickNav("tabCriados")' : '/portalnestle/passatempo/meus-passatempos/Default.aspx?tab=tabCriados';
        $(this).flash({ src: '/portalnestle/passatempo/swf/placaresValor_criados.swf', width: 85, height: 74, wmode: 'transparent', flashvars: { valor: [$valor].join(' '), url: [$urlCFJ].join(' ')} }, { version: 10 });
    });

    $(".stats .favoritos").each(function() {
        $valor = $(this).attr("rel");
        $urlCFJ = (window.location.href.indexOf("/meus-passatempos/Default.aspx") != -1) ? 'javascript:clickNav("tabFavoritos")' : '/portalnestle/passatempo/meus-passatempos/Default.aspx?tab=tabFavoritos';
        $(this).flash({ src: '/portalnestle/passatempo/swf/placaresValor_favoritos.swf', width: 85, height: 74, wmode: 'transparent', flashvars: { valor: [$valor].join(' '), url: [$urlCFJ].join(' ')} }, { version: 10 });
    });

    $(".stats .jogados").each(function() {
        $valor = $(this).attr("rel");
        $urlCFJ = (window.location.href.indexOf("/meus-passatempos/Default.aspx") != -1) ? 'javascript:clickNav("tabJogados")' : '/portalnestle/passatempo/meus-passatempos/Default.aspx?tab=tabJogados';
        $(this).flash({ src: '/portalnestle/passatempo/swf/placaresValor_jogados.swf', width: 85, height: 74, wmode: 'transparent', flashvars: { valor: [$valor].join(' '), url: [$urlCFJ].join(' ')} }, { version: 10 });
    });

    $(".infoNivel .flash").each(function() {
        $nivel = $(this).attr("rel");
        $(this).flash({ src: '/portalnestle/passatempo/swf/iconeNivel.swf', width: 67, height: 26, wmode: 'transparent', flashvars: { nivel: [$nivel].join(' ')} }, { version: 10 });
    });

    $(".boxDescItem .game .flash").each(function() {
        $jogaram = $(this).attr("rel").split("|")[0];
        $curtiram = $(this).attr("rel").split("|")[1];
        $pjogaram = $(this).attr("rel").split("|")[2];
        $pcurtiram = $(this).attr("rel").split("|")[3];
        $avatar = $(this).attr("rel").split("|")[4];
        $(this).flash({ src: '/portalnestle/passatempo/swf/descGame.swf', width: 240, height: 77, wmode: 'transparent', flashvars: { jogaram: [$jogaram].join(' '), curtiram: [$curtiram].join(' '), pjogaram: [$pjogaram].join(' '), pcurtiram: [$pcurtiram].join(' '), avatar: [$avatar].join(' ')} }, { version: 10 });
    });

    $("#flashCriarAvatar").each(function() {
        $userID = $(this).attr("rel").split("|")[0];
        $gender = $(this).attr("rel").split("|")[1];
        $selectedGender = ($gender == "F") ? "girl" : "boy";
        $(this).flash({ src: '/portalnestle/passatempo/swf/PassatempoCriadores_CriarAvatar.swf', width: 770, height: 450, wmode: 'transparent', flashvars: {
            userID: [$userID].join(' '),
            selectedGender: [$selectedGender].join(' '),
            config: ['/portalnestle/passatempo/xml/cfg/avatar.app.xml'].join(' '),
            basepath: ['/portalnestle/passatempo/'].join(' '),
            functionTag: ['gaFlash'].join(' ')
        }
        }, { version: 10 });
    });

    $("#flashQueMundo").flash({ src: '/portalnestle/passatempo/swf/queMundo.swf', width: 740, height: 540, wmode: 'transparent', flashvars: { functionTag: ["gaFlash"].join(' ')} }, { version: 10 });

    $(".b .infoNivel span.txt").html("Bam");
    $(".bb .infoNivel span.txt").html("Bam Bam");
    $(".bbb .infoNivel span.txt").html("Bam Bam Bam");

    $("ul.navSub li a").click(function() {
        $("ul.navSub li a").removeClass("hover");
        $tab = $(this).addClass("hover").attr("href");
        $(".boxProt .tab").hide().parent().find($tab).show();
        switch ($tab.split("#")[1]) {
            case 'tabFavoritos':
                paginarFavoritos(1);
                break;
            case 'tabCriados':
                paginarCriados(1);
                break;
            case 'tabJogados':
                paginarJogados(1);
                break;
        }
        $(".equal").equalHeight();
        //$diretorio = ($(this).parent().parent().hasClass("meusPassatempos")) ? "meus-passatempos" : "mundo-dos-pais";
        //_gaq.push(['_trackPageview', '/' + $diretorio + '/' + $(this).text() + '']);
        return false;
    });
    if ($.getUrlVar("tab")) {
        $("ul.navSub li a[href='#" + $.getUrlVar("tab") + "']").trigger("click");
        $("#tabFavoritos, #tabJogados, #tabCriados").stop("animate");
    } else {
        $("ul.navSub li a.hover").trigger("click");
    }

    $("ul.ga li a").click(function() {
        $url = $(this).attr("rel");
        _gaq.push(['_trackPageview', $url]);
    });

    $("ul.navSuperDuvidas li a").click(function() {
        $("ul.navSuperDuvidas li a").removeClass("hover");
        $tab = $(this).addClass("hover").attr("href");
        $("#boxTabsDuvidas .tab").hide().parent().find($tab).fadeIn();
        $("a.btnTodasPerguntas").show();
        $(".equal").equalHeight();
        return false;
    });
    $("ul.navSuperDuvidas li:first a").trigger("click");

    $("ul.listTabs li a").click(function() {
        $("ul.listTabs li a").removeClass("hover");
        $tab = $(this).addClass("hover").attr("href");
        $(".tabs .tab").hide().parent().find($tab).fadeIn();
        $("#boxDescProd").jScrollPane({ scrollbarWidth: 21, scrollbarMargin: 15, showArrows: true });
        return false;
    });
    $("ul.listTabs li a.hover").trigger("click");

    $("ul.listTabs.navCriadores li a").click(function() {
        $("ul.listTabs li a").removeClass("hover");
        $tab = $(this).addClass("hover").attr("href");
        $filhoId = $("input[name='filhoId']").val();
        switch ($tab.split("#")[1]) {
            case 'tabFavoritos':
                paginarFavoritosFilho(1, $filhoId);
                break;
            case 'tabCriados':
                paginarCriadosFilho(1, $filhoId);
                break;
            case 'tabJogados':
                paginarJogadosFilho(1, $filhoId);
                break;
        }
        $(".tabs .tab").hide().parent().find($tab).fadeIn(function() {
            $("#boxDescProd").jScrollPane({ scrollbarWidth: 21, scrollbarMargin: 15, showArrows: true });
        });
        return false;
    });

    $("a.btnCadastro, a.btnMapaCadastro").click(function() {
        $.fancybox({ 'href': 'https://' + window.location.host + '/wscadastrounico/Cadastro/Cadastro.aspx?SgAreaSite=Q3JpYWRvcmVzUGFzc2F0ZW1wbw==', 'width': 622, 'height': 543, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': true, 'overlayOpacity': 0.6, 'overlayColor': '#000' });
        _gaq.push(['_trackPageview', '/portalnestle/passatempo/ws/cadastro']);
        return false;
    });

    $("a.tbCadastro").click(function() {
        parent.cadastro();
        return false;
    });

    $("a.tbLogin").click(function() {
        parent.login();
        return false;
    });

    $("a.btnContato").click(function() {
        $.fancybox({ 'href': 'https://' + window.location.host + '/wscadastrounico/Fale/wfFale.aspx?SgAreaSite=Q3JpYWRvcmVzUGFzc2F0ZW1wbw==&cdAssunto=163', 'width': 573, 'height': 515, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': true, 'overlayOpacity': 0.6, 'overlayColor': '#000' });
        _gaq.push(['_trackPageview', '/portalnestle/passatempo/ws/contato']);
        return false;
    });

    $("a.btnPrivacidade").click(function() {
        $.fancybox({ 'href': 'http://' + window.location.host + '/wscadastrounico/Politica/wfPolitica.aspx?SgAreaSite=Q3JpYWRvcmVzUGFzc2F0ZW1wbw==', 'width': 573, 'height': 515, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': true, 'overlayOpacity': 0.6, 'overlayColor': '#000' });
        _gaq.push(['_trackPageview', '/portalnestle/passatempo/ws/politica-privacidade']);
        return false;
    });

    $("a.btnQueroConectar").click(function() {
        parent.$.fancybox({ 'href': 'https://' + window.location.host + '/wscadastrounico/Login/Login.aspx?SgAreaSite=Q3JpYWRvcmVzUGFzc2F0ZW1wbw==&RedirectAfterLogoff=http://' + window.location.host + '/portalnestle/passatempo/Home/Default.aspx&RedirectAfterLogin=http://' + window.location.host + '/portalnestle/passatempo/Home/Logado.ashx', 'width': 601, 'height': 300, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': true, 'overlayOpacity': 0.6, 'overlayColor': '#000' });
        return false;
    });

    $("a.btnNutridicas, a.btnMapaNutridic").click(function() {
        return false;
    });

    $(".btnConsultar").click(function() {
        if (!$("input.login").hasClass("blur") && !$("input.login").hasClass("error")) {
            $.getJSON("/portalnestle/passatempo/MeusPassatempos/ValidaApelido.ashx", $(".formLogin").serialize(), function(data) {
                $.each(data, function(i, item) {
                    if (data.msg == 'ok') {
                        $(".boxNickDisponivel").fadeIn();
                        _gaq.push(['_trackPageview', '/MeusPassatempos/CriandoAvatar/nick-disponivel']);
                    } else {
                        $(".boxNickDisponivel").fadeOut();
                        //$("input.login").addClass("error").val("Xiiii. Esse nick já existe.");
                        $("input.login").addClass("error").val(data.erroMsg);
                        _gaq.push(['_trackPageview', '/MeusPassatempos/CriandoAvatar/nick-indisponivel']);
                    }
                });
            });
        }
        return false;
    });
    $("input.login").each(function() {
        if ($(this).val() != "") {
            $(".btnConsultar").trigger("click");
        }
    });

    $(".btnGostou").click(function() {
        $usuarioId = $("input#usuarioId").val();
        $login = encodeURI($("input#login").val());

        $.ajax({
            type: 'POST',
            //data: $(".formLogin").serialize(),
            dataType: "json",
            url: '/portalnestle/passatempo/MeusPassatempos/SalvaApelido.ashx?usuarioId=' + $usuarioId + '&login=' + $login,
            success: function(json) {
                if (json.msg == 'ok') {
                    _gaq.push(['_trackPageview', '/salva-apelido/sucesso/']);
                    window.location = "/portalnestle/passatempo/meus-passatempos/criando-avatar-opcoes.aspx";
                } else {
                    $("input.login").addClass("error").val(json.erroMsg);
                    _gaq.push(['_trackPageview', '/salva-apelido/erro/']);
                }
            }
        });
    });

    $("a.btnMapaImprimir, a.btnPrintGift, a.btnJogoImprimir").click(function() {
        _gaq.push(['_trackPageview', '/jogo-de-imprimir/']);
    });

    $("a.btnRegras").click(function() {
        _gaq.push(['_trackPageview', '/regras-do-jogo/']);
    });

    $("input.login").focus(function() {
        if ($(this).hasClass("error")) {
            $(this).removeClass("error").val("");
        }
    }).keyup(function() {
        $(".boxNickDisponivel").fadeOut();
    }).alphanumeric();

    $(".formFaleConosco").validate({ errorContainer: $(this).find(".tenteNovamente"), errorLabelContainer: $(this).find(".msgErrorLabel"),
        submitHandler: function() {
            $.ajax({
                type: 'post',
                data: $(".formFaleConosco").serialize(),
                dataType: "json",
                url: 'enviaEmail.ashx',
                success: function(json) {
                    if (json.msg == 'ok') {
                        $(".formFaleConosco").hide().next().fadeIn();
                        _gaq.push(['_trackPageview', '/portalnestle/passatempo/ajuda/fale-conosco/enviado/']);
                    } else {
                        $(".erroEnvio").fadeIn().delay(3000).fadeOut();
                        _gaq.push(['_trackPageview', '/portalnestle/passatempo/ajuda/fale-conosco/erro/']);
                    }
                }
            });
        }
    });

    $("a.voltarFaleconosco").click(function() {
        $(".msgSuccessFaleconosco").hide().prev().fadeIn().find("select,textarea").val("");
        return false;
    });

    $("a.btnTodasPerguntas").click(function() {
        $("ul.navSuperDuvidas li a").removeClass("hover");
        $("#tabCriador, #tabJogos, #tabProblemas").show();
        $(this).hide();
        $(".equal").equalHeight();
        return false;
    });

    $("#boxTabsDuvidas h4 a").click(function() {
        $item = $(this).attr("href").split("#")[1];
        $.fancybox({ 'href': '/portalnestle/passatempo/tb/superAjuda.aspx?item=' + $item, 'width': 557, 'height': 482, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': true, 'overlayOpacity': 0.6, 'overlayColor': '#000' });
        return false;
    });

    $("a.btnEnviarPedido").click(function() {
        $.fancybox({ 'href': '/portalnestle/passatempo/tb/autorizacao.aspx', 'width': 665, 'height': 173, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': false, 'overlayOpacity': 0.6, 'overlayColor': '#000' });
        _gaq.push(['_trackPageview', '/meus-passatempos/Default/reenvio-email-pai']);
        return false;
    });

    $(".formAutorizacao").validate({ errorContainer: $(this).find(".msgError"), errorLabelContainer: $(this).find(".msgErrorLabel"),
        submitHandler: function() {
            $nome = $("input#nome").val();
            $email = $("input#email").val();
            $.ajax({
                type: 'GET',
                dataType: "json",
                url: '/portalnestle/passatempo/MeusPassatempos/EnviaEmail.ashx?nomepai=' + $nome + '&email=' + $email,
                success: function(json) {
                    if (json.msg == "ok") {
                        parent.$.fancybox.close();
                        parent.$("span.infCadNaoAutorizado").hide();
                        parent.$(".naoAutorizado").fadeIn();
                        _gaq.push(['_trackPageview', '/autorizacao-de-cadastro/sucesso/']);
                    } else {
                        _gaq.push(['_trackPageview', '/autorizacao-de-cadastro/erro/']);
                    }
                }
            });
            return false;
        }
    });

    $("a.btnCriarEditan, a.btnMapaCriarEdi").click(function() {
        $val = $(this).attr("href").split("#")[1];
        if ($val == '1') {
            $.fancybox({ 'href': '/portalnestle/passatempo/CriarMaisUm/CriarEditando.ashx', 'width': 638, 'height': 251, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': true, 'overlayOpacity': 0.6, 'overlayColor': '#000' });
        } else {
            $.fancybox({ 'href': '/portalnestle/passatempo/tb/semJogos.aspx', 'width': 206, 'height': 121, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': false, 'overlayOpacity': 0.6, 'overlayColor': '#000' });
        }
        return false;
    });

    $("a.btnQueroCriar").click(function() {
        parent.$.fancybox.close();
    });

    $(".formLogin").validate({ errorContainer: $(this).find(".msgErrorLabel"), errorLabelContainer: $(this).find(".msgErrorLabel") });

    $("label + input").click(function() {
        $(this).next().focus();
    });

    $("ul.listPecas li span").click(function() {
        $this = $(this);
        $elementoId = $(this).attr("rel").split("|")[0];
        $usuarioId = $(this).attr("rel").split("|")[1];
        $.ajax({
            type: 'POST',
            data: 'elementoId=' + $elementoId + '&usuarioId=' + $usuarioId,
            dataType: 'json',
            url: '/portalnestle/passatempo/MundoDosPais/Elementos.ashx',
            success: function(json) {
                alert(json.erroMsg);
                if (json.msg == 'ok') {
                    $this.toggleClass("hover");
                }
            }
        });
    });

    $(".infResponsavel").each(function() {
        if ($(this).find("strong").text() == 1) {
            $(this).addClass("singular");
        }
    });

    $("ul.listPecas li a, .presente + a:not(.btnNaoLiberado)").click(function() {
        $peca = $(this).attr("href").split("#")[1];
        $.fancybox({ 'href': '/portalnestle/passatempo/tb/infoPecas.aspx?item=' + $peca, 'width': 573, 'height': 296, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': true, 'overlayOpacity': 0.6, 'overlayColor': '#000' });
        return false;
    });
    $("a.btnNaoLiberado").each(function() {
        $(this).prev().prepend('<span class="bloqueado fix"></span>');
    }).click(function() { return false; });

    $("a.btnVerDetalhes").click(function() {
        $id = $(this).attr("href").split("#")[1];
        $.fancybox({ 'href': '/portalnestle/passatempo/MundoDosPais/DetalheCriadores.ashx?filhoId=' + $id, 'width': 573, 'height': 515, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': true, 'overlayOpacity': 0.6, 'overlayColor': '#000' });
        return false;
    });

    $("a.queroConectar").click(function() {
        parent.$.fancybox({ 'href': 'https://' + window.location.host + '/wscadastrounico/Login/Login.aspx?SgAreaSite=Q3JpYWRvcmVzUGFzc2F0ZW1wbw==&RedirectAfterLogoff=http://' + window.location.host + '/portalnestle/passatempo/Home/Default.aspx&RedirectAfterLogin=http://' + window.location.host + '/portalnestle/passatempo/Home/Logado.ashx', 'width': 601, 'height': 300, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': true, 'overlayOpacity': 0.6, 'overlayColor': '#000' });
        return false;
    });

    $(".semProtegidos").click(function() {
        $.fancybox({ 'href': '/portalnestle/passatempo/MundoDosPais/SemProtegidos.ashx', 'width': 641, 'height': 255, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': true, 'overlayOpacity': 0.6, 'overlayColor': '#000' });
        return false;
    });

    $(".fazerLogin").each(function() {
        parent.$.fancybox({ 'href': 'https://' + window.location.host + '/wscadastrounico/Login/Login.aspx?SgAreaSite=Q3JpYWRvcmVzUGFzc2F0ZW1wbw==&RedirectAfterLogoff=http://' + window.location.host + '/portalnestle/passatempo/Home/Default.aspx&RedirectAfterLogin=http://' + window.location.host + '/portalnestle/passatempo/Home/Logado.ashx', 'width': 601, 'height': 300, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': true, 'overlayOpacity': 0.6, 'overlayColor': '#000' });
        return false;
    });

    $(".mudounivel").each(function() {
        $pontos = $(this).attr("rel").split("|")[0];
        $elementoId = $(this).attr("rel").split("|")[1];
        //if ($pontos == 4 || $pontos == 7 || $pontos == 9) {
        parent.$.fancybox({ 'href': '/portalnestle/passatempo/MeusPassatempos/MudouNivel.ashx?pontos=' + $pontos + '&elementoId=' + $elementoId, 'width': 556, 'height': 370, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': true, 'overlayOpacity': 0.6, 'overlayColor': '#000' });
        //}
        return false;
    });

    $(".temumfilho").each(function() {
        $missao = $(this).attr("rel").split("|")[0];
        $filhoid = $(this).attr("rel").split("|")[1];
        if ($missao == "1") {
            parent.$.fancybox({ 'href': '/portalnestle/passatempo/MeusPassatempos/missao1.ashx?filhoid=' + $filhoid, 'width': 536, 'height': 466, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': true, 'overlayOpacity': 0.6, 'overlayColor': '#000' });
        } else if ($missao == "2") {
            parent.$.fancybox({ 'href': '/portalnestle/passatempo/MeusPassatempos/missao2.ashx?filhoid=' + $filhoid, 'width': 536, 'height': 390, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': true, 'overlayOpacity': 0.6, 'overlayColor': '#000' });
        } else if ($missao == "3") {
            parent.$.fancybox({ 'href': '/portalnestle/passatempo/MeusPassatempos/missao3.ashx?filhoid=' + $filhoid, 'width': 536, 'height': 333, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': true, 'overlayOpacity': 0.6, 'overlayColor': '#000' });
        }
        return false;
    });

    $(".boxRelatorio").click(function() {
        $url = $(this).attr("rel").split("|")[0];
        $usuarioId = $(this).attr("rel").split("|")[1];
        $valor = $("#relatorioMensal").attr("checked");
        $.ajax({
            type: 'GET',
            //data: $(this).serialize(),
            dataType: "json",
            url: $url + "?usuarioId=" + $usuarioId + "&valor=" + $valor,
            success: function(json) {
                if (json.msg == 'ok') {
                    // ok
                } else {
                    alert(json.erroMsg);
                }
            }
        });
        //return false;
    });

    $("a.btnSubirNivel").fancybox({ 'width': 573, 'height': 515, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': true, 'overlayOpacity': 0.6, 'overlayColor': '#000' });

    $("a.tbComoCriar").fancybox({ 'width': 800, 'height': 450, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': true, 'overlayOpacity': 0.6, 'overlayColor': '#000' });

    $("#boxDescProd, #scrollRespostas").jScrollPane({ scrollbarWidth: 21, scrollbarMargin: 15, showArrows: true });

    $(".boxPecas, .boxRespostas").each(function() {
        $item = ($.getUrlVar("item")) ? $.getUrlVar("item") : '1';
        $(this).find("div[rel='item" + $item + "']").show();
        $("#scrollRespostas").jScrollPane({ scrollbarWidth: 21, scrollbarMargin: 15, showArrows: true });
    });

    $("#boxEscolha ul").jcarousel({ scroll: 1 });

    $("input + label").click(function() {
        if ($(this).prev().attr("type") == 'checkbox') {
            if ($(this).prev().is(":checked")) {
                $(this).prev().attr("checked", false);
            } else {
                $(this).prev().attr("checked", true);
            }
        } else {
            $(this).prev().attr("checked", true);
        }
    });

    /*$(".btnJogar").live("click", function() {
    $slug = $(this).attr("href").split("#")[1];
    window.open('/portalnestle/passatempo/jogo/' + $slug + '.aspx', 'passatempoJogar');
    return false;
    });*/

    $(".btnCriarDoZero, .btnUsarEsse, .btnMapaCriardoZ, .btnQueroCriarAgora").click(function() {
        if ($(this).hasClass('navigate')) {
            $flash = ($.browser.msie) ? parent.window['PassatempoCriadores_HomeMenu'] : parent.document['PassatempoCriadores_HomeMenu'];
            $flash.navigate('criar');
        } else {
            $idGame = ($(this).attr("rel")) ? $(this).attr("rel") : '0';
            window.open('/portalnestle/passatempo/criar-mais-um/criar.aspx?idGame=' + $idGame, 'passatempoCriar');
        }
        return false;
    });



    $(".ga").click(function() {
        if ($(this).attr("rel")) {
            $path = $(this).attr("rel");
        } else {
            $path = $(this).attr("href");
        }
        _gaq.push(['_trackPageview', $path]);
    });

    $("a.flashProdutos").click(function() { // remover
        lightboxInfoProd();
        return false;
    });

    $("#flashCriarAvatar img").click(function() { // remover
        lightbox('/portalnestle/passatempo/tb/autorizacao.aspx', 665, 173, false);
    });

    $("textarea.formMensagem").maxLength(500, ".charLength");
    $("input.login").maxLength(12, ".charsLeft strong");

    $(".infoProd tbody tr:even").addClass("even");
    $(".boxInfo746:last .bot, .listItens:last, .boxDadosRelatorio .item:last, .post:last").addClass("last");

    //$(".pagination").find("a:first, a:last").addClass("blue");
    $(".hint").hint();

    $("#fecharPopup").each(function() {
        parent.$.fancybox.close();
        return false;
    });

    $.getFlashVersion = function() {
        try {
            try {
                var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
                try { axo.AllowScriptAccess = 'always'; }
                catch (e) { return '6,0,0'; }
            } catch (e) { }
            return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
        } catch (e) {
            try {
                if (navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
                    return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
                }
            } catch (e) { }
        }
        return '0,0,0';
    };
    if ($.getFlashVersion().split(",").shift() < 6) {
        window.location = '/portalnestle/passatempo/flash.aspx';
    }

});

$(window).resize(function() {
    $("#right").contentHeight();
    $("#wrapper").each(function() {
        if ($(this).height() < ($(window).height() - 92)) {
            $("#wrapper, #left, #flashContent").height($(window).height() - 92);
        }
    });
});

function loadContent(path,url){
    switch(path){
	case 'criar':
	    url = '/portalnestle/passatempo/criar-mais-um/Default.aspx';
	    window.location = url;
	break;
	case 'jogos':
	    url = '/portalnestle/passatempo/busca/Default.aspx';
	    window.location = url;
	break;
	case 'ajuda':
	    url = '/portalnestle/passatempo/ajuda/Default.aspx';
	    window.location = url;
	break;
	case 'mundodospais':
	    url = '/portalnestle/passatempo/mundo-dos-pais/Default.aspx';
	    window.location = url;
	break;
    }
}

function resize(valor){
    $("#conteudo").css("left", (valor - 210));
    $("#flashContent").width(valor);
}

function complete(){
    //alert("terminou a animação");
}

function fechar(){
    /*if($.browser.msie){
	window.opener = "whocares";
	window.close();
    }else{
	window.open('','_parent','');
	window.close();
    }*/
    window.close();
}

function isChrome(){
	$isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
	return $isChrome;
}

function jogar(slug){
    window.open('/portalnestle/passatempo/jogo/' + slug + '.aspx', 'passatempoJogar');
}

function imprimePassatempo(){
    window.open('/portalnestle/passatempo/download/passatempo.pdf', 'printPassatempo');
    _gaq.push(['_trackPageview', '/download/passatempo-de-imprimir/']);
}

function comoCriarPassatempo(){
    $.fancybox({ 'href' : '/portalnestle/passatempo/tb/comoCriar.aspx', 'width': 770, 'height': 578, 'autoScale' : false, 'type' : 'iframe', 'padding' : 0, 'showCloseButton' : true, 'overlayOpacity' : 0.6, 'overlayColor' : '#000' });
}

function lightboxInfoProd(name){
    name = (name != undefined) ? name : 'Chocolate';
    $.fancybox({ 'href' : '/portalnestle/passatempo/tb/pt'+ name +'.aspx', 'width' : 573, 'height' : 515, 'autoScale' : false, 'type' : 'iframe', 'padding' : 0, 'showCloseButton' : true, 'overlayOpacity' : 0.6, 'overlayColor' : '#000' });
}
function lightboxTermosUso(name){
    $.fancybox({ 'href' : '/portalnestle/passatempo/tb/termosUso.aspx', 'width' : 573, 'height' : 515, 'autoScale' : false, 'type' : 'iframe', 'padding' : 0, 'showCloseButton' : true, 'overlayOpacity' : 0.6, 'overlayColor' : '#000' });
}

function login(secao){
    //var urlLogoffRedirect = "http://" + window.location.host + "/portalnestle/passatempo/Default.aspx";
    //var urlLoginRedirect = "http://" + window.location.host + "/portalnestle/passatempo/Home/Logado.ashx";
    switch(secao){
	case 'criar':
	    $url = 'http://' + window.location.host + '/portalnestle/passatempo/Home/Logado.ashx'+ encodeURIComponent('?urlRetorno=/portalnestle/passatempo/criar-mais-um/Default.aspx');
	break;
	default:
	    $url = 'http://' + window.location.host + '/portalnestle/passatempo/Home/Logado.ashx';
	break;
    }
    $.ajax({
	type: 'GET',
	dataType: "json",
	url: '/portalnestle/passatempo/Home/IsLogged.ashx',
	success: function(json) {
	    if(json.msg == "ok"){
		window.location = $url;
	    }else{
	        $.fancybox({ 'href': 'https://' + window.location.host + '/wscadastrounico/Login/Login.aspx?SgAreaSite=Q3JpYWRvcmVzUGFzc2F0ZW1wbw==&RedirectAfterLogoff=http://' + window.location.host + '/portalnestle/passatempo/Default.aspx&RedirectAfterLogin=' + $url + '', 'width': 601, 'height': 300, 'autoScale': false, 'type': 'iframe', 'padding': 0, 'showCloseButton': true, 'overlayOpacity': 0.6, 'overlayColor': '#000', onClosed : function() {
			$.ajax({
			    type: 'GET',
			    dataType: "json",
			    url: '/portalnestle/passatempo/Home/IsLogged.ashx',
			    success: function(json) {
				if(json.msg == "ok"){
				    window.location = $url;
				}
			    }
			});
		    }
		});
	    }
	}
    });
    _gaq.push(['_trackPageview', '/portalnestle/passatempo/ws/login']);
}

function cadastro(){
    $("a.btnCadastro").trigger("click");
}

function lightboxMissao(id){
    id = (id != null) ? id : 1;
    $.fancybox({ 'href' : '/portalnestle/passatempo/tb/missao-'+ id +'.aspx', 'width' : 536, 'height' : 466, 'autoScale' : false, 'type' : 'iframe', 'padding' : 0, 'showCloseButton' : true, 'overlayOpacity' : 0.6, 'overlayColor' : '#000' });
}

function lightbox(url,width,height,showCloseButton){
    showCloseButton = (showCloseButton != undefined) ? showCloseButton : true;
    $.fancybox({ 'href' : url, 'width' : width, 'height' : height, 'autoScale' : false, 'type' : 'iframe', 'padding' : 0, 'showCloseButton' : showCloseButton, 'overlayOpacity' : 0.6, 'overlayColor' : '#000' });
}

function clickNav(tab){
    $("ul.navSub li a[href='#" + tab + "']").trigger("click");
}

jQuery.fn.contentHeight = function () {
    return this.each(function () {
	$docWidth = ($.browser.msie && ($.browser.version < 7)) ? ($(window).width() - 3) : ($(window).width() - 20);
	if($docWidth >= 1000){
	    $("#wrapper").width("100%");
	    $(this).width($docWidth - 107);
	}else{
	    $("#wrapper").width("1000px");
	    $(this).width("897px");
	}
    });
};

jQuery.fn.equalHeight = function () {
    var height		= 0;
    var maxHeight	= 0;
    this.each(function () {
	height		= jQuery(this).outerHeight();
	maxHeight	= (height > maxHeight) ? height : maxHeight;
    });
    return this.each(function () {
	var t		= jQuery(this);
	var minHeight	= maxHeight - (t.outerHeight() - (t.height() - 0));
	var property	= jQuery.browser.msie && jQuery.browser.version < 7 ? 'height' : 'min-height';
	t.css(property, minHeight + 'px');
    });
};

jQuery.fn.maxLength = function(max,target){
    this.each(function(){
	var type = this.tagName.toLowerCase();
	var inputType = this.type ? this.type.toLowerCase() : null;
	if(type == "input" && inputType == "text" || inputType == "password"){
	    this.onkeyup = function(){
		if(target != null){ $(target).text(max - this.value.length); }
	    };
	    this.maxLength = max;
	}else if(type == "textarea"){
	    this.onkeypress = function(e){
		var ob = e || event;
		var keyCode = ob.keyCode;
		var hasSelection = document.selection? document.selection.createRange().text.length > 0 : this.selectionStart != this.selectionEnd;
		return !(this.value.length >= max && (keyCode > 50 || keyCode == 32 || keyCode == 0 || keyCode == 13) && !ob.ctrlKey && !ob.altKey && !hasSelection);
	    };
	    this.onkeyup = function(){
		if(target != null){ $(target).text(max - this.value.length); }
		if(this.value.length > max){
		    this.value = this.value.substring(0,max);
		}
	    };
	}
    });
};

jQuery.fn.hint = function(blurClass){
    if (!blurClass) {
	blurClass = 'blur';
    }
    return this.each(function () {
	var $input = jQuery(this),
	title = $input.attr('title'),
	$form = jQuery(this.form),
	$win = jQuery(window);
	function remove() {
	    if ($input.val() === title && $input.hasClass(blurClass)) {
		$input.val('').removeClass(blurClass);
	    }
	}
	if (title) { 
	    $input.blur(function () {
		if (this.value === '') {
		    $input.val(title).addClass(blurClass);
		}
	    }).focus(remove).blur();
	    $form.submit(remove);
	    $win.unload(remove);
	}
    });
};

jQuery.fn.alphanumeric = function(p) {
    p = $.extend({
	ichars: "!@#$%^&*()+=[]\\\';,/{}|\":<>?~`.- ",
	nchars: "",
	allow: ""
    }, p);

    return this.each(function() {
	if (p.nocaps) p.nchars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	if (p.allcaps) p.nchars += "abcdefghijklmnopqrstuvwxyz";

	s = p.allow.split('');
	for ( i=0;i<s.length;i++) if (p.ichars.indexOf(s[i]) != -1) s[i] = "\\" + s[i];
	p.allow = s.join('|');
	
	var reg = new RegExp(p.allow,'gi');
	var ch = p.ichars + p.nchars;
	ch = ch.replace(reg,'');

	$(this).keypress(function (e){
	    if (!e.charCode) k = String.fromCharCode(e.which);
		else k = String.fromCharCode(e.charCode);
		    
	    if (ch.indexOf(k) != -1) e.preventDefault();
	    if (e.ctrlKey&&k=='v') e.preventDefault();
	});
	$(this).bind('contextmenu',function (){return false});
    });
};

$.extend({
    getUrlVars: function(){
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++){
	    hash = hashes[i].split('=');
	    vars.push(hash[0]);
	    vars[hash[0]] = hash[1];
	}
	return vars;
    },
    getUrlVar: function(name){
	return $.getUrlVars()[name];
    }
});


/**
*	swffit v2.3.3 (11/23/2009) <http://swffit.millermedeiros.com/>
*	Copyright (c) 2009 Miller Medeiros <http://www.millermedeiros.com/>
*	This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/
var swffit = function() { var win = window, doc = document, html = doc.getElementsByTagName("html")[0], AGENT = navigator.userAgent.toLowerCase(), WK = /webkit/.test(AGENT), IE = /msie/.test(AGENT) && !win.opera, FF = /firefox/.test(AGENT) && !win.opera, UNDEF = "undefined", _ft, _re, _t, _mw, _mh, _xw, _xh, _hc, _vc, _ow, _oh; swfobject.createCSS("object", "position:absolute; outline:none"); function fit(t, mw, mh, xw, xh, hc, vc) { mw = mw || _ow; mh = mh || _oh; xw = xw || null; xh = xh || null; hc = (hc || hc == null); vc = (vc || vc == null); configure({ target: t, minWid: mw, minHei: mh, maxWid: xw, maxHei: xh, hCenter: hc, vCenter: vc }); } function configure(o) { var evalNum = function(v, p) { return (typeof o[p] != UNDEF) ? o[p] : v; }, evalBool = function(v, p) { return (o[p] || (v && typeof o[p] == UNDEF)); }; _mw = evalNum(_mw, "minWid"); _mh = evalNum(_mh, "minHei"); _xw = evalNum(_xw, "maxWid"); _xh = evalNum(_xh, "maxHei"); _hc = evalBool(_hc, "hCenter"); _vc = evalBool(_vc, "vCenter"); if (o.target && (o.target != _t)) { _t = o.target; swfobject.addDomLoadEvent(initFit); if (IE) { swfobject.addLoadEvent(initFit); } } else { startFit(); } } function initFit() { if (!html.style.overflowX) { controlScroll(0, 0); } if (!html.style.overflowY) { controlScroll(0, 1); } html.style.height = doc.body.style.height = "100%"; doc.body.style.margin = doc.body.style.padding = 0; var st = "width:100%; height:100%"; st += (IE) ? "; overflow:hidden" : ""; swfobject.createCSS("#" + _t, st); _ft = doc.getElementById(_t); _ft = (_ft != UNDEF && FF && /object/.test(_ft.innerHTML)) ? doc.getElementById(_t).getElementsByTagName("object")[0] : _ft; _ow = _ft.width; _oh = _ft.height; _mw = _mw || _ow; _mh = _mh || _oh; startFit(); } function startFit() { setSize(); if (!_re) { swffit.addResizeEvent(setSize); _re = 1; } } function stopFit(w, h) { if (_re) { swffit.removeResizeEvent(setSize); _re = 0; setStyle("top", "auto"); setStyle("left", "auto"); setStyle("marginTop", 0); setStyle("marginLeft", 0); w = w || "100%"; h = h || "100%"; setWidth(w); setHeight(h); forceRedraw(); } } function forceRedraw() { if (WK) { html.focus(); } } function controlResizeEvent(a, fn) { var p = (a) ? ["addEventListener", "attachEvent"] : ["removeEventListener", "detachEvent"]; if (win[p[0]]) { win[p[0]]("resize", fn, false); } else { if (win[p[1]]) { win[p[1]]("onresize", fn); } } } function setWidth(w) { var v = (isNaN(w)) ? w : w + "px"; setStyle("width", v); } function setHeight(h) { var v = (isNaN(h)) ? h : h + "px"; setStyle("height", v); } function setStyle(p, v) { _ft.style[p] = v; } function setSize() { var iw = (win.innerWidth) ? win.innerWidth : ((doc.documentElement.clientWidth) ? doc.documentElement.clientWidth : doc.body.clientWidth), ih = (win.innerHeight) ? win.innerHeight : ((doc.documentElement.clientHeight) ? doc.documentElement.clientHeight : doc.body.clientHeight); iw -= (!IE && ih <= _mh) ? 18 : 0; ih -= (!IE && iw <= _mw) ? 18 : 0; if (_xw && iw >= _xw) { setWidth(_xw); setPosition(0, 1); } else { if (iw > _mw && (iw < _xw || !_xw)) { setWidth("100%"); } else { setWidth(_mw); } setPosition(0, 0); } if (_xh && ih >= _xh) { setHeight(_xh); setPosition(1, 1); } else { if (ih > _mh && (ih < _xh || !_xh)) { setHeight("100%"); } else { setHeight(_mh); } setPosition(1, 0); } forceRedraw(); } function setPosition(t, x) { var p, m; if (t) { p = (x && _vc) ? "50%" : "auto"; m = (x && _vc) ? -(_xh * 0.5) + "px" : 0; setStyle("top", p); setStyle("marginTop", m); } else { p = (x && _hc) ? "50%" : "auto"; m = (x && _hc) ? -(_xw * 0.5) + "px" : 0; setStyle("left", p); setStyle("marginLeft", m); } } function controlScroll(s, v) { var p = (v) ? "overflowY" : "overflowX"; html.style[p] = (s) ? "scroll" : "auto"; } function getValueOf(p) { var o = { target: _t, minWid: _mw, minHei: _mh, maxWid: _xw, maxHei: _xh, hCenter: _hc, vCenter: _vc }; return o[p]; } return { fit: fit, configure: configure, startFit: startFit, stopFit: stopFit, getValueOf: getValueOf, addResizeEvent: function(fn) { controlResizeEvent(1, fn); }, removeResizeEvent: function(fn) { controlResizeEvent(0, fn); }, showScrollH: function() { controlScroll(1, 0); }, showScrollV: function() { controlScroll(1, 1); } }; } ();

function paginarBusca(page, a, b, c, d, m0, m1, q, o) {
    if (a == null) {
        a = $("input#busca-a").val();
    }
    if (b == null) {
        b = $("input#busca-b").val();
    }
    if (c == null) {
        c = $("input#busca-c").val();
    }
    if (d == null) {
        d = $("input#busca-d").val();
    }
    if (m0 == null) {
        m0 = $("input#busca-m0").val();
    }
    if (m1 == null) {
        m1 = $("input#busca-m1").val();
    }
    if (q == null) {
        q = $("input#busca-q").val();
    }
    if (o == null) {
        o = $("input#busca-o").val();
    }
    window.location = '/portalnestle/passatempo/Busca/Default.aspx?a=' + a + '&b=' + b + '&c=' + c + '&d=' + d + '&m0=' + m0 + '&m1=' + m1 + '&q=' + q + '&o=' + o + '&page=' + page;
}

function paginarFavoritos(page) {
    $.ajax({
        dataType: "html",
        url: '/portalnestle/passatempo/MeusPassatempos/Favoritos.ashx?page=' + page,
        success: function(html) {
            $("#tabFavoritos").html(html).find(".listItens:last").addClass("last");
	    flashGame();
	    $scroll = function(){
		if(page > 1){
		    var target = ($.browser.opera) ? 'html' : 'html,body';
		    var targetOffset = $("#tabFavoritos").offset().top;
		    $(target).animate({scrollTop: targetOffset - 50}, 2000);
		}
    	    }
	    setTimeout($scroll, 1000);
        }
    });
}

function paginarCriados(page) {
    $.ajax({
        dataType: "html",
        url: '/portalnestle/passatempo/MeusPassatempos/Criados.ashx?page=' + page,
        success: function(html) {
            $("#tabCriados").html(html).find(".listItens:last").addClass("last");
	    flashGame();
	    $scroll = function(){
		if(page > 1){
		    var target = ($.browser.opera) ? 'html' : 'html,body';
		    var targetOffset = $("#tabCriados").offset().top;
		    $(target).animate({scrollTop: targetOffset - 50}, 2000);
		}
	    }
	    setTimeout($scroll, 1000);
        }
    });
}

function paginarJogados(page) {
    $.ajax({
        dataType: "html",
        url: '/portalnestle/passatempo/MeusPassatempos/Jogados.ashx?page=' + page,
        success: function(html) {
            $("#tabJogados").html(html).find(".listItens:last").addClass("last");
	    flashGame();
	    $scroll = function(){
		if(page > 1){
		    var target = ($.browser.opera) ? 'html' : 'html,body';
		    var targetOffset = $("#tabJogados").offset().top;
		    $(target).animate({scrollTop: targetOffset - 50}, 2000);
		}
	    }
	    setTimeout($scroll, 1000);
        }
    });
}

function paginarFavoritosFilho(page, filhoId) {
    if (filhoId == null) {
        filhoId = $("#filhoId").val();
    }
    $.ajax({
        dataType: "html",
        url: '/portalnestle/passatempo/MundoDosPais/Favoritos.ashx?page=' + page + '&filhoId=' + filhoId,
        success: function(html) {
            $("#tabFavoritos").html(html).find(".listItens:last").addClass("last");
	    flashGame();
	    $scroll = function(){
		if(page > 1){
		    var target = ($.browser.opera) ? 'html' : 'html,body';
		    var targetOffset = $("#tabFavoritos").offset().top;
		    $(target).animate({scrollTop: targetOffset - 50}, 2000);
		}
	    }
	    setTimeout($scroll, 1000);
        }
    });
}

function paginarCriadosFilho(page, filhoId) {
    if (filhoId == null) {
        filhoId = $("#filhoId").val();
    }
    $.ajax({
        dataType: "html",
        url: '/portalnestle/passatempo/MundoDosPais/Criados.ashx?page=' + page + '&filhoId=' + filhoId,
        success: function(html) {
            $("#tabCriados").html(html).find(".listItens:last").addClass("last");
	    flashGame();
	    $("#boxDescProd").jScrollPane({ scrollbarWidth: 21, scrollbarMargin: 15, showArrows: true });
        }
    });
}

function paginarJogadosFilho(page, filhoId) {
    if (filhoId == null) {
        filhoId = $("#filhoId").val();
    }
    $.ajax({
        dataType: "html",
        url: '/portalnestle/passatempo/MundoDosPais/Jogados.ashx?page=' + page + '&filhoId=' + filhoId,
        success: function(html) {
            $("#tabJogados").html(html).find(".listItens:last").addClass("last");
	    flashGame();
	    $scroll = function(){
		if(page > 1){
		    var target = ($.browser.opera) ? 'html' : 'html,body';
		    var targetOffset = $("#tabJogados").offset().top;
		    $(target).animate({scrollTop: targetOffset - 50}, 2000);
		}
	    }
	    setTimeout($scroll, 1000);
        }
    });
}

function flashGame(){
    $(".boxDescItem .game .flash").each(function() {
        $jogaram = $(this).attr("rel").split("|")[0];
        $curtiram = $(this).attr("rel").split("|")[1];
        $pjogaram = $(this).attr("rel").split("|")[2];
        $pcurtiram = $(this).attr("rel").split("|")[3];
        $avatar = $(this).attr("rel").split("|")[4];
        $(this).flash({ src: '/portalnestle/passatempo/swf/descGame.swf', width: 240, height: 77, wmode: 'transparent', flashvars: { jogaram: [$jogaram].join(' '), curtiram: [$curtiram].join(' '), pjogaram: [$pjogaram].join(' '), pcurtiram: [$pcurtiram].join(' '), avatar: [$avatar].join(' ')} }, { version: 10 });
    });
    $(".equal").equalHeight();
    //$("ul.navSub li a.hover").trigger("click");
}

function gaFlash(url){
    _gaq.push(['_trackPageview', url]);
}
