//*****************************************************************************
//
//*****************************************************************************

var IsTimerRunning = false;
var TimerID = null;
var intTimeout = 450;
var activetab = null;

function Browser() {

  var ua, s, i;

  this.isIE      = false;  // Internet Explorer
  this.isNS      = false;  // Netscape
  this.version   = null;
  this.showmenus = true;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
	 if (this.version < 5) this.showmenus = false;
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

// ---------------------------------------------------------------------------

function getPageOffsetLeft(el) {

	var x;

	// Return the x coordinate of an element relative to the page.

	x = el.offsetLeft;

	if (el.offsetParent != null)
		x += getPageOffsetLeft(el.offsetParent);

	return x;
}

// ---------------------------------------------------------------------------

function getPageOffsetTop(el) {

	var y;

	// Return the x coordinate of an element relative to the page.

	y = el.offsetTop;

	if (el.offsetParent != null)
		y += getPageOffsetTop(el.offsetParent);

	return y;
}

function MenuFocus(id, showmenu) {

	if(!browser.showmenus) return;

	var MenuID;

	// Hide all menus

	MakeInactive();

	// If the timer is running, clear it

	StopTimer();

	// Get menu id and highlight the title

	MenuID = document.getElementById("mnu" + id);

	// Show the menu if requested

	if (showmenu) {

		var x, y, mw, sw, SubMenuID, xMax;

		// Get ID of menu to show

		SubMenuID = document.getElementById("sub" + id)

		// Work out where to put the menu

		mw = MenuID.offsetWidth;
		sw = SubMenuID.offsetWidth;

		x = getPageOffsetLeft(MenuID);
		y = getPageOffsetTop(MenuID) + MenuID.offsetHeight;

		// Determine the width of the browser window

		if (browser.isNS)
			xMax = window.scrollX + window.innerWidth;

		if (browser.isIE)
			xMax = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) +
			(document.documentElement.clientWidth != 0 ? document.documentElement.clientWidth : document.body.clientWidth);

		// Adjust menu position so it will be shown within the window

		if (x + sw > xMax)
			x = x + mw - sw;

		// Show menu

		SubMenuID.style.left = x + "px";
		SubMenuID.style.top  = y + "px";
		SubMenuID.style.visibility = "visible";

	}
}

function StartTimer(id) {

	if(!browser.showmenus) return;

	// If not already running, start the time to hide the menus

	if (!IsTimerRunning) {
		
		TimerID = setTimeout("MakeInactive()", intTimeout);

		IsTimerRunning = true;

	}
	
}

function StopTimer() {

	if(!browser.showmenus) return;

	// Clear the timer if running

	if (IsTimerRunning) {

		clearTimeout(TimerID);
		TimerID = null;
		IsTimerRunning = false;

	}
}

function MakeInactive() {

	// Hide all the menus

	document.getElementById("subAboutUs").style.visibility = "hidden";
	document.getElementById("subAreasOfLaw").style.visibility = "hidden";
	document.getElementById("subOurPeople").style.visibility = "hidden";
//	document.getElementById("subNewsAndEvents").style.visibility = "hidden";
	document.getElementById("subJoinUs").style.visibility = "hidden";
	document.getElementById("subContactUs").style.visibility = "hidden";

}

// Show the barrister profile selected from the quick nav list
function ShowBar()
{
	var i = document.frmProfiles.lstSelectBarrister.selectedIndex;
	var h = document.frmProfiles.lstSelectBarrister[i].value;
	if (h!="") window.location = "/people/" + h + ".htm";
}

// If a profile page is on display reflect this is the quick nav list
function SetBar()
{
	var sHREF = document.location.href;
	var iPos  = sHREF.lastIndexOf("/");
	var sHTML = sHREF.substring(iPos+1, sHREF.length);
	iPos = sHTML.indexOf(".");
	sHTML = sHTML.substring(0, iPos);
	var iSet = 0;

	for (i=1; i<=document.frmProfiles.lstSelectBarrister.length - 1; i++)
		{
		if (document.frmProfiles.lstSelectBarrister[i].value == sHTML) {
			iSet = i-1;
		}
	}
	
	document.frmProfiles.lstSelectBarrister.selectedIndex = iSet+1;
}