// ***************************************************
// ***** CLASS: MenuItem *****************************
// ***************************************************
function MenuItem(label, ref)
{
  this.label = label;
  this.ref = ref;

  this.getLabel = function getLabel() { return this.label; };
  this.getRef = function getRef() { return this.ref; };
}

// ***************************************************
// ***** CLASS: FlagItem *****************************
// ***************************************************
function FlagItem(img, language)
{
  this.img = img;
  this.language = language;

  this.getImg = function getImg() { return this.img; };
  this.getLanguage = function getLanguage() { return this.language; };
}

// ***************************************************
// ***** CLASS: Menu *********************************
// ***************************************************
function Menu(language)
{
	this.language = language;
	this.menuItems = new Array();
	this.flagItems = new Array();
	
	this.populateFlagItems = function populateFlagItems()
	{
      this.flagItems.push(new FlagItem("images/frflagsmall.jpg", "FR"));
	  this.flagItems.push(new FlagItem("images/ukflagsmall.jpg", "EN"));
	}
	
	this.draw = function draw()
    {
	  this.language = getLanguage();
	  this.populateMenuItems();	
      var headerDiv = document.getElementById("header");
	  var menuTable = document.createElement("table");
	  menuTable.setAttribute("align", "center");
	  var menuRow = document.createElement("tr");

	  for (var i = 0; i < this.menuItems.length; i++)
	  {
	    var cellElem = document.createElement("td");		
		cellElem.appendChild(createAnchor(this.menuItems[i].getRef(), this.menuItems[i].getLabel(), "menuanchor"));
		menuRow.appendChild(cellElem);
		if (i != this.menuItems.length - 1)
		  menuRow.appendChild(createSpacerCell(10, 0));
	  }
	  menuTable.appendChild(menuRow);
      menuRow.appendChild(createSpacerCell(30, 0));

	  this.populateFlagItems();
	  var url = document.location.href.split('?language=')[0] + "?";
	  for (var i = 0; i < this.flagItems.length; i++)
	  {
		if (this.flagItems[i].getLanguage() != this.language)
		{
    	  cellElem = document.createElement("td");			
          var imgElem = document.createElement("img");
		  imgElem.setAttribute("src", this.flagItems[i].getImg());
		  imgElem.setAttribute("width", "20");
		  imgElem.setAttribute("height", "15");
		  
		  cellElem.appendChild(createImgAnchor(url + "language=" + this.flagItems[i].getLanguage(), imgElem, "flaganchor"));
    	  menuRow.appendChild(cellElem);
		  if (i != this.flagItems.length - 1)
		    menuRow.appendChild(createSpacerCell(5, 0));
		}
	  }

	  headerDiv.appendChild(menuTable);
	}
	
	this.populateMenuItems = function populateMenuItems()
    {
	  if (this.language == null) this.language = "EN";
	  
	  switch (this.language)
	  {
	    case "FR":
		  this.menuItems.push(new MenuItem("Page d'acceuil", "index.html?language=" + this.language));			  
    	  this.menuItems.push(new MenuItem("Biographie", "biography.html?language=" + this.language));		  
    	  this.menuItems.push(new MenuItem("Agenda", "concerts.html?language=" + this.language));
    	  this.menuItems.push(new MenuItem("Discographie", "discography.html?language=" + this.language));	  
    	  this.menuItems.push(new MenuItem("Audio & Vidéo", "audiovideo.html?language=" + this.language));				
		  this.menuItems.push(new MenuItem("Presse", "press.html?language=" + this.language));		
		  this.menuItems.push(new MenuItem("Photos", "pictures.html?language=" + this.language));
		  this.menuItems.push(new MenuItem("Répertoire", "repertoire.html?language=" + this.language));	
		  this.menuItems.push(new MenuItem("Livre d'or", "guestbook.php?language=" + this.language));			  
		  this.menuItems.push(new MenuItem("Contact", "contact.html?language=" + this.language));			  		  
		  break;
	  default:
		  this.menuItems.push(new MenuItem("Home", "index.html?language=" + this.language));			  
    	  this.menuItems.push(new MenuItem("Biography", "biography.html?language=" + this.language));		  		  
    	  this.menuItems.push(new MenuItem("Concert Schedule", "concerts.html?language=" + this.language));
    	  this.menuItems.push(new MenuItem("Discography", "discography.html?language=" + this.language));	  
    	  this.menuItems.push(new MenuItem("Audio & Video", "audiovideo.html?language=" + this.language));				
		  this.menuItems.push(new MenuItem("Press", "press.html?language=" + this.language));		
		  this.menuItems.push(new MenuItem("Pictures", "pictures.html?language=" + this.language));
		  this.menuItems.push(new MenuItem("Repertoire", "repertoire.html?language=" + this.language));				
		  this.menuItems.push(new MenuItem("Guestbook", "guestbook.php?language=" + this.language));			  		
		  this.menuItems.push(new MenuItem("Contact", "contact.html?language=" + this.language));			  		  		  
		  break;
	}
  }
}

function initializeMenu()
{
  var menu = new Menu("EN");
  menu.draw();
}