jQuery(document).ready(function() {
    //scroll();

    //if ((document.location.pathname.indexOf('efault.aspx') == -1) && (document.location.pathname != '/') && (document.location.pathname.toLowerCase() != '/portalnestle/ninhosoleil/')) {
        jQuery(".alavanca .off").delay(7000).slideDown(2500, "easeOutBounce");
    //}

    /*HOVER*/
    jQuery(".alavanca a").ready(function() {
        jQuery(".alavanca a").css({ top: '-110px' });
        setTimeout(function() {
            jQuery('.alavanca a').css({ top: '0px' });
        }, 9500)
        jQuery(".alavanca a").mouseover(function() {
            jQuery(".alavanca .off").css({ backgroundPosition: 'left top', top: '-1px' })
        });
        jQuery(".alavanca a").mouseout(function() {
            jQuery(".alavanca .off").css({ backgroundPosition: 'left bottom', top: '0' })
        });
        jQuery(".alavanca a").mouseover(function() {
            jQuery(".alavanca .on").css({ backgroundPosition: 'right top', top: '0' })
        });
        jQuery(".alavanca a").mouseout(function() {
            jQuery(".alavanca .on").css({ backgroundPosition: 'right bottom', top: '0' })
        });
    });

    /* Abre e fecha o banner superior */
    jQuery(".alavanca a").toggle(function() {
        jQuery(".alavanca a").css({ top: '-110px' });
        setTimeout(function() {
            jQuery('.alavanca a').css({ top: '0px' });
        }, 5500)
        jQuery(".alavanca .off").slideUp(2000, "easeInCubic");
        jQuery(".alavanca .on").delay(2300).slideDown(2500, "easeOutBounce");
        jQuery(".pontilhado").fadeIn();
        jQuery(".banner").slideDown(2000, "easeInSine", function() {
            jQuery(".alavanca a").css({ display: "block" });
            jQuery(".alavanca a").mouseover(function() {
                jQuery(".alavanca .on").css({ backgroundPosition: 'right top' })
            });
            jQuery(".alavanca a").mouseout(function() {
                jQuery(".alavanca .on").css({ backgroundPosition: 'right bottom' })
            });
            jQuery(".alavanca .off").hide();
        });
        _trackEvent('HOME', 'BANNER_PUXAR');
    }, function() {
        jQuery(".alavanca a").css({ top: '-110px' });
        setTimeout(function() {
            jQuery('.alavanca a').css({ top: '0px' });
        }, 5500)
        jQuery(".alavanca .on").slideUp(2000, "easeInCubic");

        jQuery(".alavanca .off").delay(2300).slideDown(2500, "easeOutBounce");
        jQuery(".banner").slideUp(2000, "easeInSine", function() {
            jQuery(".pontilhado").fadeOut();
        });
        _trackEvent('HOME', 'BANNER_FECHAR');
    });

    //verifyCookie();

    jQuery('#tabvanilla > ul').tabs({ fx: { height: 'toggle', opacity: 'toggle'} });
    jQuery('#featuredvid > ul').tabs();

    //jQuery(".alavanca a").trigger("click");// trigger de click do banner

    /* função geral para pops */
    jQuery(".bt-pop").fancybox({
        padding: 0,
        margin: 0,
        centerOnScroll: true,
        showCloseButton: false,
        overlayColor: "#fcdb2b",
        overlayOpacity: 0.9
    });

    /* fecha pops */
    jQuery(".pop .bt-fechar").click(function() {
        jQuery.fancybox.close();
    });

    /* Icone Facebook + Over */
    /*jQuery(".BrincadeiraValida .ico_fb").mouseover(function() {
    jQuery(".BrincadeiraValida .ico_fb2").css({display: 'block' })
    });
    jQuery(".BrincadeiraValida .ico_fb").mouseout(function() {
    jQuery(".BrincadeiraValida .ico_fb2").css({display: 'none' })
    });*/

    jQuery(".BrincadeiraValida").hover(function() {
        jQuery(this).children("a").children(".BrincadeiraValida .ico_fb2").css({ display: 'block' });
    }, function() {
        jQuery(".BrincadeiraValida .ico_fb2").css({ display: 'none' });
    });
    //    jQuery(".BrincadeiraValida").click(function() {
    //        parent.document.location.href = 'http://www.facebook.com/ninhosoleil?sk=app_254106464608630';
    //    });

    jQuery(".Classif").hover(function() {
        jQuery(this).children(".BrincandeiraClassificOver").css({ display: 'block' });
    }, function() {
        jQuery(".BrincandeiraClassificOver").css({ display: 'none' });
    });

    jQuery(".BrincadeiraBox").hover(function() {
        //jQuery(this).css("cursor", "pointer");
        jQuery(this).find(".BrincadeiraLink").css("background-position", "left bottom");
        jQuery(this).find(".selo, .selo2, .selo3").css("background-position", "right bottom");
    }, function() {
        //jQuery(this).css("cursor", "default");
        jQuery(this).find(".BrincadeiraLink").css("background-position", "left top");
        jQuery(this).find(".selo,.selo2, .selo3").css("background-position", "right top");
    });

    jQuery(".box-info ul li").hover(function() {
        //jQuery(this).css("cursor", "pointer");
        jQuery(this).find(".ico-info a").css("background-position", "top left");
    }, function() {
        //jQuery(this).css("cursor", "default");
        jQuery(this).find(".ico-info a").css("background-position", "bottom left");
    });

    jQuery(".NoticiaEach").hover(function() {
        //jQuery(this).css("cursor", "pointer");
        jQuery(this).find(".NoticiasDetalhe").css("background-position", "bottom left");
    }, function() {
        //jQuery(this).css("cursor", "default");
        jQuery(this).find(".NoticiasDetalhe").css("background-position", "top left");
    });

    jQuery(".NotRecentes").hover(function() {
        //jQuery(this).css("cursor", "pointer");
        jQuery(this).find(".NoticiasDetalhe").css("background-position", "bottom left");
    }, function() {
        //jQuery(this).css("cursor", "default");
        jQuery(this).find(".NoticiasDetalhe").css("background-position", "top left");
    });

    jQuery(".bombando").hover(function() {
        //jQuery(this).css("cursor", "pointer");
        jQuery(this).find(".NoticiasDetalhe").css("background-position", "bottom left");
    }, function() {
        //jQuery(this).css("cursor", "default");
        jQuery(this).find(".NoticiasDetalhe").css("background-position", "top left");
    });

    jQuery(".ico_fb2").hover(function() {
        //jQuery(this).css("cursor", "pointer");
        jQuery(this).find(".bt_seta").css("background-position", "top left");
    }, function() {
        //jQuery(this).css("cursor", "default");
        jQuery(this).find(".bt_seta").css("background-position", "bottom left");
    });

    if (jQuery.browser.msie && (jQuery.browser.version == 6)) { jQuery("body").addClass("ie6") };
    if (jQuery.browser.msie && (jQuery.browser.version == 7)) { jQuery("body").addClass("ie7") };

    if (document.location.hash != '') {
        if (document.location.hash == '#todas') {
            jQuery('iframe#pagHome').attr("src", "getBrincadeiras.aspx");
        } else {
            jQuery('iframe#pagHome').attr("src", "getBrincadeira.aspx?tituloBrincadeira=" + document.location.hash.replace('#', ''));
        }
    }

    /*ScrollToBau*/
    jQuery(".BrincadeiraBox a").click(function() {
        var cod = jQuery(this).attr("cod");

        setIluFlash(cod);
        scrollToBau();
        //alert(cod);
    });

    /*PRODUTOS*/
    //jQuery(".item:last").addClass("selected");
    var qsProd = getQueryString("p");
    if (qsProd != "" && qsProd != null) {
        jQuery("#" + qsProd).addClass("selected");
    } else {
        jQuery("#ninho-soleil-petit-suisse-morango").addClass("selected");
    }


    if (navigator.appVersion.indexOf("Mac") != -1) {
        $("head").append('<link rel="stylesheet" type="text/css" media="all" href="styles/MacOS.css" />');
    }

    jQuery(".bt-ver-video").click(function() {
        _trackEvent('HOME', 'BANNER_VIDEO');
    });
    jQuery("#pop-video .bt-fechar").click(function() {
        _trackEvent('HOME', 'BANNER_VIDEO_FECHAR');
    });
    jQuery(".copyright a").click(function() {
        _trackEvent('HOME', 'POLITICA_DE_PRIVACIDADE_ABRIR');
        popupPolitica();
        return false;
    });
    jQuery(".logo a").click(function() {
        _trackEvent('INTERNA', 'LOGO_NINHO_IR_PARA_HOME');
    });
    jQuery(".bt-ver-mais a").click(function() {
        _trackEvent('HOME', 'FOOTER_NOTICIAS_BOTAO_VER_MAIS');
    });
    jQuery(".bt-ver-todos a").click(function() {
        _trackEvent('HOME', 'FOOTER_PRODUTOS_BOTAO_VER_TODOS');
    });
    jQuery(".bt-brinque-fb a").click(function() {
        _trackEvent('HOME', 'FOOTER_BOTAO_BRINQUE_NO_FACEBOOK');
    });
    jQuery(".bt-baixe-app a").click(function() {
        _trackEvent('HOME', 'FOOTER_BOTAO_BRINQUE_NO_FACEBOOK');
    });
    jQuery(".bt-abra a").click(function() {
        _trackEvent('INTERNA', 'BOTAO_ABRA_O_BAU');
    });
});


	
function reSize(){
	var intIframe = jQuery('body').height();
	
	parent.document.getElementById('pagHome').style.height = "" + (intIframe + 80) + "px";
	
	//alert(intIframe);
}
	
function verifyCookie(){
	var match_cookie = document.cookie.match("alavanca") // busca o cookie

	if(!match_cookie){// se o cookie não existe
		// função que abre a alavanca	
		setTimeout(function () { // trigger de click do banner
		   jQuery('.alavanca a').trigger('click');
		}, 11000)			
	}
	/* GRAVAÇÃO DO COOKIE */
	document.cookie = "alavanca=1";
}

function scrollToBau(){
    //alert("baú");
    var p = parent.document.getElementById("flashDiv");
	
    parent.window.scrollTo(0, getPositionTop(p));
}

function scrollToBrincadeira(){
   var destino = $('#pagHome').offset().top;
   jQuery("html:not(:animated),body:not(:animated)").animate({ scrollTop: destino }, 5000);
   return false;
}

function getPositionTop(obj) {
    var topValue = 0;
    while (obj) {
        topValue += obj.offsetTop;
        obj = obj.offsetParent;
    }
    return topValue;
}

function getPositionLeft(obj) {
    var leftValue = 0;
    while (obj) {
        leftValue += obj.offsetLeft;
        obj = obj.offsetParent;
    }
    return leftValue;
}

function getQueryString(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");

    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}

function carregar(pagina) {
    if (pagina == 0) {
        jQuery('iframe#pagHome').attr("src", "getBrincadeiras.aspx");
    } else {
        jQuery('iframe#pagHome').attr("src", "getBrincadeira.aspx?idbrincadeira=" + pagina);
    }
    //alert(pagina);
}

function setIluFlash(id) {
    var flash = parent.document.getElementById('flashDiv');
    //alert(flash);
    //alert(id);
    flash.setGame(id);
    flash.setInterna(1);
}

function onFlashReady() {

    if ((document.location.hash != '') && (document.location.hash != '#todas')) {
        var vidbrincadeira = $("iframe#pagHome").contents().find(".BrincadeiraBox")[0];
        var idbr = $(vidbrincadeira).attr("cod");
        //alert(idbr);
        setIluFlash(idbr);
    } else {
        zeraInterna();
    }

    //
    //alert(window.location.hash);

    var caminhosite = document.location.pathname.toLowerCase();

    if ((caminhosite == '/portalnestle/ninhosoleil/' || caminhosite == '/dpa/ninho/ninhowebsite/') && (window.location.hash == '#' || window.location.hash == '')) {
        window.setTimeout("openBanner()", 7000);
    };

//    if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
//	    stopSounds();
//	}

}

function stopSounds() {
    var flash = parent.document.getElementById('flashDiv');
	flash.stop();
}

function zeraInterna() {
    var flash = parent.document.getElementById('flashDiv');
    flash.setInterna(0);
    flash.closeBau();
    parent.document.location.hash = '';
}

function getHome() {
    jQuery('iframe#pagHome').attr("src", "index.aspx");
    document.location.hash = '';
}

function onSoundReady(lista){
	var $flashSound = parent.document.getElementById('flashSound');
	var $soundList = lista;
}

function playFlashSound(id){
	/* LISTA DE SONS
	bau_abrindo
	bau_abrindo_estrelinhas
	abrir_bau_over
	bau_fechando
	loading_brincadeiras_complete
	loading_brincadeiras_progress
	over_botoes
	over_botoes_estrelinhas
	clic_botoes
	vitamina_coletada
	aprenda_brincar_click
	aprenda_brincar_over
	balao_estourando
	*/
	setTimeout("onSoundReady()", 5000);
	var $flashSound = parent.document.getElementById('flashSound');
	$flashSound.playSound(id);
	//alert('5 segundos, som ok!');
}
function sound(){
    jQuery(".overS").mouseover(function() {
        playFlashSound("over_botoes");
    });
	jQuery(".clicS").click(function () {
		playFlashSound("clic_botoes");
	});
	
	jQuery(".bt-all").click(function () {
		playFlashSound("clic_botoes");
	});
	
}

function openBanner() {
    jQuery(".alavanca a").trigger("click");
}
