// JavaScript Document

//find out about user os and browser
var agent     = navigator.userAgent.toLowerCase();
var is_ie     = ((agent.indexOf("msie") != -1) && (agent.indexOf("opera") == -1));
var is_opera  = (agent.indexOf("opera") != -1);
var is_mac    = (agent.indexOf("mac") != -1);
var is_mac_ie = (is_ie && is_mac);
var is_win_ie = (is_ie && !is_mac);
var is_safari = (agent.indexOf('safari') != -1 && is_mac);
var is_gecko  = (navigator.product == "Gecko");

//DOM helper functions
function cancelClick(e){
		if (window.event){
			window.event.cancelBubble = true;
			window.event.returnValue = false;
			return;
		}
		if (e){
			e.stopPropagation();
			e.preventDefault();
		}
	}

//macromedia functions

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}


//Javascript functions by Phil

var visSubMenuId;

function aboutTextShow(m) {
				for(var no=1;no<6;no++) {
					if ( no == m) {
						document.getElementById("about" + no).style.display = "block";
						document.getElementById("aboutpic" + no).style.display = "block";
					} else {
						document.getElementById("about" + no).style.display = "none";
						document.getElementById("aboutpic" + no).style.display = "none";
						
					}
				}
}


// GET arg parsers
function PageQuery(q) {
if(q.length > 1) this.q = q.substring(1, q.length);
else this.q = null;
this.keyValuePairs = new Array();
if(q) {
for(var i=0; i < this.q.split("&").length; i++) {
this.keyValuePairs[i] = this.q.split("&")[i];
}
}
this.getKeyValuePairs = function() { return this.keyValuePairs; }
this.getValue = function(s) {
for(var j=0; j < this.keyValuePairs.length; j++) {
if(this.keyValuePairs[j].split("=")[0] == s)
return this.keyValuePairs[j].split("=")[1];
}
return false;
}
this.getParameters = function() {
var a = new Array(this.getLength());
for(var j=0; j < this.keyValuePairs.length; j++) {
a[j] = this.keyValuePairs[j].split("=")[0];
}
return a;
}
this.getLength = function() { return this.keyValuePairs.length; } 
}

function queryString(key){
var page = new PageQuery(window.location.search); 
return unescape(page.getValue(key)); 
}

//about page loaders
function aboutSection() {
	
	if(queryString('about') !='false') {
		
		aboutTextShow(queryString('about'));
	}
}



/************************************************************************************************************
	(C) www.dhtmlgoodies.com, November 2005
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.
	
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
	************************************************************************************************************/
	
	

	var timeBeforeAutoHide = 700;	// Microseconds to wait before auto hiding menu(1000 = 1 second)
	var slideSpeed_out = 10;	// Steps to move sub menu at a time ( higher = faster)
	var slideSpeed_in = 10;
		
	
	var slideTimeout_out = 25;	// Microseconds between slide steps ( lower = faster)
	var slideTimeout_in = 10;	// Microseconds between slide steps ( lower = faster)
	
	var showSubOnMouseOver = true;	// false = show sub menu on click, true = show sub menu on mouse over
	var fixedSubMenuWidth = false;	// Width of sub menu items - A number(width in pixels) or false when width should be dynamic
	
	var xOffsetSubMenu = -120; 	// Offset x-position of sub menu items - use negative value if you want the sub menu to overlap main menu
	
	var slideDirection = 'right';	// Slide to left or right ?
	
	/* Don't change anything below here */
	
	var activeSubMenuId = false;
	var activeMainMenuItem = false;
	var currentZIndex = 1000;		
	var autoHideTimer = 0;
	var submenuObjArray = new Array();
	var okToSlideInSub = new Array();
	var subPositioned = new Array();
	

	function stopAutoHide()
	{
		autoHideTimer = -1;
	}
	
	function initAutoHide()
	{
		autoHideTimer = 0;
		if(autoHideTimer>=0)autoHide();
	}
	
	function autoHide()
	{
		
		if(autoHideTimer>timeBeforeAutoHide)
		{
			
			if(activeMainMenuItem){
				activeMainMenuItem.className='';
				activeMainMenuItem = false;
			}
			
			//modified by phil: don't timeout the initial vis submenu.
			if(activeSubMenuId && activeSubMenuId != visSubMenuId){
				//alert ("timeout");
				var obj = document.getElementById('subMenuDiv' + activeSubMenuId);
				showSub();
				//added by phil: if there is a vid submenu, slide it back in after the timed out menu has slid out
				if (visSubMenuId) {
					initShowSub(visSubMenuId);
				}
				
			}
		}else{
			if(autoHideTimer>=0){
				autoHideTimer+=50;
				setTimeout('autoHide()',50);
			}
		}
	}	
	
	function getTopPos(inputObj)
	{		
	  var returnValue = inputObj.offsetTop;
	  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
	  return returnValue;
	}
	
	function getLeftPos(inputObj)
	{
	  var returnValue = inputObj.offsetLeft;
	  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
	  return returnValue;
	}
	
	function showSub()
	{
		var subObj = false;
		if(this && this.tagName){
			//numericId is numbered in order down the page, however only links with submenus have one  - so about is 2, our work is 3
			var numericId = this.parentNode.id.replace(/[^0-9]/g,'');
			//alert(numericId)
			okToSlideInSub[numericId] = false;
			var subObj = document.getElementById('subMenuDiv' + numericId);
			if(activeMainMenuItem)activeMainMenuItem.className='';
			if(subObj){
				if(!subPositioned[numericId]){
					if(slideDirection=='right'){
						subObj.style.left = getLeftPos(submenuObjArray[numericId]['parentDiv']) + submenuObjArray[numericId]['parentDiv'].offsetWidth + xOffsetSubMenu + 'px';
					}else{
						subObj.style.left = getLeftPos(submenuObjArray[numericId]['parentDiv']) + xOffsetSubMenu + 'px';
						
					}
					submenuObjArray[numericId]['left'] = subObj.style.left.replace(/[^0-9]/g,'');
					subObj.style.top = getTopPos(submenuObjArray[numericId]['parentDiv']) + 'px';
					subPositioned[numericId] = true;
				}				
				subObj.style.visibility = 'visible';
				subObj.style.zIndex = currentZIndex;
				currentZIndex++;	
				this.className='activeMainMenuItem';
				activeMainMenuItem = this;
			}
		}else{
			
			var numericId = activeSubMenuId;
		}
		if(activeSubMenuId && (numericId!=activeSubMenuId || !subObj)) {
				slideMenu(activeSubMenuId,(slideSpeed_in*-1));
		}
		if(numericId!=activeSubMenuId && this && subObj){
			subObj.style.width = '0px';	
			slideMenu(numericId,slideSpeed_out);
			activeSubMenuId = numericId;
		}else{
			if(numericId!=activeSubMenuId)activeSubMenuId = false;
		}
		if(showSubOnMouseOver)stopAutoHide();
	}

//Phil's addition. This will show a submenu on page load
// bastardisation of the showmsub function above.
function initShowSub(initSubMenuId)
	{
		var subObj = false;
			//numericId is numbered in order down the page, however only links with submenus have one  - so about is 2, our work is 3
			var numericId = initSubMenuId;
			//alert(numericId)
			okToSlideInSub[numericId] = false;
			var subObj = document.getElementById('subMenuDiv' + numericId);
			if(activeMainMenuItem)activeMainMenuItem.className='';
			if(subObj){
				if(!subPositioned[numericId]){
					if(slideDirection=='right'){
						subObj.style.left = getLeftPos(submenuObjArray[numericId]['parentDiv']) + submenuObjArray[numericId]['parentDiv'].offsetWidth + xOffsetSubMenu + 'px';
					}else{
						subObj.style.left = getLeftPos(submenuObjArray[numericId]['parentDiv']) + xOffsetSubMenu + 'px';
						
					}
					submenuObjArray[numericId]['left'] = subObj.style.left.replace(/[^0-9]/g,'');
					subObj.style.top = getTopPos(submenuObjArray[numericId]['parentDiv']) + 'px';
					subPositioned[numericId] = true;
				}				
				subObj.style.visibility = 'visible';
				subObj.style.zIndex = currentZIndex;
				currentZIndex++;	
				this.className='activeMainMenuItem';
				activeMainMenuItem = this;
			}

			subObj.style.width = '0px';	
			slideMenu(numericId,slideSpeed_out);
			activeSubMenuId = numericId;

		if(showSubOnMouseOver)stopAutoHide();
	}



	function slideMenu(menuIndex,speed){
		var obj = submenuObjArray[menuIndex]['divObj'];
		var obj2 = submenuObjArray[menuIndex]['ulObj'];
		var width = obj.offsetWidth + speed;
		if(speed<0){
			if(width<0)width = 0;
			obj.style.width = width + 'px';
			if(slideDirection=='left'){
				obj.style.left = submenuObjArray[menuIndex]['left'] - width + 'px';
				obj2.style.left = '0px';
			}else{
				obj2.style.left = width - submenuObjArray[menuIndex]['width'] + 'px' 
			}
			if(width>0 && okToSlideInSub[menuIndex])setTimeout('slideMenu(' + menuIndex + ',' + speed + ')',slideTimeout_in); else{
				obj.style.visibility = 'hidden';
				obj.style.width = '0px';
				if(activeSubMenuId==menuIndex)activeSubMenuId=false;
			}
			
		}else{
			if(width>submenuObjArray[menuIndex]['width'])width = submenuObjArray[menuIndex]['width'];
			if(slideDirection=='left'){
				obj.style.left = submenuObjArray[menuIndex]['left'] - width + 'px';
				obj2.style.left = '0px';
			}else{
				obj2.style.left = width - submenuObjArray[menuIndex]['width'] + 'px' 
			}		
			
			obj.style.width = width + 'px';
			if(width<submenuObjArray[menuIndex]['width']){
				setTimeout('slideMenu(' + menuIndex + ',' + speed + ')',slideTimeout_out);
			}else{
				okToSlideInSub[menuIndex] = true;
			}
		}
	}
	function resetPosition()
	{
		subPositioned.length = 0;
	}
			
	function initLeftMenu()
	{
		// 3 lines line below added by phil: we only want this to work if W3C DOM is fully supported
		// also check for DHTML methods
		// also disable this script for IE 5.2 for mac, cos it is crap
		if (!is_mac_ie) {
			if (document.getElementById || document.all || document.layers) {
				if (document.getElementById && document.createElement) {
					var menuObj = document.getElementById('dhtmlgoodies_menu');	
					var mainMenuItemArray = new Array();
					
					var mainMenuItem = menuObj.getElementsByTagName('LI')[0];
					while(mainMenuItem){
						if(mainMenuItem.tagName && mainMenuItem.tagName.toLowerCase()=='li'){
							mainMenuItemArray[mainMenuItemArray.length] = mainMenuItem;
							var aTag = mainMenuItem.getElementsByTagName('A')[0];
							if(showSubOnMouseOver)
								aTag.onmouseover = showSub;	
							else
								aTag.onclick = showSub;	
						}
						mainMenuItem = mainMenuItem.nextSibling;
					}		
					
					var lis = menuObj.getElementsByTagName('A');
					for(var no=0;no<lis.length;no++){
						if(!showSubOnMouseOver)lis[no].onmouseover = stopAutoHide;
						lis[no].onmouseout = initAutoHide;
						lis[no].onmousemove = stopAutoHide;
					}
							
					for(var no=0;no<mainMenuItemArray.length;no++){
						var sub = mainMenuItemArray[no].getElementsByTagName('UL')[0];
						if(sub){
							mainMenuItemArray[no].id = 'mainMenuItem' + (no+1);
							var div = document.createElement('DIV');
							div.className='dhtmlgoodies_subMenu';
							document.body.appendChild(div);
							div.appendChild(sub);
							if(slideDirection=='right'){
								div.style.left = getLeftPos(mainMenuItemArray[no]) + mainMenuItemArray[no].offsetWidth + xOffsetSubMenu + 'px';
							}else{
								div.style.left = getLeftPos(mainMenuItemArray[no]) + xOffsetSubMenu + 'px';
							}
							div.style.top = getTopPos(mainMenuItemArray[no]) + 'px';
							div.id = 'subMenuDiv' + (no+1);
							sub.id = 'submenuUl' + (no+1);
							sub.style.position = 'relative';	
			
							if(navigator.userAgent.indexOf('Opera')>=0){
								submenuObjArray[no+1] = new Array();
								submenuObjArray[no+1]['parentDiv'] = mainMenuItemArray[no];
								submenuObjArray[no+1]['divObj'] = div;
								submenuObjArray[no+1]['ulObj'] = sub;
								submenuObjArray[no+1]['width'] = sub.offsetWidth;
								submenuObjArray[no+1]['left'] = div.style.left.replace(/[^0-9]/g,'');
							}
							sub.style.left = 1 - sub.offsetWidth + 'px';	
							
							if(document.all)div.style.width = '1px';	
								
							if(navigator.userAgent.indexOf('Opera')<0){
								submenuObjArray[no+1] = new Array();
								submenuObjArray[no+1]['parentDiv'] = mainMenuItemArray[no];
								submenuObjArray[no+1]['divObj'] = div;
								submenuObjArray[no+1]['ulObj'] = sub;
								submenuObjArray[no+1]['width'] = sub.offsetWidth;
								
								
								
								submenuObjArray[no+1]['left'] = div.style.left.replace(/[^0-9]/g,'');
								if(fixedSubMenuWidth)submenuObjArray[no+1]['width'] = fixedSubMenuWidth;
							}	
			
							if(!document.all)div.style.width = '1px';			
								
						}			
					}
				
						
			
					
					
					menuObj.style.visibility = 'visible';
					
					window.onresize = resetPosition;
					
					//added by phil: after initialising menus, make the initial submenu visible.
					if (visSubMenuId) {
						initShowSub(visSubMenuId);
					}
				
					//added by phil: check if there are getargs, if so hide/show the appropriate about texts.
					aboutSection();
				}
			}
		}
	}
	
	
	window.onload = initLeftMenu; 	