/* // ||||||||||||||||||||||||||||||||||||||||||||||||||
// Creating a new image element will force the browser
// to redraw the image. Simple image src swaping will not.
// 'Src swap' version
*/

function doNav(){
	var image = document.getElementById("theimage");
	var newimage = document.createElement("img");
	var parent = image.parentNode;
	parent.replaceChild(newimage, image);
	newimage.setAttribute("id","theimage");
	newimage.setAttribute("src",this.href);
	newimage.setAttribute("alt",this.xtitle);
	//newimage.setAttribute("width",image.getAttribute("width"));
	//newimage.setAttribute("height",image.getAttribute("height"));
	
	curNav.className = "";
	this.className = "on";
	curNav = this;

	return false;
}


function get_firstChild(o) { 
	return (o.firstChild.nodeName == "#text") ? o.firstChild.nextSibling : o.firstChild;
}




// ||||||||||||||||||||||||||||||||||||||||||||||||||

function attachNav(){
	var i, e;
	var imageTotal = 0;
	var wrap = document.getElementById("imgnav")
	if (!wrap) return;
	for (i = 0; i < wrap.childNodes.length; i ++) {
		if ((wrap.childNodes[i].nodeName == "OL") || (wrap.childNodes[i].nodeName == "UL")){
			var nav = wrap.childNodes[i];
			
		}
	}
	//var nav = get_firstChild(wrap); //wrap.firstChild; //.parentNode.parentNode;
	nav.className = "imgnav";

	var navItems = new Array();
	
	for (i = 0; i < nav.childNodes.length; i ++) {
		if (nav.childNodes[i].nodeName == "LI") {
			navItems[navItems.length] = nav.childNodes[i];
			imageTotal++;
		}
	}
	
	if (document.createElement) 
	{
		var descli = document.createElement("li");
		var descdiv = document.createElement("div");
			descdiv.setAttribute("id","intro");
			descli.appendChild(descdiv);		
			nav.appendChild(descli);
			
		var imgdiv = document.createElement("div");
			imgdiv.className = "bild";
		var image = document.createElement("img");
			image.setAttribute("id","theimage");
			
			var link = get_firstChild(navItems[0]);
			
			image.setAttribute("src",link.href);
			image.setAttribute("alt",link.title);
			image.setAttribute("id","theimage");
			imgdiv.appendChild(image);
			
			wrap.insertBefore(imgdiv,nav); 
	}
	
	
	
	for(i = 0; i < navItems.length; i ++){
		e = get_firstChild(navItems[i]); //document.getElementById("imgnav"+i);
		if (e) {
			
			//e.firstChild.nodeValue = i+1;
			e.onclick = doNav;
			if (e.title != "") {
				e.onmouseover = function() { 
					var d = document.getElementById('intro');
					if (d) d.innerHTML = this.title;
					//window.status = this.title; return true;
					}
				
				e.onmouseout = function() { 
					var d = document.getElementById('intro');
					if (d) d.innerHTML = curNav.title;
					//window.status = ''; return true;
					}
			}
			e.onfocus = e.blur;
			if(i == 0) { 
				curNav = this;
				e.onclick();
				e.onmouseover();
			}
		}
	}
}
if (document.getElementById){
	addOnLoad("attachNav");
}