// JavaScript Document



function QueryString(key)
{
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			break;
		}
	}
	return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();

function QueryString_Parse()
{
	var query = window.location.search.substring(1);
	var pairs = query.split("&");
	
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;		
		}
	}

}
QueryString_Parse();

  
  
function loadNav()
{
	
	//If it has items in then don't fill with more
	if(document.navigationForm.linkintoSd3.options.length>0)
		return;
		
	//Create a title
	var anOption = document.createElement("OPTION");
	anOption = new Option("Please select");
	document.navigationForm.linkintoSd3.options.add(anOption);
	//anOption.innerText = "Please select";
	anOption.value = "";
		
	//Load up the main navigation
	for(i=0;i<navigation.length;i++)
	{		
		//document.navigationForm.nav1.options[i].innerHTML = knowledge[i];
		//document.navigationForm.nav1.options[i].value = links[i];
		var anOption = document.createElement("OPTION");
		anOption = new Option(navigation[i]);		
		anOption.value = navigation_links[i];
		document.navigationForm.linkintoSd3.options.add(anOption);
		//alert(anOption.value);		
	}
	
}
	
function loadKnowledgeNav()
{
	//If it has items in then don't fill with more
	if(document.knowledgeForm.exploresustainability.options.length>0)
		return;
		
	//Create a title
	var anOption = document.createElement("OPTION");
	anOption = new Option("Please select");
	document.knowledgeForm.exploresustainability.options.add(anOption);
	
	anOption.value = "";
	
	//Load up the knowledge navigation
	for(i=0;i<knowledge.length;i++)
	{		
		//document.navigationForm.nav1.options[i].innerHTML = knowledge[i];
		//document.navigationForm.nav1.options[i].value = links[i];
		var anOption = document.createElement("OPTION");
		anOption = new Option(knowledge[i]);		
		anOption.value = knowledge_links[i];
		document.knowledgeForm.exploresustainability.options.add(anOption);		
	}
	
	
}

function loadCaseStudyNav()
{
	//If it has items in then don't fill with more
	if(document.casestudyForm.readcasestudy.options.length>0)
		return;
		
	//Create a title
	var anOption = document.createElement("OPTION");
	anOption = new Option("Please select");
	document.casestudyForm.readcasestudy.options.add(anOption);
	
//Load up the knowledge navigation
	for(i=0;i<casestudy.length;i++)
	{		
		//document.navigationForm.nav1.options[i].innerHTML = knowledge[i];
		//document.navigationForm.nav1.options[i].value = links[i];
		var anOption = document.createElement("OPTION");
		anOption = new Option(casestudy[i]);		
		anOption.value = casestudy_links[i];
		document.casestudyForm.readcasestudy.options.add(anOption);		
	}

}

function list()
{
	for(i=0;i<document.navigationForm.linkintoSd3.options.length;i++)
	{
		alert('list: ' + document.navigationForm.linkintoSd3.options[i].innerHTML);
		alert('value: ' + document.navigationForm.linkintoSd3.options[i].value);
	}
}
function goToLink()
{
	//if(document.navigationForm.nav1.selected)
	var newLocation = document.navigationForm.linkintoSd3.value;
	if(newLocation.length>0)
		document.location = newLocation
}

function goToKnowledgeLink()
{
	
	//if(document.navigationForm.nav1.selected)
	var newLocation  = document.knowledgeForm.exploresustainability.value;
	if(newLocation.length>0)
		document.location  = newLocation
}
function goToCaseStudyLink()
{
	
	//if(document.navigationForm.nav1.selected)	
	var newLocation  = document.casestudyForm.readcasestudy.value;
	if(newLocation.length>0)
		document.location  = newLocation
}


/***********************************************************************************************************

				 THE IMAGELOADER
	
************************************************************************************************************/
function preLoadImages(){
	
	/*For the preLoading of images to take place, this function must be called in the onLoad handler caller
	in the body tag of the page. Images that are to be swapped must have a capital 'H' on the end and the original
	image should have a capital 'N' on the end*/
	
	
 	imageArray = new Array();
 	
	
	
	/*****************************************************************/
 	
	/*If there are any extra Images that cannot be detected they should be 
	placed in a array called ExtraImages which the following script will detect*/
	
	
	var URLstring = document.location.toString();
	
	n = URLstring.length;
	while(URLstring.charAt(n)!="/"){
		
			n--;}
		
			var preFix = URLstring.slice(0,n);
			
	
	
	
		
	if(typeof(ExtraImages)=="object"){
		eX = new Array();
		
		for(i=0;i<ExtraImages.length;i++){
			extra_image = new Image();
			eX[i] = extra_image;
			
			var extra_string = preFix+ExtraImages[i];
			
			eX[i].src=extra_string;
			
		}}
		
		
	/*****************************************************************/	
		
	
	/*The following script finds all images with 'H' or 'N' as the last letter and preLoads the 
	image with the opposite letter on the end*/
	for(i=0;i<document.images.length;i++){
		
	
		var an_image = new Image();
		imageArray[i]= an_image;
		an_image_string = document.images[i].src;
		
		
		var theString =an_image_string.toString();
		
		var last= theString.lastIndexOf(".");
		
		if (theString.charAt(last-1) == "N"||theString.charAt(last-1) == "n"){
			
			var suffix = theString.slice(last,theString.length);
			var newString = theString.slice(0,last-1)+"H"+suffix;
			imageArray[i].src= newString;
			
			
		}
		
		if (theString.charAt(last-1) == "H"||theString.charAt(last-1) == "h"){
			
			var suffix = theString.slice(last,theString.length);
			var newString = theString.slice(0,last-1)+"N"+suffix;
			imageArray[i].src= newString;
			
			
			
		}
		
		
	}
	
	
}
/***********************************************************************************************************

				 THE IMAGESWAPPER
	
************************************************************************************************************/
function imgswap(pic,imageName){
	
	/*This function takes image names that have "N" for normal or "H" for highlighted as the last
	letter in the image name and also a suffix (".gif" etc) must be present also 
	All images must be in a folder named "media" unless otherwise explicitly stated in all references
	to the image within the HTML page.
	If the image rolled over changed a different image than itself on the same page then add the name of 
	the swapped image as the second parameter (imageName) otherwise leave it blank*/
	

	if (pic.indexOf("media")==-1){
			
			pic = "media/"+pic;
			}
			
	var suffix = pic.slice(pic.length-4,pic.length);
	
  	var picstartpos = pic.indexOf("media/");
	var picname = pic.substring(picstartpos+6,pic.length-5);
	
	
	
	if(typeof(imageName)!="undefined"){
		picname=imageName;}
	
  	if(document.all){
  	
  	
  	
			document.all(picname).src=pic;
  	}
  
  
  	if(document.layers){
  
  	var theString = document.images[picname].src;
  	
  	/*This finds the second to last delimiter to obtain the whole image address for Netscape
  	or just gives it the ../name string which appears to work*/
  	
  	
  	if(pic.charAt(0)=="."){
  		
  	document.images[picname].src=pic;}
  	else{
  	var lastPos = (theString.slice(0,theString.lastIndexOf("/")-1).lastIndexOf("/")+1);
 	document.images[picname].src=theString.slice(0,lastPos)+(pic);
 	}
   
  }
}


/***********************************************************************************************

						Style Chooser
						
************************************************************************************************/
function chooseStyle(csspath){
	//This function is called on loading every page 
	//for the purposes of referencing a style sheet.
	if(csspath == null)
		csspath ='';
		
	/*if(document.all){
		document.write('<'+'link rel="stylesheet" href="' + csspath + 'css/explorer.css" />');
	}
	if(document.layers){
		document.write('<'+'link rel="stylesheet" href="' + csspath + 'css/netscape.css" />');
	}*/
	
	if (navigator.userAgent.indexOf('Mac')==-1) 
	{
		document.write('<'+'link rel="stylesheet" href="' + csspath + 'css/pc.css" />');
	}
	else
	{
		document.write('<'+'link rel="stylesheet" href="' + csspath + 'css/mac.css" />');
	}

}
/***********************************************************************************************************

				 	OPEN POPUP WINDOW
	
************************************************************************************************************/
// page=*.asp or *.html to open
// h,w,t,l = height,width,top,left
// rs = resizable scrollbars
function openpopup(page,pagename,h,w,t,l,rs,sbs) { 
	
  w = window.open(page, pagename, "height="+h+",width="+w+",top="+t+",left="+l+",resizable="+rs+",scrollbars="+sbs);
  w.focus();
}


function opencenteredpopup(page,pagename,h,w,rs,sbs) 
{ 
  l = (screen.width/2)-(w/2);
  t = (screen.height/2)-(h/2);
   
  w = window.open(page, pagename, "height="+h+",width="+w+",top="+t+",left="+l+",resizable="+rs+",scrollbars="+sbs);
  w.focus();
}
/*************************************************************************************************************

					The news ticker					
					
**************************************************************************************************************/
//enviroment_newsticker();"

var latestreports_i=-1;			// current letter being typed
var latestreports_cnt=0;			// current news item
function latestreports_newsticker()
{
  // next character of current item
  if (latestreports_i < latestreports_newslist[latestreports_cnt][0].length - 1)
  {
    latestreports_i++;
    temp1 = latestreports_newslist[latestreports_cnt][0];
    temp1 = temp1.split('');
    latestreports_curr = latestreports_curr+temp1[latestreports_i];
    temp2 = latestreports_newslist[latestreports_cnt][1];
    reports_news.innerHTML = "<small><a href='"+temp2+"' class='snippets' target='_self'>"+latestreports_curr+"</a>";
    setTimeout('latestreports_newsticker()',10)
    return;
  }
  // new item
  latestreports_i = -1; latestreports_curr = "";
  if (latestreports_cnt<latestreports_newslist.length-1)
    latestreports_cnt++;
  else
    latestreports_cnt=0;
  setTimeout('latestreports_newsticker()',3000)
}


var imagenum = 0;
function StartImageRotate()
{
	window.setTimeout('rotate()',1000);
}
function rotate()
{
	
	//Clear all
	for(i=1;i<4;i++)
		imgswap('image' + i + 'N.gif','Image' + i);
		
	imagenum++;
	if(imagenum>3)
		imagenum = 1;

	
	imgswap('image' + imagenum + 'H.gif','Image' + imagenum);
	window.setTimeout('rotate()',1500);
}
