/*	DESCRIPTION: returns an object reference from its id.
	ARGUMENTS: objId: id of object
	RESULTS: returns the object reference of the requested object
*/
function getById(objId) {
	var objRef;
	objRef = document.getElementById(objId);
	return objRef;
}

/*	DESCRIPTION: returns an object reference from its tag
	ARGUMENTS: objTag: Tag of object; parent: id of parent 
	RESULTS: returns the object reference of the requested object
*/
function getByTag(objTag, parentId) {
//	alert(objTag, parentId)
	var objRef;
	objRef = getById(parentId).getElementsByTagName(objTag);
	return objRef;
}

/*	DESCRIPTION: image preloader
	ARGUMENTS: arrPreload: array of  image SRCs without state and ext e.g ...
	preLoadedImages(['../../images/nav_brand/about', '../../images/nav_brand/costumeandwigs']);
	RESULTS: normal and _on states images preloaded for each item in array
*/
function preLoadedImages(arrPreload) {
	var arrStates = [ '','_on' ];
	var pageImages = new Array();
	var imageCount = 0;
	var stateCount, currentState, i, n 
	
	for (var i=0; i<arrPreload.length; i ++) {
		n = arrPreload[i];
		for (stateCount in arrStates) { // this preloads the states for each images 
			currentState = arrStates[stateCount];
			pageImages[imageCount] = new Image();
			pageImages[imageCount].src = n + currentState + '.gif';
			imageCount ++;
		}
	}
	return pageImages;
}

/*	DESCRIPTION: sets the left hand nav by hiding/showing and activating/deactivating items by reading location.href. 
	ARGUMENTS: item: overides the filename detected from the url
	RESULTS: Hide all items in non-current section/fdr. Current section. Current page set to active
*/
function setNav(item) {

	if(document.getElementById) { 
		// get the file and folder names from the url
		var s = location.href.split("/"); 
		var fdrName = s[s.length-2];
		if (item) 
			var fileName = item
		else {
			var fileName = s[s.length-1] ;
			fileName = fileName.substring(0,fileName.indexOf("."));
		}
		// get the HTML element with the same ID (LI) as the current folder and change the class of that element 
		getById(fdrName).className = 'folderon';
		
		// loop through the LI elements in the folder setting each to display:block
		// change the class of that which matches the file name
		var ul = getByTag('LI',fdrName);
		if (ul.length > 0) {
			for (var i = 0; i < ul.length; i++) {
				ul[i].style.display = 'block';
				if (ul[i].className == fileName){
					ul[i].className = 'pageon';
					if(fileName == "london_3D_team"){
					ul[i].className = 'pageonsub';
					} 
				}

			}
		}
	}
}

/*	DESCRIPTION: pops up a window.
	ARGUMENTS: url: url of popped up page
	RESULTS: returns a popup!
*/
function popup(url) { 
	newwindow = window.open(url,'location','width=435,height=445');
	if (window.focus) {newwindow.focus()}
	return false;
}
function popupgastro(url) { 
	newwindow = window.open(url,'location','width=600,height=600');
	if (window.focus) {newwindow.focus()}
	return false;
}
function popupmap(url) {

	if (screen)
	{
		if (screen.availHeight >= 822){
		var goodtop = 0;
		goodtop = (screen.availHeight - 822)/2;
		newwindow = window.open(url,'location','top='+goodtop+', width=595,height=822');
		}else{
		var maxheight = 400;
		maxheight = screen.availHeight;
		//alert (maxheight);
		newwindow = window.open(url,'location','scrollbars=1 top=0,width=595,height='+maxheight+'');
		}
	}else{
	newwindow = window.open(url,'location','scrollbars=1 top=0,width=595,height=400');
	}

	if (window.focus) {newwindow.focus()}
	return false;
}
function popupplan(url,height,width) {

	if (screen)
	{
		//if (screen.availHeight >= 635){
		//var goodtop = 0;
		//goodtop = (screen.availHeight - 635)/2;
		//newwindow = window.open(url,'location','top='+goodtop+', width='+width+',height=635');
		//}else{
		//var maxheight = 400;
		//maxheight = screen.availHeight;
		//alert (maxheight);
		//newwindow = window.open(url,'location','scrollbars=1 top=0,width='+width+',height='+maxheight+'');
		//}
	//}else{
	newwindow = window.open(url,'location','scrollbars=0, statusbar=0, resizable=1, top=0,width='+width+',height='+height+'');
	}

	if (window.focus) {newwindow.focus()}
	return false;
}
function popupnews(url) {

	if (screen)
	{
		if (screen.availHeight >= 822){
		var goodtop = 0;
		goodtop = (screen.availHeight - 822)/2;
		newwindow = window.open(url,'location','top='+goodtop+', width=595,height=822');
		}else{
		var maxheight = 400;
		maxheight = screen.availHeight;
		//alert (maxheight);
		newwindow = window.open(url,'location','scrollbars=1 top=0,width=595,height='+maxheight+'');
		}
	}else{
	newwindow = window.open(url,'location','scrollbars=1 top=0,width=595,height=400');
	}

	if (window.focus) {newwindow.focus()}
	return false;
}

function popupnews2(url) {

	if (screen)
	{
		if (screen.availHeight >= 822){
		var goodtop = 0;
		goodtop = (screen.availHeight - 822)/2;
		newwindow = window.open(url,'location','top='+goodtop+', width=215,height=345');
		}else{
		var maxheight = 345;
		maxheight = screen.availHeight;
		//alert (maxheight);
		newwindow = window.open(url,'location','scrollbars=0 top=0,width=215,height='+maxheight+'');
		}
	}else{
	newwindow = window.open(url,'location','scrollbars=0 top=0,width=215,height=345');
	}

	if (window.focus) {newwindow.focus()}
	return false;
}

function popupcv(url) {

	if (screen)
	{
		if (screen.availHeight >= 822){
		var goodtop = 0;
		goodtop = (screen.availHeight - 822)/2;
		newwindow = window.open(url,'location','top='+goodtop+',scrollbars=1,width=630,height=822');
		}else{
		var maxheight = 400;
		maxheight = screen.availHeight;
		//alert (maxheight);
		newwindow = window.open(url,'location','scrollbars=1,top=0,width=630,height='+maxheight+'');
		}
	}else{
	newwindow = window.open(url,'location','scrollbars=1,top=0,width=630,height=400');
	}

	if (window.focus) {newwindow.focus()}
	return false;
}

function popupscreensaver(url) {

	if (screen)
	{
		if (screen.availHeight >= 685){
		var goodtop = 0;
		goodtop = (screen.availHeight - 685)/2;
		newwindow = window.open(url,'location','top='+goodtop+', width=680,height=685');
		}else{
		var maxheight = 400;
		maxheight = screen.availHeight;
		//alert (maxheight);
		newwindow = window.open(url,'location','scrollbars=1 top=0, width=680, height='+maxheight+'');
		}
	}else{
	newwindow = window.open(url,'location','scrollbars=1 top=0,width=680,height=400');
	}

	if (window.focus) {newwindow.focus()}
	return false;
}

/*	DESCRIPTION: popup window for 360 degree iPix movies.
*/
function clientWin(pagename) {
	window.open(pagename, '', 'scrollbars=0, resizable, width=400, height=455, left=300, top=200');
}
function clientWinFlash(pagename) {
	window.open(pagename, '', 'scrollbars=0, resizable, width=400, height=550, left=300, top=200');
}

/*	DESCRIPTION: 4 scripts for rollover images.
*/
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_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_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];}
}