var tempo, sDiv;
var inDiv = new Array("showAll", "todasCategorias", "topoLoja", "txtCodVP", "txtPVPosto");

function initMenu(d){
    var c;
    var a;
    if (document.getElementById) {
        navRoot = $(d);
        if (d == "showAll" || d == "todasCategorias" || d == "topoLoja") {
            navRoot.onmouseover = function(){

                if (a != undefined) {
                    clearTimeout(a)
                }
                c = setTimeout('mostraMenu("' + this.id + '")', 200)
            }
        }
       
	   if(d!="topoLoja"){
			navRoot.onmouseout = function(){
	
				if (c != undefined) {
					clearTimeout(c)
				}
	
				a = setTimeout('escondeMenu("' + this.id + '")', 400)
			}
	   }
    }
}

function mostraMenu(a){

    escolheDiv(a);
    try {
        if (!Element.visible(sDiv)) {
            new Effect.BlindDown(sDiv, {
                duration: 0.3,
                queue: {
                    position: "end",
                    scope: "menu",
                    limit: 10
                }
            })
        }
    } 
    catch (b) {
        $(sDiv).display = ""
    }
}

function escondeMenu(b){

	
    escolheDiv(b);
    try {
        new Effect.Fade(sDiv, {
            duration: 0.5,
            queue: {
                position: "end",
                scope: "menu",
                limit: 10
            }
        })
    } 
    catch (a) {
        $(sDiv).display = "none"
    }
}

function escolheDiv(b){
    if (b == "showAll") {
        sDiv = inDiv[0]
    }
    if (b == "todasCategorias") {
        sDiv = inDiv[1]
    }
    if (b == "topoLoja") {
        sDiv = inDiv[2]
    }
    if (b == "showVP") {
        sDiv = inDiv[3]
    }
    if (b == "showPVPosto") {
        sDiv = inDiv[4]
    }
}

function over(a){
    window.clearTimeout(tempo);
    a.onmouseout = function(){
        tempo = window.setTimeout(escondeMenu, 1000)
    }
}
function trocaBtn(){
	var vBtn = document.getElementById('btnTopo');
	if(vBtn.innerHTML=="VER TOPO ADORO"){
		vBtn.innerHTML = "ESCONDER TOPO";
		mostraMenu('topoLoja');
	}else{
		vBtn.innerHTML = "VER TOPO ADORO";
		escondeMenu('topoLoja');
	}
}


var a =0;
function gradient(id, level)
{
	
	var box = document.getElementById(id);
	box.style.opacity = level;
	box.style.MozOpacity = level;
	box.style.KhtmlOpacity = level;
	box.style.filter = "alpha(opacity=" + level * 100 + ")";
	box.style.display="block";
	if(level==0){box.style.display="none";}	
	return;
}

function fadein(id) 
{
	var level = 0;
	while(level <= 1)
	{
		setTimeout( "gradient('" + id + "'," + level + ")", (level* 1000) + 10);
		level += 0.01;
	}
}

function openbox(div,fadin)
{
  var box = document.getElementById(div); 
  
  if(fadin)
  {
	 gradient(div, 0);
	 fadein(div);
  }
  else
  { 	
    box.style.display='block';
  }  	
}
