//*****************************************************************************
//
//*****************************************************************************

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) {
	
		MenuID.style.backgroundcolor = "#fc0";
	
		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) - 2;
		y = getPageOffsetTop(MenuID) + MenuID.offsetHeight - 4;

		// 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("subHome").style.visibility = "hidden";
	document.getElementById("subAboutUs").style.visibility = "hidden";
	document.getElementById("subExpertise").style.visibility = "hidden";
	document.getElementById("subPeople").style.visibility = "hidden";
	document.getElementById("subCareers").style.visibility = "hidden";

}

var Picture = new Array();

Picture[1]   = '/assets/imagebank/domestic_violence.jpg';
Picture[2]   = '/assets/imagebank/closure_orders.jpg';
Picture[3]   = '/assets/imagebank/police_station_attendance.jpg';
Picture[4]   = '/assets/imagebank/mental_health.jpg';
Picture[5]   = '/assets/imagebank/family_law.jpg';
Picture[6]   = '/assets/imagebank/closure_orders.jpg';
Picture[7]   = '/assets/imagebank/domestic_violence.jpg';
Picture[8]   = '/assets/imagebank/closure_orders.jpg';
Picture[9]   = '/assets/imagebank/domestic_violence.jpg';
Picture[10]  = '/assets/imagebank/closure_orders.jpg';

function InsertImage()
{

	var iPictureNum = 1 + Math.floor(Math.random()*10)

	sImg = Picture[iPictureNum];

	document.write("<img src='" + sImg + "' width='675' height='250' alt='[Photograph]'>");
}	
	