
//When looking at pages further down the hierarchy, add a prefix to menu URLs
if ((document.URL).indexOf("internal/") != -1)
    prefix = "../";
else
    prefix = "";

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
if (document.images) {
	left_01_over = newImage(prefix + "images/template/left_01-over.gif");
	left_02_over = newImage(prefix + "images/template/left_02-over.gif");
	left_03_over = newImage(prefix + "images/template/left_03-over.gif");
	left_04_over = newImage(prefix + "images/template/left_04-over.gif");
	left_05_over = newImage(prefix + "images/template/left_05-over.gif");
	search_help_over = newImage(prefix + "images/template/search_help_over.gif");
	internal_over = newImage(prefix + "images/template/internal_over.gif");
	preloadFlag = true;
}

var tv=0
var visible=0;
var browser="";

//Detect the browser
if (document.layers)
	browser = "net4";
else if (navigator.appName == "Netscape")
	browser = "mozilla";
else if (navigator.userAgent.indexOf("Opera") != -1)
	browser = "opera";
else if (navigator.appName == "Konqueror")
	browser = "kon";
else
	browser = "ie";

//Definitions for the pop-up menus
//First three elements of each menu are: id, top and left.
//Next three are: id of picture on menu, urls for unselected and selected pics
var menus = new Array();
//Introduction
menus[0] = ["sub1",115,107,"left_01","images/template/left_01.gif","images/template/left_01-over.gif",
"CVPR Group","cvpr.php",
"Applying to study at York","apply.php"];
//Who we are
menus[1] = ["sub2",147,107,"left_02","images/template/left_02.gif","images/template/left_02-over.gif",
"People in the group","people.php"];
//Research
menus[2] = ["sub3",179,107,"left_03","images/template/left_03.gif","images/template/left_03-over.gif",
"Theoretical Foundations","theoretical.php",
"Analysis of Differential Surface Structure","diff_surf.php",
"Feature Detection in 2D and 3D","feature_detect.php",
"Feature Tracking in 3D","feature_track.php",
"Inexact Graph Matching","graph_match.php",
"Algorithms for Radar Imaging","radar_imaging.php",
"Theoretical Studies of Connectionist Systems","connectionist.php",
"Spectral Methods for Graphs","spectral.php",
"Chemical Structure Databases","chemical.php",
"Relational Graph Matching","relational.php",
"Quantum Algorithms","quantum.php"];
//Publications
menus[3] = ["sub4",211,107,"left_04","images/template/left_04.gif","images/template/left_04-over.gif",
"Search publications","search_papers.php",
"List all publications","search_papers.php?author=&amp;keywords=&amp;submit=Search",
"Download publications","download_papers.php"];
//News
menus[4] = ["sub5",243,107,"left_05","images/template/left_05.gif","images/template/left_05-over.gif",
"Studentships now available","apply.php",
"GbR conference in York","http://www-users.cs.york.ac.uk/~erh/gbr/"];

function WriteMenus() {
	for (var menu=0; menu<menus.length; menu++)
	{
		if (menus[menu].length > 6)	// Make sure the menu has some items
		{
			var m_id = menus[menu][0];
			var m_top = menus[menu][1];
			var m_left = menus[menu][2];
			var im_name = menus[menu][3];
			var im_unsel = prefix + menus[menu][4];
			var im_sel = prefix + menus[menu][5];
						
			if (browser != "net4") {
				if (browser=="mozilla" || browser=="opera") {
					m_top -= 7;		//Mozilla and Opera offsets (relative to IE)
					m_left -= 2;	//for correct menu positioning
				}
				else if (browser=="kon")
					m_top -= 5;
				document.write('<div id="' + m_id + '" ');
				document.write('onmouseover="ShowMenu(\'' + m_id + '\'); ');
				document.write('changeImages(\'' + im_name + '\', \'' + im_sel + '\');" ');
				document.write('onmouseout="SetHideTimer(\'' + m_id + '\'); ');
				document.write('changeImages(\'' + im_name + '\', \'' + im_unsel + '\');" ');
				document.write('style="visibility: hidden; background: #000066; ');
				document.write('padding: 0px; border: 0px; margin: 0px; ');
				document.write('position: absolute; top: ' + m_top + 'px; left: ' + m_left + 'px;">');
				document.write('<table class="subtable" cellspacing="1">');
				for (var item=6; item<menus[menu].length; item+=2)
				{
					document.write ('<tr><td>');
					document.write ('<a class="subitem" href="' + prefix + menus[menu][item+1] + '">')
					document.write (menus[menu][item]);
					document.write ('</a>');
					document.write ('</td></tr>');
				}
				document.write('</table>');
				document.write('</div>');
			}
			else	//Menus for Netscape Navigator v4
			{
				m_top -= 5;	//Netscape offsets
				m_left -= 2;
				document.write('<layer name="' + m_id + '" top="' + m_top + '" left="' + m_left + '" visibility="hide">');
				document.write('<table class="subtable" cellspacing="0" cellpadding="0" border="0">');
				for (var item=6; item<menus[menu].length; item+=2)
				{
					document.write ('<tr><td>');
					document.write ('<a class="subitem" href="' + prefix + menus[menu][item+1] + '"' );
					document.write ('onmouseover="ShowMenu(\'' + m_id + '\'); ');
					document.write ('changeImages(\'' + im_name + '\', \'' + im_sel + '\');" ');
					document.write ('onmouseout="SetHideTimer(\'' + m_id + '\');');
					document.write ('changeImages(\'' + im_name + '\', \'' + im_unsel + '\');">');
					document.write (menus[menu][item]);
					document.write ('</a>');
					document.write ('</td></tr>');
				}
				document.write('</table>');
				document.write('</layer>');
			}
		}
	}
}

//Show a submenu when user moves over a main menu item, or simply
//keep it there when user moves over the submenu itself
function ShowMenu(sel_menu)
{
	//If there's a timeout pending, cancel it
	if (tv != 0) clearTimeout(tv);
	//Only need to do something now if selected menu is not already visible
	if (sel_menu != visible)
	{
		//If there is another submenu still showing, remove it now
		if (visible != 0) HideMenu(visible);

		if (browser != "net4") {
			var newmenu = document.getElementById(sel_menu);
			newmenu.style.visibility="visible";
   		}
   		else document.layers[sel_menu].visibility="visible";
		visible = sel_menu;
	}
}

function SetHideTimer(submenu)
{
	if (tv != 0) clearTimeout(tv);	//If there's a previous timeout pending, cancel it
	tv = setTimeout("HideMenu('" + submenu + "')",300);
}

function HideMenu(sm)
{
	if (browser != "net4") {
		submenu = document.getElementById(sm);
		submenu.style.visibility="hidden";
 	}
 	else document.layers[sm].visibility="hidden";
	visible=0;
	tv=0;
}


