var tmrHide = new Array();
var rgMenus = new Array();
if ( navigator.appName.toLowerCase().indexOf('explorer') != -1 && navigator.userAgent.toLowerCase().indexOf('mac') != -1 ) var undefined="undefined";
/******************************************************************
*  LFCMenu : The top-level menu object (news, mobile, etc.)       *
*                                                                 *
*  Parameters:                                                    *
*  name - The top level drop-down menu title                      *
*  x    - The x co-ordinate of this drop-down                     *
*         (0 being the left-most point of the horizontal menu-bar *
*  est  - Boolean representing whether this drop-down consists    *
*         of e-Season items                                       *
*                                                                 *
*  Functions:                                                     *
*  addItem - Adds an LFCMenuItem to the drop-down list            *
*  create  - Generates the HTML for this menu                     *
*  show    - Displays the drop-down list on-screen                *
*  hide    - Hides the drop-down list from view                   *
*                                                                 *
******************************************************************/
function LFCMenu(name,x, est)
{
  this.x=x;
  this.id = rgMenus.length;
  this.name = name;
  this.eSeason = (est == null ? false : est);
  this.items = new Array();
  this.activeMenu = false;
  this.activeItem = false;
  this.addItem = function()
  {
    this.items[this.items.length] = new LFCMenuItem(this,arguments[0],arguments[1],this.items.length,arguments[2]);
  };
  this.create = function()
  {
    document.writeln('<div id="'+this.name+'" style="position:absolute;visibility:hidden;height:1px;z-index:5">');
    document.writeln('<table style="border-top:solid 1px;border-right:solid 1px;border-left:solid 1px;border-bottom:solid 1px;border-color:#000000" cellspacing=0 cellpadding=2>\n');
    for ( i = 0; i < this.items.length; i++ )
        document.writeln('<tr>'+this.items[i].getHTML()+'</tr>');
    document.writeln('</table>');
    document.writeln('</div>');
  };
  this.show = function()
  {
    if ( document.all )
    {
      table = document.all['menutable'];
      bar = document.all['menubar'];
      menu = document.all[this.name];
      tableLeft = table.offsetLeft;
      lmargin = 3;
    }
    else if ( document.getElementById )
    {
      table = document.getElementById('menutable');
      bar = document.getElementById('menubar');
      menu = document.getElementById(this.name);
      tableLeft = (window.innerWidth - table.width) / 2;
      lmargin = 6;
    }
    if ( this.eSeason == true )
      menu.style.left = (tableLeft+bar.offsetLeft+this.x-menu.offsetWidth-lmargin)+"px";
    else
      menu.style.left = (tableLeft+bar.offsetLeft+this.x-lmargin)+"px";
    menu.style.top = (table.offsetHeight+175)+"px";  //147 è la distanza dall'alto del menu
    this.activeMenu = true;
    menu.style.visibility = 'visible';
    for ( i = 0; i < rgMenus.length; i++ )
    {
      if ( rgMenus[i].id != this.id )
        rgMenus[i].hide(true,true);
    }
  };
  this.hide = function(active,hideItems)
  {
    if ( document.all )
      menu = document.all[this.name];
    else if ( document.getElementById )
      menu = document.getElementById(this.name);
    
    if ( active == null )
    {
      this.activeMenu = false;
      if ( !tmrHide[this.id] )
        tmrHide[this.id] = setInterval(this.name+".hide(true)",500);
      return ;
    }
    if ( hideItems != null )
      this.activeItem == false;
    if ( this.activeMenu == false && this.activeItem == false )
    {
      menu.style.visibility = 'hidden';
      if ( tmrHide[this.id] )
      {
        clearInterval(tmrHide[this.id]);
        tmrHide[this.id] = null;
      }
      return ;
    }
    if ( !tmrHide[this.id] )
      tmrHide[this.id] = setInterval(this.name+".hide(true)",500);
  };
  rgMenus[rgMenus.length] = this;
}
/******************************************************************
*  LFCMenuItem : The links underneath each top-level menu         *
*                                                                 *
*  Parameters:                                                    *
*  owner  - The top-level menu to which this belongs              *
*  name   - The link title                                        *
*  url    - The URL for this item                                 *
*  pos    - The item's position within the drop-down list         *
*                                                                 *
*  Optional Parameters:                                           *
*  win    - If the link is to open in a new pop-up window this is *
*           the window's associated name                          *
*           If "_blank" is supplied, use default parameters,      *
*           unless some are supplied                              *
*  params - If the link is to open in a new pop-up window these   *
*           are the parameters for that window                    *
*                                                                 *
*  Functions:                                                     *
*  getHTML - Produces the HTML for this link                      *
*                                                                 *
******************************************************************/
function LFCMenuItem(owner,name, url, pos, win, params)
{
  this.owner = owner;
  this.name = name;
  this.url = url;
  this.pos = pos;
  this.css = "menu";
  this.win = win;
  this.params = params;
  if ( this.params == null )
  {
    if ( this.win == "_blank" )
      this.params = ",'menubar=yes,resizable=yes,scrollbars=yes,location=yes,status=yes,toolbar=yes'";
    else
      this.params = "";
  }
  if ( this.owner.eSeason )
  {
    this.css = "est";
    if ( this.win != "this" )
    {
      this.win = "console";
      this.params = ",'width=778,height=220,scrollbars=no'";   //548
    }
  }
  if ( this.win == "this" )
    this.win = null;
  this.getHTML = function()
  {
    if ( this.win != null )
      return '<td id="menu'+this.owner.id+'-'+this.pos+'" class="'+this.css+'Out" onMouseOver="this.className=\''+this.css+'Over\';'+this.owner.name+'.activeItem=true;" onMouseOut="this.className=\''+this.css+'Out\';'+this.owner.name+'.activeItem=false;" onMouseUp="window.open(\''+this.url+'\',\''+this.win+'\''+this.params+');"><div class="menuLink">'+this.name+'</div></td>\n';
    else
      return '<td id="menu'+this.owner.id+'-'+this.pos+'" class="'+this.css+'Out" onMouseOver="this.className=\''+this.css+'Over\';'+this.owner.name+'.activeItem=true;" onMouseOut="this.className=\''+this.css+'Out\';'+this.owner.name+'.activeItem=false;" onMouseUp="location.href=\''+this.url+'\';"><div class="menuLink">'+this.name+'</div></td>\n';
  }
}
function initMenuBar()
{

  menuNews = new LFCMenu("menuNews",54);
  menuNews.addItem("Ultime News","news.php");
  menuNews.addItem("News 2006","news06.php");
  menuNews.addItem("News 2005","news05.php");
  menuNews.addItem("News 2004","news04.php");
  menuNews.create();
  menuSocieta = new LFCMenu("menuSocieta",112);
  menuSocieta.addItem("Società","societa.php");
  menuSocieta.addItem("Staff","staff.php");
  menuSocieta.addItem("Come trovarci","mappa.php");
  menuSocieta.addItem("Contatti","contatti.php");
  menuSocieta.create();
  menuDraghi = new LFCMenu("menuDraghi",210);
  menuDraghi.addItem("Roster","roster.php");
  menuDraghi.addItem("Calendario","calendario.php");
  menuDraghi.addItem("Classifica","classifica.php");
  menuDraghi.addItem("Allenamenti","allenamenti.php");
  menuDraghi.addItem("Game day","http://www.draghiudine.it/pagine/gameday.html","_blank");
  menuDraghi.addItem("Statistiche","statistiche.php");
  menuDraghi.create();
  menuFires = new LFCMenu("menuFires",320);
  menuFires.addItem("Roster", "rosterfires.php");
  menuFires.addItem("Calendario","http://www.fidaf.org/index.php?src=Html/calendari.php?id_campionato=3&scroll=auto");
  menuFires.addItem("Classifica","http://www.fidaf.org/index.php?src=Html/calendari.php?id_campionato=3&scroll=auto");
  menuFires.addItem("Gameday","http://www.fidaf.org/Public/statistiche/K10/K1000734.htm","_blank");
  menuFires.addItem("Allenamenti","allenamenti.php");
  menuFires.create();
  menuFanzone = new LFCMenu("menuFanzone",420);
  menuFanzone.addItem("Archivio","archivio.php");
  menuFanzone.addItem("Flag","flag.php");
  menuFanzone.addItem("Football","football.php");
  menuFanzone.addItem("Gallery","gallery.php");
  menuFanzone.addItem("Video","http://www.aftv.eu/category/tag/draghi-udine","_blank");
  menuFanzone.addItem("Negozio","shop.php");
  menuFanzone.addItem("Storia","storia.php");
  menuFanzone.create();
  positionEST();
}
function positionEST()
{
  if ( document.all )
  {
    table = document.all['menutable'];
    bar = document.all['menubar'];
    est = document.all['estlink'];
    est.style.left = (table.offsetLeft+590)+"px";
  }
  else if ( document.getElementById )
  {
    table = document.getElementById('menutable');
    bar = document.getElementById('menubar');
    est = document.getElementById('estlink');
    est.style.left = (((window.innerWidth - 771) / 2)+580)+"px";
  }
  est.style.top = "118px"; //118
  est.style.visibility = "visible";
}

