var BoxStatic = {
  boxs:[],
  init:function()
  {
    var tempImage = [];
    var imageList = ["Loading.gif","About.png","Contact.png","Back.png","Bottom.png","Bottom_Left.png","Bottom_Right.png","Head.png","Head_Left.png","Head_Right.png","Menu.png","Menu_hover.png","Shade.png","Trans.png","Close.png","Close_Back.png","Close_Back_hover.png","Close_Hover.png"];
    for(var i = 0; i < imageList.length; i++)
    {
      tempImage.push(new Image())
      tempImage[i].src = Global.toRoot+"Layout/Images/Box/"+imageList[i];
    }
  },
  add:function()
  {
    var box = new Box(BoxStatic.boxs.length);
    BoxStatic.boxs.push(box);
    return box;
  },
  close:function(id)
  {
    if(isNaN(id))
    {
      id = this.getAttribute("name");
      if(this.onmouseout != undefined)
      {
        this.onmouseout();
      }
    }
    if(BoxStatic.boxs[id] != null)
    {
      BoxStatic.boxs[id].close();
      BoxStatic.boxs[id] = null;
    }
    return false;
  },
  
  // Menu
  openMenu:function()
  {
    this.focus();
    this.parentNode.getElementsByTagName("ul")[0].style.display = "block";
    return false;
  },
  closeMenus:[],
  closeMenu:function()
  {
    BoxStatic.closeMenus.push(this);
    setTimeout("BoxStatic.closingMenu();", 200);
  },
  closingMenu:function()
  {
    while(BoxStatic.closeMenus.length > 0)
    {
      BoxStatic.closeMenus.shift().parentNode.getElementsByTagName("ul")[0].style.display = "none";
    }
  },
  
  open:function(id, url)
  {
    if(isNaN(id))
    {
      id = this.getAttribute("name");
      url = this.getAttribute("href");
    }
    if(BoxStatic.boxs[id] != null)
    {
      BoxStatic.boxs[id].open(url);
    }
    return false;
  },
  sendMail:function(id)
  {
    if(isNaN(id))
    {
      id = this.getAttribute("name");
    }
    if(BoxStatic.boxs[id] != null)
    {
      BoxStatic.boxs[id].sendMail();
    }
    return false;
  },
  // Move
  activeBox:null,
  
  moveStart:function(event, id)
  {
    if(isNaN(id))
    {
      id = this.parentNode.getAttribute("id").replace(/box_/ig, "");
    }
    if(BoxStatic.boxs[id] != null)
    {
      try
      {
        var disableThis = document.getElementById("main");
        disableThis.onselectstart = function() { return false;};
        disableThis.unselectable = "on";
        disableThis.style.MozUserSelect = "none";
      } catch(e){}
      
      BoxStatic.activeBox = id;
      BoxStatic.boxs[BoxStatic.activeBox].moveStart(event);
    }
  },
  moveStop:function()
  {
    if(BoxStatic.boxs[BoxStatic.activeBox] != null)
    {
      try
      {
        var disableThis = document.getElementById("main");
        disableThis.onselectstart = "";
        disableThis.unselectable = "off";
        disableThis.style.MozUserSelect = "";
      } catch(e){}
      
      BoxStatic.boxs[BoxStatic.activeBox].moveStop();
      BoxStatic.activeBox = null;
    }
  },
  move:function(event)
  {
    if(BoxStatic.boxs[BoxStatic.activeBox] != null)
    {

      if(window.event != undefined)  // ie
      {
        try
        {
          document.selection.empty();
        }catch(e){}
      }
      BoxStatic.boxs[BoxStatic.activeBox].move(event);
    }
  }
}
