function Menu(name, extension)
{
 this.name = name;
 if (extension == undefined)
  extension = ".html";
 if (name != "home")
  this.file = name + extension;
 else
   this.file = "http://www.tjallstars.com";
 this.fade = 0;
 this.opacity = 0;
}

Menu.prototype.name;
Menu.prototype.file;
Menu.prototype.image;
Menu.prototype.fade;
Menu.prototype.opacity;

var change = 20;
var duration = 25;

var menus = new Array();

var filename = getFileName();
if (filename == "")
 filename = "home";
if (filename == "purchase")
 filename = "music";
if (filename == "sign_guestbook")
 filename = "guestbook";
if (filename == "photo")
 filename = "photos";
var animating = false;

var frame = 0;

function load()
{
 for (i in menus)
 {
  var menu = menus[i];
  menu.image = document.getElementById(menu.name);
  if (menu.name == filename)
   //menu.fade = change;
   setOpacity(menu.image, 100);
  else
   setOpacity(menu.image, 0);
  if (menu.image.style != null)
   menu.image.style.visibility = 'visible';
 }
 var table = document.getElementById("table");
 window.setTimeout("animate()", duration);
}

function animate()
{
 var fading = 0;
 for (i in menus)
 {
  var menu = menus[i];
  if (menu.fade != 0)
  {
   menu.opacity += menu.fade;
   setOpacity(menu.image, menu.opacity);
   if ((menu.fade == change && menu.opacity >= 100) || (menu.fade == -change && menu.opacity <= 0))
    menu.fade = 0;
   if (menu.fade != 0)
    fading++;
  }
 }
 if (fading > 0)
  window.setTimeout("animate()", duration);
}

function mouseOver(index)
{
 menus[index].fade = change;
 window.setTimeout("animate()", duration);
}

function mouseOut(index)
{
 menus[index].fade = -change;
 window.setTimeout("animate()", duration);
}

function WriteHeader()
{
 document.write("<title>Tommy James and his Allstars</title>");
 document.write("<link rel='stylesheet' type='text/css' href='stylesheet.css'>");
}

function WriteMenus()
{
 for (i in menus)
 {
  var menu = menus[i];
  document.write("<tr><td width=162 height=24 background='menus/" + menu.name + ".gif'");
  if (menu.name != filename)
   document.write(" onmouseover='mouseOver(" + i + ")' onmouseout='mouseOut(" + i + ")'");
  document.write("><a href='" + menu.file + "'>");
  document.write("<img id='" + menu.name + "' src='menus/" + menu.name + "_over.gif' style='visibility: hidden'></a></td></tr>");
 }
}

function WriteBodyStart(onLoadMethod)
{
 if (onLoadMethod == undefined)
  onLoadMethod = "load()";
 document.write("<body bgcolor='#4D4D4D' topmargin=0 leftmargin=0 onload='" + onLoadMethod + "'>");
 document.write("<table align=center cellspacing=0 cellpadding=0 border=0>"); //begin main table
 
 document.write("<tr>"); //begin blank row
 document.write("<td colspan=4 width=780 height=5></td>"); 
 document.write("</tr>");

 document.write("<tr>"); //begin top row
 document.write("<td width=5 align='right'><img src='main/top_left.gif'></td>"); 
 document.write("<td colspan=2><img src='main/top.gif'></td>");
 document.write("<td width=5 align='left'><img src='main/top_right.gif'></td>");
 document.write("</tr>");

 document.write("<tr>"); //begin banner row
 document.write("<td background='main/left.gif' align='right' valign='top'><img src='main/left_top_edge.gif'></td>"); 
 document.write("<td colspan=2><a href='http://www.tjallstars.com'><img height=160 src='main/banner.jpg'></a></td>");
 document.write("<td background='main/right.gif' align='left' valign='top'><img src='main/right_top_edge.gif'></td>");
 document.write("</tr>");
 
 document.write("<tr>"); //begin center row

 document.write("<td background='main/left.gif' align='right' valign='baseline'><img src='main/left_bottom_edge.gif'></td>");

 document.write("<td width=162 height=100% valign=top background='menus/gradient.gif'>");
 document.write("<table cellspacing=0 cellpadding=0 border=0 height=100%>");
 document.write("<tr><td height=12></td></tr>");
 WriteMenus();
 document.write("<tr><td height=150></td></tr>");
 document.write("<tr><td></td></tr>");
 document.write("</table>");
 document.write("</td>");
 
 document.write("<td valign=top bgcolor='#FFFFFF'><table width=608 cellpadding=5><tr><td>");
}

function WriteBodyEnd()
{
 document.write("</td><td></td></tr></table></td>"); 
 document.write("<td width=5 background='main/right.gif' align='left' valign='baseline'><img src='main/right_bottom_edge.gif'></td>");
 document.write("</tr>");

 document.write("<tr>"); //start bottom row
 document.write("<td valign='top'><img src='main/bottom_left.gif'></td>"); //bottom left cell
 document.write("<td background='main/bottom.gif' valign='top'>"); 
 document.write("<a href='mailto:tom@tjallstars.com'><img src='main/email.gif' /></a><br /><img src='main/phone.gif' /></td>");
 document.write("<td background='main/bottom.gif' align='right' valign='top'>");
 document.write("<a href='http://www.mayergraphics.com' target='_blank'><img src='main/logo.gif' /></a></td>");
 document.write("<td valign='top'><img src='main/bottom_right.gif'></td>"); //bottom right cell
 document.write("</tr>"); //end bottom row

 document.write("<tr>"); //begin blank row
 document.write("<td colspan=4 height=10></td>"); 
 document.write("</tr>");

 document.write("</table>"); //end main table
 document.write("</body>");
}

function getFileName() 
{
 var file = document.location.href;

 var start = file.lastIndexOf("/");

 if (start == -1) return;
 finish = file.indexOf(".", start + 1);

 return file.slice(start + 1, finish);
}

function fadeIn(index,opacity) 
{
 if (document.getElementById) 
 {
  obj = document.getElementById(menus[index].name);
  if (opacity <= 100) 
  {
   setOpacity(obj, opacity);
   opacity += 10;
   window.setTimeout("fadeIn('"+index+"',"+opacity+")", 16);
  }
 }
}

function setOpacity(obj, opacity) 
{
  opacity = (opacity == 100)?99.999:opacity;

  if (obj == null)
   return;

  if (obj.style == null)
   return;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function getPath() 
{
 var path = document.location.href;
 var position = path.indexOf("body/");
 if (position == -1) return;
 slash = path.indexOf("/", position + 5);
 return path.slice(position + 5, slash + 1) + document.title;
}
