var menuSelected;
var menuHeight;

function menuDoLeave()
{
    window.location = menuSelected;
}

function menuSelect( url, func )
{
    menuSelected = url;
    eval(func);
    return false;
}

function writeMenu( selected, prepath, lang, func )
{
    // Declarations
    var names = [ "news",
                  "weare",
                  "multimedia",
                  "upcoming",
                  "goodies",
                  "guestbook",
                  "contact" ];
                        
    var itemHeight = 61;
    
    var nofItems   = 7;
    
    var sepName    = prepath + "/images/menu/seperator/normal.gif"
    var sepWidth   = 70;
    var sepHeight  = 80;

    var widths;
    var totalWidth;
    
    // Conditional initializations
    if ( lang == "en" )
    {
        widths = [ 151, 203, 309, 269, 226, 315, 237 ];
        totalWidth = 2130;
    }
    else
    {
        widths = [ 199, 201, 309, 306, 361, 341, 237 ];
        totalWidth = 2374;
    }
    
    // Table header
    document.writeln( '<table valign="top" cellspacing="0">' );
    document.writeln( '  <tr>' );
    
    // Calculate scaling
    var winSize = new Array(2);
    getWindowSize(top,winSize);
    var ratio = winSize[0] / totalWidth;
  
    itemHeight = Math.floor( ratio * itemHeight );
    sepWidth   = Math.floor( ratio * sepWidth );
    sepHeight  = Math.floor( ratio * sepHeight );

    // Export item height
    menuHeight = itemHeight;
    
    // Write images
    for( var i=1; i<=nofItems; i++ ) 
    {
      var itemWidth = Math.floor( ratio * widths[i-1] );

      if ( i == selected )
      {
        var normalName = prepath + "/images/menu/" + names[i-1] + "/anim_" + lang + ".gif";
        
        document.writeln( '<td>' );
        document.writeln( '  <img src="' + normalName + '" width="' + itemWidth + '" height="' + itemHeight + '" name="' + names[i-1] + '" border="0" vspace="0" hspace="0">' );
        document.writeln( '</td>' );
      }
      else
      {
        var normalName = prepath + "/images/menu/" + names[i-1] + "/normal_" + lang + ".gif";
        var selName    = prepath + "/images/menu/" + names[i-1] + "/selected_" + lang + ".gif";
        var refName;
        
        if ( names[i-1] == "guestbook" )
            refName = prepath + "/" + names[i - 1] + "/" + names[i - 1] + "_" + lang + ".php";
        else
            refName = prepath + "/" + names[i - 1] + "/" + names[i - 1] + "_" + lang + ".html";
     
        document.writeln( '<td>' );
        document.writeln( '  <a href="#" onclick="menuSelect(\'' + refName + '\',\'' + func + '\')" onmouseover="document.' + names[i-1] + '.src=\'' + selName + '\'" onmouseout="document.' + names[i-1] + '.src=\'' + normalName + '\'">' );
        document.writeln( '    <img src="' + normalName + '" width="' + itemWidth + '" height="' + itemHeight + '" name="' + names[i-1] + '" border="0" vspace="0" hspace="0">' );
        document.writeln( '  </a>' );
        document.writeln( '</td>' );
      }
      
      if ( i < nofItems )
      {
        document.writeln( '<td>' );          
        document.writeln( '  <img src="' + sepName + '" width="' + sepWidth + '" height="' + sepHeight + '" border="0" vspace="0" hspace="0">' );
        document.writeln( '</td>' );          
      }
    }
        
    // Table footer
    document.writeln( '  </tr>' );
    document.writeln( '</table>' );
}
