/* This javascript defined the main menu */
var indx = 0;
var menuDb = new Array();
for (i=0;i<20;i++)
  menuDb[i]=new Array();
var submenu = new Array();
var myWhich = -1;
var alertTimerId = 0;
var opener;

// load menu
menuAdd(1 ,0, "Home", "home.htm");
menuAdd(2 ,0, "Concerti", "concerti.htm");
menuAdd(3 ,0, "La band", "");
  menuAdd(3 ,1, "chi", "chi.htm" );
  menuAdd(3 ,2, "dove", "dove.htm" );
  menuAdd(3 ,3, "cosa", "cosa.htm" );
menuAdd(4 ,0, "Musica", "");
  menuAdd(4 ,1, "mp3", "mp3.htm" );
  menuAdd(4 ,2, "repertorio", "repertorio.htm" );
menuAdd(5 ,0, "Storia", "");
  menuAdd(5 ,1, "esperienze", "esperienze.htm" );
  menuAdd(5 ,2, "concerti", "concertiold.htm" );
  menuAdd(5 ,3, "galleria", "galleria.htm" );
menuAdd(6 ,0, "Approfondimenti", "approfondimenti.htm");
menuAdd(7 ,0, "Corsi", "corsi.htm");
menuAdd(8 ,0, "Galleria", "galleria.htm" );
menuAdd(9 ,0, "Link", "");
  menuAdd(9 ,1, "amici", "amici.htm" );
  menuAdd(9 ,2, "siti", "siti.htm" );
menuAdd(10 ,0, "Contatti", "contatti.htm");


if (document.images)
{
  preload_image_object = new Image();
  
  // set image url
  image_url = new Array();
  image_url[0] = "images/back.gif";
  image_url[1] = "images/up.gif";
  image_url[2] = "images/down.gif";
  image_url[3] = "images/play.gif";
  image_url[4] = "images/rew.gif";
  image_url[5] = "images/pause.gif";
  image_url[6] = "images/forw.gif";
  image_url[7] = "images/back_glow.gif";
  image_url[8] = "images/up_glow.gif";
  image_url[9] = "images/down_glow.gif";
  image_url[10] = "images/play_glow.gif";
  image_url[11] = "images/rew_glow.gif";
  image_url[12] = "images/pause_glow.gif";
  image_url[13] = "images/forw_glow.gif";

   var i = 0;
   for(i=0; i<=13; i++) 
     preload_image_object.src = image_url[i];
}



function menuAdd(padreIndx,figlioIndx,display,URL){
  menuDb[padreIndx][figlioIndx]         = new Object;
  menuDb[padreIndx][figlioIndx].display = display;
  menuDb[padreIndx][figlioIndx].URL     = URL;
}

/* funzione di creazione menu e submenu */
function menuCrea(){
  var topMenuTabs="";
  var topLen = menuDb.length;
  var initSubTab='<table width="100%" height="15" cellspacing="0" cellpadding="0"><tr><td width="5">&nbsp;</td>';
  var endSubTab='</tr></table>';

  for (var i = 0; i < topLen; i++){
    var subLen = menuDb[i].length;
    submenu[i]=initSubTab;       
    for (var j = 0; j < subLen; j++){
      if (j==0){
         // topMenu
         var myUrl = '<a class="MENU" href="javascript:void(0);" onMouseout="hideit('+i+');" onMouseover="showit('+i+');">'+menuDb[i][j].display+'</a>';
         if(menuDb[i][j].URL != ""){
           myUrl = '<a href="'+ menuDb[i][j].URL +'" target="contenuto" onMouseout="hideit('+i+');" onMouseover="showit('+i+');">'+menuDb[i][j].display+'</a>';	
         }
         topMenuTabs = topMenuTabs + 
           '<td>'+
           '    <table class="YELLOW" width="100%" height="25">'+
           '          <tr>'+
           '            <td nowrap class="ORANGE" id="'+i+'" width="100%">' +
           '              &nbsp;&nbsp;' + myUrl + '&nbsp;&nbsp;' +
           '            </td>' +
           '      </tr>' +
           '    </table>' +
           '</td>';
      } else {
         // subMenu
         submenu[i]=submenu[i]+
         '<td>' +
         '  <table width="100%" class="YELLOW" height="15">' +
         '    <tr>' +
         '      <td nowrap class="ORANGE" onmouseover="className=\'YELLOW\';" onmouseout="className=\'ORANGE\';">' +
         '        &nbsp;<a target="contenuto" href="'+ menuDb[i][j].URL +'">'+ menuDb[i][j].display +'</a>&nbsp;' +
         '      </td>' +
         '    </tr>' +
         '  </table>' +
         '</td>';
         
         if (j== (subLen-1))
            submenu[i]=submenu[i]+endSubTab;
      }
    }
  }
  return topMenuTabs;  
}

/* funzione che mostra il sottomenu e lo posiziona in corrispondenza del tab*/ 
function showit(which) {
  clearTimeout ( alertTimerId );

  //ricavo le coordinate LEFT e TOP della voce di menu selezionata
  var thisParent = document.getElementById(which);
  var myLeft = 0;
  var myTop = 0;
  var trParent = thisParent.offsetParent;
  
  myLeft += trParent.offsetLeft; 
  myTop += trParent.offsetTop;
  while (trParent.offsetParent.tagName != 'BODY') {
	  trParent = trParent.offsetParent;	//get the next parent up the nest
	  myLeft += trParent.offsetLeft;
	  myTop += trParent.offsetTop;
	}
	
  // identifico il sottomenu da visualizzare
  thecontent=(which==-1)? "" : submenu[which]
  
  // visualizzo e posiziono il sottomenu
  obj = document.getElementById('subTable');
  obj.innerHTML=thecontent
  obj.style.left = myLeft;
  obj.style.top = myTop + thisParent.offsetTop + thisParent.offsetHeight;
  obj.style.visibility = 'visible';
  thisParent.className='YELLOW';
}

/* funzione che porta il tab menua non selezionato */
function hideit(which) {
	myWhich = which;
	var thisParent = document.getElementById(myWhich);
  thisParent.className='ORANGE';
  alertTimerId = window.setInterval("hide()", 2500);     
}

function hide() {
	var thisParent = document.getElementById(myWhich);
  var myLeft = 0;
  var myTop = 0;
  var trParent = thisParent.offsetParent;
  myLeft += trParent.offsetLeft; 
  myTop += trParent.offsetTop;
  while (trParent.offsetParent.tagName != 'BODY')
        {
	trParent = trParent.offsetParent;	//get the next parent up the nest
	myLeft += trParent.offsetLeft;
	myTop += trParent.offsetTop;
	}
  // identifico il sottomenu da visualizzare
  thecontent=(myWhich==-1)? "" : submenu[myWhich]	
  obj = document.getElementById('subTable');
  obj.innerHTML=thecontent;
  obj.style.left = myLeft;
  obj.style.top = myTop + thisParent.offsetTop + thisParent.offsetHeight;
  obj.style.visibility = 'hidden';	
}

/* funzione che mostra fotografie in una popup window */
function displayImage(picURL,picWidth,picHeight,picTitle) {
	if (opener && !opener.closed){
    opener.close();
  }
  var d = new Date();
  var winName = 'newWin' + d.getTime();
	var attributes = 'scrollbars=no,resizable=no,toolbar=no,menubar=no,status=no,width=' + picWidth + ',heigth=' + picHeight;
  var newWindow = window.open("", winName, attributes);
  var currentWidth = parseInt(picWidth, 10) + 75;
  var currentHeight = parseInt(picHeight, 10) + 115;
  var str = '<html>' +
    '  <head>' + 
    '    <title>'+picTitle+'</title>' +
    '    <link REL="stylesheet" HREF="css/index.css" TYPE="text/css">' +
    '  </head>' +
    '  <body><br>' +
    '    <table align="center" cellspacing="0" cellpadding="0">' +
    '      <tr>' +
    '        <td>' +
    '          <img border="1"  width="'+ picWidth+'" heigth="'+picHeight+'"src="'+picURL+'" title="' + picTitle + '">' +
    '        </td>' +
    '      </tr>' +
    '    </table>' + 
    '  </body>' +
    '</html>';
  var popdoc = newWindow.document; 

  /*
  var currentWidth = newWindow.document.body.clientWidth;
  var currentHeight = newWindow.document.body.clientHeight;
  var test = 'picWidth[' + picWidth + ']\n picHeight[' + picHeight + ']\n ' +
    'document.body.clientWidth[' + document.body.clientWidth + ']\n + document.body.clientHeight[' +  document.body.clientHeight + 
    ']\n newWindow.innerWidth[' + newWindow.innerWidth + ']\n newWindow.innerHeight[' + newWindow.innerHeight + ']';
  alert(test);
  newWindow.resizeBy(picWidth - currentWidth + 35, picHeight - currentHeight + 35);
  */
  
  newWindow.resizeTo(currentWidth, currentHeight);
  popdoc.write(str); 
  popdoc.close(); 
  newWindow.focus();
  opener = newWindow;
}



/* funzione per tornare in alto nella pagina precedente */
function backAndUp() { 	
		frames['contenuto'].history.go(-1);
	  up();
}

function up() { 
	  window.scrollTo(0,0);
}


function down() { 	
	 window.scrollTo(0,1400);
}

var last = 0;
function adjustFrame(){

  window.frames.contenuto.scrollBy(0,200);
  currTop = window.frames.contenuto.document.body.scrollTop;
  if (currTop > 0)
  {
    currHeight = document.getElementById('contenuto').getAttribute('height');
    currHeight++;
    
    /* alert("last, currtop, currheigth [" + last + ", " + currTop + ", " + currHeight + "]"); */
    document.getElementById('contenuto').setAttribute('height',currHeight);
    if(last >= currTop) {
      document.getElementById('contenuto').setAttribute('height',last + 400);
      last = 0;
    } else {
      last = currTop;
      adjustFrame();
    }
  }
}

function setHeight(){
 document.getElementById('contenuto').setAttribute('height',0);
 adjustFrame();
}



