﻿var tmrHide = new Array();
var rgMenus = new Array();
if ( navigator.appName.toLowerCase().indexOf('explorer') != -1 && navigator.userAgent.toLowerCase().indexOf('mac') != -1 ) var undefined="undefined";

function opcfMenu(name,x,lang)
{
  this.x=x;
  this.id = rgMenus.length;
  this.name = name;
  this.imgName = "img"+name;
  this.orgImg = "";
  this.lang = (lang == null ? false : lang);
  this.items = new Array();
  this.activeMenu = false;
  this.activeItem = false;
  this.addItem = function()
  {
    this.items[this.items.length] = new opcfMenuItem(this,arguments[0],arguments[1],this.items.length,arguments[2]);
  };
  this.create = function()
  {
    document.writeln('<div id="'+this.name+'" style="position:absolute;left:10px;top:55px;visibility:hidden;height:1px;z-index:5">');
    document.writeln('<table cellspacing=0 cellpadding=0 border=0><tr>\n');
    for ( i = 0; i < this.items.length; i++ )
        //document.writeln('<td>'+this.items[i].getHTML()+'</td>');
        document.writeln(this.items[i].getHTML());
    document.writeln('</tr></table>');
    document.writeln('</div>');
	/*
	if ( document.all )
    {
	  imgMenu = document.all[this.imgName];
    }
    else if ( document.getElementById )
    {
      imgMenu = document.getElementById(this.imgName);
    }
	this.orgImg = imgMenu.src;
	*/
  };
  this.show = function()
  {
    if ( document.all )
    {
      //table = document.all['menutable'];
      //bar = document.all['menubar'];
      menu = document.all[this.name];
      //tableLeft = table.offsetLeft;
      //lmargin = -9;
    }
    else if ( document.getElementById )
    {
      //table = document.getElementById('menutable');
     // bar = document.getElementById('menubar');
      menu = document.getElementById(this.name);
     // tableLeft = (window.innerWidth - table.width) / 2;
      //lmargin = -9;
    }

    //menu.style.left = (tableLeft+bar.offsetLeft+this.x-lmargin)+"px";
   // menu.style.top = (table.offsetTop+122)+"px";
    menu.style.left = this.x+"px";
    menu.style.top = 55+"px";
    this.activeMenu = true;
    menu.style.visibility = 'visible';
    for ( i = 0; i < rgMenus.length; i++ )
    {
      if ( rgMenus[i].id != this.id )
        rgMenus[i].hide(true,true);
    }
  };
  this.hide = function(active,hideItems)
  {
    if ( document.all ) {
      menu = document.all[this.name];
	  //imgMenu = document.all[this.imgName];
     } else if ( document.getElementById ) {
      menu = document.getElementById(this.name);
	  //imgMenu = document.getElementById(this.imgName);
	 }
    if ( active == null )
    {
      this.activeMenu = false;
      if ( !tmrHide[this.id] )
        tmrHide[this.id] = setInterval(this.name+".hide(true)",400);
      return ;
    }
    if ( hideItems != null )
      this.activeItem == false;
    if ( this.activeMenu == false && this.activeItem == false )
    {
      menu.style.visibility = 'hidden';
	  //imgMenu.src=this.orgImg;
      if ( tmrHide[this.id] )
      {
        clearInterval(tmrHide[this.id]);
        tmrHide[this.id] = null;
      }
      return ;
    }
    if ( !tmrHide[this.id] )
      tmrHide[this.id] = setInterval(this.name+".hide(true)",400);
	 
  };
  rgMenus[rgMenus.length] = this;
}

function opcfMenuItem(owner, name, url, pos, win, params)
{
  this.owner = owner;
  this.name = name;
  this.url = url;
  this.pos = pos;
  this.css = "menu";
  this.win = win;
  this.params = params;
  if ( this.params == null )
  {
    if ( this.win == "_blank" )
      this.params = ",'menubar=yes,resizable=yes,scrollbars=yes,location=yes,status=yes,toolbar=yes'";
    else
      this.params = "";
  }
  if (this.owner.lang) {
  	this.css = "lang";
  }
  if ( this.win == "this" )
    this.win = null;
  this.getHTML = function()
  {
    //if ( this.win != null )
      //return '<td id="menu'+this.owner.id+'-'+this.pos+'" class="'+this.css+'Out" onMouseOver="this.className=\''+this.css+'Over\';this.style.cursor=\'pointer\';'+this.owner.name+'.activeItem=true;" onMouseOut="this.className=\''+this.css+'Out\';'+this.owner.name+'.activeItem=false;" onMouseUp="window.open(\''+this.url+'\',\''+this.win+'\''+this.params+');"><div>'+this.name+'</div></td>\n';
    //else
      //return '<td id="menu'+this.owner.id+'-'+this.pos+'" class="'+this.css+'Out" onMouseOver="this.className=\''+this.css+'Over\';this.style.cursor=\'pointer\';'+this.owner.name+'.activeItem=true;" onMouseOut="this.className=\''+this.css+'Out\';'+this.owner.name+'.activeItem=false;" onMouseUp="location.href=\''+this.url+'\';"><div>'+this.name+'</div></td>\n';
//var checking
//checking =  '<td id="menu'+this.owner.id+'-'+this.pos+'" onMouseOver="this.style.cursor=\'pointer\';'+this.owner.name+'.activeItem=true;" onMouseOut="'+this.owner.name+'.activeItem=false;" onMouseUp="location.href=\''+this.url+'\';">'+'<img src="images/'+this.name+'.gif" id="'+this.name+'" name="'+this.name+'onmouseover="MM_swapImage(\''+this.name+'\',\'\',\'images/'+this.name+'_o.gif\',1)" onmouseout="MM_swapImgRestore()">'+'</td>\n';
//alert(checking);
      return '<td id="menu'+this.owner.id+'-'+this.pos+'" onMouseOver="this.style.cursor=\'pointer\';'+this.owner.name+'.activeItem=true;" onMouseOut="'+this.owner.name+'.activeItem=false;" onMouseUp="location.href=\''+this.url+'\';">'+'<img src="images/'+this.name+'.gif" id="'+this.name+'" name="'+this.name+'" onmouseover="MM_swapImage(\''+this.name+'\',\'\',\'images/'+this.name+'_o.gif\',1)" onmouseout="MM_swapImgRestore()">'+'</td>\n';
  }
}

function initMenuBar()
{
  menuEducation = new opcfMenu("menuEducation",314);
  menuEducation.addItem("m3_1","award_scheme.asp");
  menuEducation.addItem("m3_2","award_winner.asp");
  menuEducation.addItem("m3_3","university_sponsorship_programme.asp");  
  menuEducation.create();
  
  menuProjects = new opcfMenu("menuProjects",390);
  menuProjects.addItem("m4_0","project_0910.asp");
  menuProjects.addItem("m4_1","funding.asp");
  menuProjects.addItem("m4_2","focal_species.asp");
  menuProjects.addItem("m4_3","project_list.asp");
  //menuProjects.addItem("m4_4","project_ra.asp");
  menuProjects.create();

  menuFund = new opcfMenu("menuFund",444);
  menuFund.addItem("m5_1","fundraising.asp");
  menuFund.addItem("m5_2","donors.asp");
  menuFund.addItem("m5_3","audited_accounts.asp"); 
  menuFund.create();

//positionEST();
}
function positionEST()
{
  if ( document.all )
  {
    table = document.all['menutable'];
    bar = document.all['menubar'];
  }
  else if ( document.getElementById )
  {
    table = document.getElementById('menutable');
    bar = document.getElementById('menubar');
  }
}

function changeLang(slang) {
	var locArray = location.pathname.split("/");
	location.href="../"+slang+"/"+locArray[locArray.length-1];
	return true;
}

initMenuBar();