/**
 * function to change the background by clicking 
 * on small images on the left content.
 * @var imageId		id of image in html
 * @var caller		0 if called directly, true if called by another function
 */
 
function changeImage(imageId, caller) {
  	var imageContainer = document.getElementById('centerContent');
  	var image = document.getElementById(imageId);
  	if (image) {
		var imageWidth; 
		// <IE9
		var imageHtml = image.outerHTML;
		// others
		if (! imageHtml) {
			imageHtml = new XMLSerializer().serializeToString(image);
		}
		// others
		var pattern = /width="(\d*)"/;
		var imageWidthArray = pattern.exec(imageHtml);
		if (imageWidthArray && imageWidthArray.length > 1) {
			imageWidth = imageWidthArray[1];
		}
		// <IE9
		else {
			pattern = /width=(\d*)/;
			imageWidthArray = pattern.exec(imageHtml);
			imageWidth = imageWidthArray[1];
		}

		var imageContainerWidth = 440;
		//var imageWidth = image.getAttribute("width");
		imageContainer.style.backgroundImage = "url()";
		if (imageWidth && imageWidth < imageContainerWidth) {
			imageContainer.style.backgroundPosition = (imageContainerWidth - imageWidth) / 2 + "px center";
		}
		else {
			imageContainer.style.backgroundPosition = "left center";
		}
		imageContainer.style.backgroundImage = "url(" + image.src + ")";
	}
}	

/**
 * Add mouse over eventhandlers to the menubar.
 * Only for internet explorer.
 */

function startList() {
  if (document.all && document.getElementById) {
  	// list
	var navRoot = document.getElementById("navigationList");
    for (i=0; i<navRoot.childNodes.length; i++) {
      node = navRoot.childNodes[i];
      if (node.nodeName=="LI") {
		node.onmouseover=function() {
	  		this.className+=" over";
		}
		node.onmouseout=function() {
	  		this.className=this.className.replace(" over", "");
		}
      }
    }
    // submit button
    var button = document.getElementById("button");
    if(button){
		button.onmouseover=function() {
	  	this.className+=" over";
		}
		button.onmouseout=function() {
	  	this.className=this.className.replace(" over", "");
		}
	} 
	// info button
	var info = document.getElementById("info");
	if(info){
		info.onmouseover=function() {
	 	this.className+=" over";
		}
		info.onmouseout=function() {
	  	this.className=this.className.replace(" over", "");
	  	}
	}
	//layer button
	var layer = document.getElementById("layer");
	if(layer){
		layer.onmouseover=function() {
		this.className+=" over";
		}
		layer.onmouseout=function() {
		this.className=this.className.replace(" over", "");
		}
	}
   }
}

callOnLoad(startList);

/**
 * Attach events to onload.
 */
 
function callOnLoad(init) {
	if (window.addEventListener) {
		window.addEventListener("load", init, false);
	}
	else if (window.attachEvent) {
		window.attachEvent("onload", init);
	}
	else {
		window.onload = init;
	}
}

