var ROOT = '';

var menus = {
  'menu_societa' : new Array(
    new Array('Informazioni', '/societa/informazioni.php', null),
    new Array('Storia', '/societa/storia.php', null),
    new Array('Organigramma', '/societa/organigramma.php', null),
    new Array('Eventi', '/societa/eventi.php', null)
  ),
  'menu_psm' : new Array(
    new Array('News', '/primam/news.php', null),
    new Array('Rosa', '/primam/rosa.php', null),
    new Array('Campionato', '', new Array(
      new Array('Risultati', '/primam/campionato/risultati.php'),
      new Array('Classifica', '/primam/campionato/classifica.php'),
      new Array('Calendario completo', '/primam/campionato/calendario.php?tipo=1'),
      new Array('Calendario squadra', '/primam/campionato/calendario.php?tipo=2'),
      new Array('Marcatori', '/primam/campionato/marcatori.php')
    )),
    new Array('Multimedia', '/primam/multimedia.php', null),
    new Array('Multe', '/primam/multe.php', null),
    new Array('Fantaseconda', '/primam/fantaseconda.php', null),
    new Array('Figurine', '/primam/figurine.php', null)
  ),
  'menu_psf' : new Array(
    new Array('News', '/primaf/news.php', null),
    new Array('Campionato', '/societa/organigramma.php', new Array(
      new Array('Risultati', '/primaf/campionato/risultati.php'),
      new Array('Classifica', '/primaf/campionato/classifica.php'),
      new Array('Calendario completo', '/primaf/campionato/calendario.php?tipo=1'),
      new Array('Calendario squadra', '/primaf/campionato/calendario.php?tipo=2'),
      new Array('Marcatori', '/primaf/campionato/marcatori.php')
    )),
    new Array('Multimedia', '/primaf/multimedia.php', null)
  ),
  'menu_giovanili' : new Array(
    new Array('Juniores', '/juniores/news.php', null),
    new Array('Allievi', '/allievi/news.php', null),
    new Array('Giovanissimi', '', null),
    new Array('Esordienti', '', null),
    new Array('Pulcini', '', null)
  ),
  'menu_forum' : new Array(
    new Array('Lista', '/forum/lista.php', null),
    new Array('Nuovo messaggio', '/forum/scrivi.php', null),
    new Array('Informazioni', '/forum/informazioni.php', null)
  ),
  'menu_informazioni' : new Array(
    new Array('Contatti', '/informazioni/contatti.php', null),
    new Array('Link', '/informazioni/link.php', null)
  )
};

function showMenu(nomeMenu) {
  var menu = document.getElementById(nomeMenu);

  if (document.getElementById('table_' + nomeMenu) == null) {
    var table = document.createElement('table');
    table.id = 'table_' + nomeMenu;
    table.className = 'tabella_sottomenu_discesa';
    table.width = '100%';
    table.cellPadding = '2';
    table.cellSpacing = '0';

    var tbody = document.createElement('tbody');
    table.appendChild(tbody);

    var menuObject = menus[nomeMenu];

    for (var i = 0; i < menuObject.length; i++) {
      if (menuObject[i][2] == null) {
        var tr = document.createElement('tr');
        tr.appendChild(createMenuCell('10px', '<img src="' + ROOT + '/img/freccia_dx.gif" alt="" />'));
        tr.appendChild(createMenuCell('', menuObject[i][1] != '' ? '<a href="' + ROOT + menuObject[i][1] + '" class="link_menu">' + menuObject[i][0] + '</a>' : menuObject[i][0]));
        tbody.appendChild(tr);
      } else {
        var tr1 = document.createElement('tr');
        tr1.appendChild(createMenuCell('10px', '<img src="' + ROOT + '/img/freccia_down.gif" alt="" />'));
        tr1.appendChild(createMenuCell('', menuObject[i][0]));
        tbody.appendChild(tr1);

        var tr2 = document.createElement('tr');
        tr2.className = 'norollover';
        tr2.appendChild(createMenuCell('', ''));

        var td2 = document.createElement('td');
        var tableInt = document.createElement('table');
        tableInt.className = 'sottotabella_sottomenu_discesa';
        tableInt.width = '100%';
        tableInt.cellPadding = '0';
        tableInt.cellSpacing = '0';
        var tbodyInt = document.createElement('tbody');
        tableInt.appendChild(tbodyInt);
        var sottomenuObject = menuObject[i][2];
        for (var j = 0; j < sottomenuObject.length; j++) {
          var trInt = document.createElement('tr');
          trInt.appendChild(createMenuCell('10px', '<img src="' + ROOT + '/img/freccia_dx.gif" alt="" />'));
          trInt.appendChild(createMenuCell('', sottomenuObject[j][1] != '' ? '<a href="' + ROOT + sottomenuObject[j][1] + '" class="link_menu">' + sottomenuObject[j][0] + '</a>' : sottomenuObject[j][0]));
          tbodyInt.appendChild(trInt);
        }
        td2.appendChild(tableInt);
        tr2.appendChild(td2);

        tbody.appendChild(tr2);
      }
    }

    menu.appendChild(table);
  }

  menu.style.display = menu.style.display == '' || menu.style.display == 'none' ? 'block' : 'none';
}

function createMenuCell(width, innerHTML) {
  var td = document.createElement('td');
  if (width != '') {
    td.style.width = width;
  }
  td.innerHTML = innerHTML;
  return td;
}
