function Menu(name)
{
 this.name = name;
 if (name != "home")
  this.file = name + ".html";
 else
   this.file = "http://www.mayergraphics.com";
 //this.image = new Image();
 //this.image.src = "menus/" + name + "_down.gif";
 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();

menus[0] = new Menu("home");
menus[1] = new Menu("portfolio");
menus[2] = new Menu("services");
menus[3] = new Menu("contact");

var filename = getFileName();
if (filename == "")
 filename = "home";
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);
  menu.image.style.visibility = 'visible';
 }
 window.setTimeout("animate()", duration);
 /*imageId = 'home';
 image = document.getElementById(imageId);
 setOpacity(image, 0);
 image.style.visibility = 'visible';*/
 //fadeIn(imageId,0);
}

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 WriteMenus()
{
 for (i in menus)
 {
  var menu = menus[i];
  document.write("<tr><td width=181 height=33 background='menus/" + menu.name + ".gif'");
  if (menu.name != filename)
   document.write(" onmouseover='mouseOver(" + i + ")' onmouseout='mouseOut(" + i + ")'");
  document.write("><a href='" + menu.name + ".html'>");
  document.write("<img id='" + menu.name + "' src='menus/" + menu.name + "_down.gif' style='visibility: hidden'></a></td></tr>");
 }
}

function WriteHeader()
{
 document.write("<title>Mayer Graphics</title>");
 document.write("<link rel='stylesheet' type='text/css' href='stylesheet.css'>");
}

function WriteBodyStart()
{
 document.write("<body bgcolor='#E5E5E5' topmargin=0 leftmargin=0 onload='load()'>")
 document.write("<div>");
 document.write("<table align=center cellspacing=0 cellpadding=0 border=0>"); //begin main table
 
 document.write("<tr>"); //begin top row
 document.write("<td align='right'><img width=5 height=32 src='main/top_left_shadow.gif'></td>"); //top left cell
 document.write("<td><a href='mailto:contact@mayergraphics.com'><img width=781 height=32 src='main/contact.gif'></a></td>");
 document.write("<td align='left'><img width=5 height=32 src='main/top_right_shadow.gif'></td>");
 document.write("</tr>");
 
 document.write("<tr>"); //begin center row
 document.write("<td background='main/left_shadow.gif' align='right'><img width=1 height=1 src='main/clear.gif'></td>"); //center left cell
 document.write("<td width=781 align=center>"); //begin center cell
 document.write("<table cellspacing=0 cellpadding=0 border=0>"); //begin center table
 document.write("<tr><td><a href='http://www.mayergraphics.com'><img width=781 height=146 src='main/banner.jpg'></a></td></tr>"); 
 
 document.write("<tr>"); //begin interface row
 document.write("<td bgcolor='#FFFFFF'>"); //begin interface column
 document.write("<table cellspacing=0 cellpadding=0 border=0><tr>"); //begin interface table

 document.write("<td width=181 valign=top>"); //begin menu column
 document.write("<table width=181 cellspacing=0 cellpadding=0 border=0>"); //begin menu table

 document.write("<tr><td><img width=181 height = 55 src='menus/top.jpg'></td></tr>"); //top row

 for (i in menus)
 {
  var menu = menus[i];
  document.write("<tr><td width=181 height=33 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 width=181 height=33 id='" + menu.name + "' src='menus/" + menu.name + "_down.gif' style='visibility=hidden'></a></td></tr>");
 }

 /*document.write("<tr><td width=181 height=33 background='menus/home.gif' onmouseover='fadeIn(0,0)'><a href='home.html'><img id='home' src='menus/home_down.gif' style='visibility=hidden'></a></td></tr>"); //top row
 document.write("<tr><td><img src='menus/portfolio.gif'></td></tr>"); //top row
 document.write("<tr><td><img src='menus/services.gif'></td></tr>"); //top row
 document.write("<tr><td><img src='menus/contact.gif'></td></tr>"); //top row*/

 document.write("<tr><td><img width=181 height=125 src='menus/bottom.gif'></td></tr>"); //bottom graphic row
 document.write("<tr><td height=5></td></tr>"); //bottom graphic row

 document.write("</table>"); //end menu table
 document.write("</td>"); //end menu column

 document.write("<td valign=top>"); //begin body column
 document.write("<table><tr><td height=5 colspan=2></tr><tr></td><td width=5></td><td>"); //begin body table
 
}

function WriteBodyEnd()
{
 document.write("</td></tr></table>"); //end body table
 document.write("</td>"); //end body column
 
 document.write("</tr></table>"); //end interface table
 document.write("</td>"); //end interface column
 document.write("</tr>"); //end interface row


 document.write("</table>"); //end center table
 document.write("</td>"); //end center cell
 document.write("<td background='main/right_shadow.gif' align='left'><img width=1 height=1 src='main/clear.gif'></td>");
 document.write("</tr>"); //end center row

 document.write("<tr>"); //start bottom row
 document.write("<td><img width=5 height=32 src='main/bottom_left_shadow.gif'></td>"); //bottom left cell
 document.write("<td background='main/footer.gif'></td>"); //bottom cell
 document.write("<td><img width=5 height=32 src='main/bottom_right_shadow.gif'></td>"); //bottom right cell
 document.write("</tr>"); //end bottom row

 document.write("</table>"); //end main table
 document.write("</div>");
 document.write("</body>");
}

function getFileName() {
var file = document.location.href;

var start = file.lastIndexOf("/");

if (start == -1) return;
finish = file.indexOf(".", start + 1);

//position = path.lastIndexOf("/");

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;
  
  // 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 AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
