/*

Title: Silhouette Image Rollover

Created by: Tim Ottewell
Created on: 08/06/2009
Version 1.0

Changes:

Changes made by:
Date of changes:

*/

function changeImages(rLink, imageLocation, rolloverImages) {
	//Code to swap out the silhouette images
	
	//gets the ID of the link that has been clicked
	var linkID = rLink.getAttribute("id");
	
	//create an array containing the rollover images
	var images = rolloverImages.getElementsByTagName("img");	
	
	//looks through all the rollover images
	for (var i = 0; i < images.length; i++) {
		//gets the ID of each rollover image
		var imageID = images[i].getAttribute("id");
		
		//if the ID of the image matches the ID of the link
		if (linkID == imageID) {
			//get the source attribute of the rollover image
			var imageSource = images[i].getAttribute("src");
			
			//set the image source of the holder to the rollover image source
			imageLocation.setAttribute("src", imageSource);
		}
	}
}

function prepareImages() {
	//sets the default image that will be displayed at the beginning and on rollout 
	var defaultImage = document.getElementById("imageHolder");
	
	//sets the array of images that will be used for rollovers
	var rolloverImages = document.getElementById("rolloverImages");
	
	//sets the source for the default rollover image
	var defaultImageSource = defaultImage.getAttribute("src");
	
	
	//sets the default title image that will be displayed at the beginning and on rollout 
	var defaultTitleImage = document.getElementById("titleHolder");
	
	//sets the array of images that will be used for rollovers
	var titleRolloverImages = document.getElementById("titleRolloverImages");
	
	//sets the source for the default title image
	var defaultTitleImageSource = defaultTitleImage.getAttribute("src");
	
	
	//get the div containing the topic rollover links
	var rolloverLinks = document.getElementById("rolloverLinks");
	
	//create an array of all the topic links
	var links = rolloverLinks.getElementsByTagName("a");
	
	//get the div containing the topic rollover links
	var rolloverPeopleLinks = document.getElementById("rolloverPeopleLinks");
	
	//create an array of all the topic links
	var peopleLinks = rolloverPeopleLinks.getElementsByTagName("a");
	
	//check for mouse over and mouse out events on the topics links
	for (var i = 0; i < links.length; i++) {
		links[i].onmouseover = function() {
			changeImages(this, defaultImage, rolloverImages);
			changeImages(this, defaultTitleImage, titleRolloverImages);
		}
		//hide things on rollout
		links[i].onmouseout = function() {
			//change the src attribute for the default image
			defaultImage.setAttribute("src", defaultImageSource);
			defaultTitleImage.setAttribute("src", defaultTitleImageSource);
		}
	}
	
	//check for mouse over and mouse out events on the people links
	for (var i = 0; i < peopleLinks.length; i++) {
		peopleLinks[i].onmouseover = function() {
			changeImages(this, defaultImage, rolloverImages);
			changeImages(this, defaultTitleImage, titleRolloverImages);
		}
		//hide things on rollout
		peopleLinks[i].onmouseout = function() {
			//change the src attribute for the default image
			defaultImage.setAttribute("src", defaultImageSource);
			defaultTitleImage.setAttribute("src", defaultTitleImageSource);
		}
	}
}

//function to run the script which everything has loaded
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

//run the script
addLoadEvent(prepareImages);
