
var tdColor="#ffffff";		// menu item text color
var tdBgColor="#C3C1C1";	// menu item background color
var hlColor="#FFFFFF";		// highlight text color
var hlBgColor="#68B4A2";	// highlight background color

var menuCloseTimeout=250;
var timeoutId=-1;
var oldTdID=null;

var sT="";
var pT=new Array();
var tA=new Array();

var root;

 domain="co.uk";
// domain="wetherbyosteopaths";

root = location.href.substring(0, location.href.indexOf( domain ) + domain.length + 1);

function doMenu(sTdID)
{
	clearTimeout(timeoutId);

	var i;
	var oElement;
	var sID = sTdID.substring(0, sTdID.length-1);

	for(i=1; (oElement = document.getElementById(sID + i)) != null; i++)
	{
		oElement.style.backgroundColor=hlBgColor;
		oElement.style.color=hlColor;
	}

	var nIndex;
	var sT="";
	var tda=new Array();
	tda=sID.split("_");
	if(oldTdID!=null)
	{
		var aTd=new Array();
		var sOldID=oldTdID.substring(0, oldTdID.length-1);
		aTd=sOldID.split("_");
		for(nIndex=1; nIndex<aTd.length; nIndex++)
		{
			sT+="_"+aTd[nIndex];
			if(aTd[nIndex]!=tda[nIndex])
			{
				for(i=1; (oElement = document.getElementById("td" + sT + i)) != null; i++)
				{
					oElement.style.backgroundColor=tdBgColor;
					oElement.style.color=tdColor;
				}

				if(document.getElementById("tbl"+sT)!=null)
					document.getElementById("tbl"+sT).style.visibility="hidden";
			}
		}			
	}
	oldTdID=sTdID;
	sT="tbl";
	for(nIndex=1; nIndex<tda.length; nIndex++)
		sT+="_"+tda[nIndex];
	if(document.getElementById(sT)!=null)
	{
		if( document.getElementById("tbl"+pT[0]).style.left != (getOffsetLeft(document.getElementById("mainmenu"))+document.getElementById("td"+pT[0]+"1").offsetLeft+128)+"px" )
			setMenuPos();
		document.getElementById(sT).style.visibility="visible";
	}

}

function clearMenu()
{
	if(oldTdID!=null)
	{
		var sID = oldTdID.substring(0, oldTdID.length-1);
		var oElement;
		var aTd=new Array();
		aTd=sID.split("_");
		var sT="";
		var i;
		for(var nIndex=1; nIndex<aTd.length; nIndex++)
		{
			sT+="_"+aTd[nIndex];
			for(i=1; (oElement = document.getElementById("td" + sT + i)) != null; i++)
			{
				oElement.style.backgroundColor=tdBgColor;
				oElement.style.color=tdColor;
			}
			if(document.getElementById("tbl"+sT)!=null)
				document.getElementById("tbl"+sT).style.visibility="hidden";
		}
		oldTdID=null;			
	}
}

function goTargetURL(strURL)
{
	location.href = root + strURL;
}


function setCoord(st)
{
	var tt="";
	tA=st.split("_");
	if(tA.length>2)
	{
		tA=tA.slice(0,-1);
		tt=tA.join("_");
		coordTop= (getOffsetTop(document.getElementById("tbl"+tt))+document.getElementById("td"+st+"1").offsetTop-1)+"px";
		coordLeft=(getOffsetLeft(document.getElementById("tbl"+tt))+document.getElementById("td"+st+1).offsetWidth+120)+"px";

	}
	else
	{
		coordTop= (getOffsetTop(document.getElementById("mainmenu"))+document.getElementById("td"+st+"1").offsetTop-1)+"px";
		coordLeft=(getOffsetLeft(document.getElementById("mainmenu"))+document.getElementById("td"+st+"1").offsetLeft+120)+"px";
	}

	document.getElementById("tbl"+st).style.position="absolute";
	document.getElementById("tbl"+st).style.left=coordLeft;
	document.getElementById("tbl"+st).style.top=coordTop;
}


function getOffsetTop(element)
{
//	oldtop = element.offsetTop;
	offset=0;
	do
	{
		offset+=element.offsetTop;
		element = element.offsetParent;
	}while(element != null);
//	alert( oldtop + ", " + offset );
	return offset;
}

function getOffsetLeft(element)
{
	oldleft = element.offsetLeft;
	offset=0;
	do
	{
//		alert( element.tagName );
		offset+=element.offsetLeft;		
		element = element.offsetParent;
	}while(element != null);
//	alert( oldleft + ", " + offset );
	return offset;
}

function setMenuPos()
{	

	for(var nIndex=0; typeof(pT[nIndex])!="undefined"; nIndex++)
	{
		sT=pT[nIndex];
		setCoord(sT);
	}
}

var sMenuHTML="<table class=\"menu\" id=\"mainmenu\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
var p=0;
var j=0;
while(eval("typeof(td_"+ ++j +")!=\"undefined\""))
{
	sMenuHTML += "<tr><td width=\"100%\" id=\"td_" + j + "1\" onmouseover=\"doMenu(this.id)\" onmouseout=\"timeoutId=setTimeout('clearMenu()',menuCloseTimeout)\"";
	sMenuHTML += (eval("typeof(url_" + j + ")!=\"undefined\"")) ? " onclick=\"goTargetURL('" + eval("url_" + j) + "')\">" : ">";
	sMenuHTML += eval("td_" + j);

/*	if(eval("typeof(url_" + j + ")==\"undefined\""))
		sMenuHTML += "<img src=\"" + root + "graphics/frame/menu_arrow2.gif\" width=\"7\" height=\"13\">";
	else
		sMenuHTML += "<img src=\"" + root + "graphics/frame/menu_dots.gif\" width=\"7\" height=\"13\">";*/
	sMenuHTML += "</td></tr>";

	if (eval("typeof(td_" + j + ")!=\"undefined\""))
		pT[p++] = "_" + j;
}
sMenuHTML += "</table>";
document.write(sMenuHTML);

for(var nIndex=0; typeof(pT[nIndex])!="undefined"; nIndex++)
{
	sT=pT[nIndex];
	sMenuHTML="";
	j=0;
	sMenuHTML += "<table class=\"submenu\" id=\"tbl"+sT+"\" cellspacing=\"0\" cellpadding=\"0\">";
	while (eval("typeof(td"+sT+"_"+ ++j +")!=\"undefined\""))
	{

		sMenuHTML += "<tr><td width=\"100%\" id=\"td" + sT + "_" + j + "1\" onmouseover=\"doMenu(this.id)\" onmouseout=\"timeoutId=setTimeout('clearMenu()',menuCloseTimeout)\"";
		sMenuHTML += (eval("typeof(url" + sT + "_" + j + ")!=\"undefined\"")) ? " onclick=\"goTargetURL('" + eval("url" + sT + "_" + j) + "')\">" : ">";
		sMenuHTML += eval("td" + sT + "_" + j);

/*		if(eval("typeof(url" + sT + "_" + j + ")==\"undefined\""))
			sMenuHTML += "<img src=\"" + root + "graphics/frame/menu_arrow2.gif\" width=\"7\" height=\"13\">";
		else
			sMenuHTML += "<img src=\"" + root + "graphics/frame/menu_dots.gif\" width=\"7\" height=\"13\">";*/
		sMenuHTML += "</td></tr>";
		
		if (eval("typeof(td" + sT + "_" + j + ")!=\"undefined\""))
			pT[p++] = sT + "_" + j;
	}
	sMenuHTML += "</table>";
	document.write(sMenuHTML);
}

document.getElementById("mainmenu").style.visibility="visible";
