/*
* niceMenus - by Thomas Krille
*
* you are not allowed to alter, rewrite or use any of the javascript-code below this advice
* if you want to use niceMenus contact me
*
* Copyright 2006 by Thomas Krille (tk-2000@web.de) and Paint-the-Web (http://www.paint-the-web.org)
*/

function goMenu(nr){
  if(!boxes[nr]["animGo"]){
    boxaniOn(nr);
    boxes[nr]["animGo"]=true;
  }
}

function leaveMenu(nr){
  boxes[nr]["animGo"]=false;
  boxaniOff(nr);
}
var counter=20;
var boxOffTop=8;
var boxOffLeft=1;
function boxaniOn(nr) {
  for(var i=0;i<hoverCSSFx.length;i++){
    eval('document.getElementById("menu"+nr).style.'+hoverCSSFx[i]["attr"]+'="'+hoverCSSFx[i]["hov"]+'";');
  }
  clearInterval(boxes[nr]["intv"]);
  if(boxes[nr]["state"]==maxFrames/*+1*/) {
    document.getElementById("sub"+nr).style.visibility = "visible";
    document.getElementById("boxani"+nr).style.visibility = "hidden";
    document.getElementById('boxani'+nr).style.display = "none";
    //document.getElementById("sub"+nr).style.visibility = "visible";
    counter=0;
  }
  else {
    if (boxes[nr]["state"]==0) {
      document.getElementById("boxani"+nr).style.width= "0px";
      document.getElementById("boxani"+nr).style.height="0px";
      boxes[nr]["state"]++;
      boxes[nr]["intv"]=window.setInterval("boxaniOn("+nr+");", 15);
      document.getElementById('menu_spacer'+nr).style.display = "inline";
    }
    else {
      document.getElementById('boxani'+nr).style.visibility = "visible";
      document.getElementById('boxani'+nr).style.display = "inline";
      boxes[nr]["state"]++;

      var k1=Math.ceil(boxes[nr]["width"]/maxFrames);
      
      if((boxes[nr]["state"]*k1)>boxes[nr]["width"]) {
        document.getElementById("boxani"+nr).style.width=boxes[nr]["width"]+"px";
        var w=boxes[nr]["width"];
      }
      else{
        document.getElementById("boxani"+nr).style.width=(boxes[nr]["state"]*k1)+"px";
        var w=boxes[nr]["state"]*k1;
      }
      
      var k2=Math.ceil(boxes[nr]["height"]/maxFrames);
      
      if((boxes[nr]["state"]*k2)>boxes[nr]["height"]) {
        document.getElementById("boxani"+nr).style.height=boxes[nr]["height"]+"px";
        var h=boxes[nr]["height"];
      }
      else {
        document.getElementById("boxani"+nr).style.height=(boxes[nr]["state"]*k2)+"px";
        var h=boxes[nr]["state"]*k2;
      }
      
      document.getElementById("boxani"+nr).style.top=Math.round(boxOffTop+(boxes[nr]["height"]-h)/2) + "px";
      document.getElementById("boxani"+nr).style.left=Math.round(boxOffLeft+(boxes[nr]["width"]-w)/2) + "px";
      
      boxes[nr]["intv"]=window.setInterval("boxaniOn("+nr+");", 15);
    }
  }
}

function boxaniOff(nr) {
  clearInterval(boxes[nr]["intv"]);
  if(counter<20){counter++;boxes[nr]["intv"]=window.setInterval("boxaniOff("+nr+");", 10);return;}
  for(var i=0;i<hoverCSSFx.length;i++){
    eval('document.getElementById("menu"+nr).style.'+hoverCSSFx[i]["attr"]+'="'+hoverCSSFx[i]["std"]+'";');
  }
  if(boxes[nr]["state"]==0) {
    document.getElementById("boxani"+nr).style.visibility = "hidden";
    document.getElementById('boxani'+nr).style.display = "none";
    document.getElementById('menu_spacer'+nr).style.display = "none";
  }
  else {
    if (boxes[nr]["state"]==maxFrames/*+1*/) {
      document.getElementById("boxani"+nr).style.width=boxes[nr]["width"];
      document.getElementById("boxani"+nr).style.height=boxes[nr]["height"];
      boxes[nr]["state"]--;
      boxes[nr]["intv"]=window.setInterval("boxaniOff("+nr+");", 15);
      document.getElementById("sub"+nr).style.visibility = "hidden";
      document.getElementById('boxani'+nr).style.visibility = "visible";
      document.getElementById('boxani'+nr).style.display = "inline";
    }
    else {
      document.getElementById('boxani'+nr).style.visibility = "visible";
      document.getElementById('boxani'+nr).style.display = "inline";
      boxes[nr]["state"]--;
      
      var k1=Math.ceil(boxes[nr]["width"]/maxFrames);
      document.getElementById("boxani"+nr).style.width= (boxes[nr]["state"]*k1)+"px";
        
      var k2=Math.ceil(boxes[nr]["height"]/maxFrames);
      document.getElementById("boxani"+nr).style.height= (boxes[nr]["state"]*k2)+"px";

      document.getElementById("boxani"+nr).style.top=Math.round(boxOffTop+(boxes[nr]["height"]-(boxes[nr]["state"]*k2))/2) + "px";
      document.getElementById("boxani"+nr).style.left=Math.round(boxOffLeft+(boxes[nr]["width"]-(boxes[nr]["state"]*k1))/2) + "px";

      boxes[nr]["intv"]=window.setInterval("boxaniOff("+nr+");", 15);
    }
  }
}
