//Reposition the 4th-level navigation ul to beneath the big img in the content div of the page template

function getPosition(e){
	var left = 0;
	var top  = 0;
	while (e.offsetParent){
		left += e.offsetLeft;
		top += e.offsetTop;
		e = e.offsetParent;
	}
	left += e.offsetLeft;
	top += e.offsetTop;
	return {x:left, y:top};
}

function getHeight(e){
	var height=0;
	height=e.offsetHeight;
	return height;	
}

function repositionNav4(){
	//Create array of navigation ul's
	var navUlFour=document.getElementById('navigation').getElementsByTagName('ul');
	//Create array of img elements in the content (should only ever be one)
	var postImg=document.getElementById('content').getElementsByTagName('img');
	//Get current position of the 4th-level navigation ul
	var ulPosition=getPosition(navUlFour[3]);
	//Get position of the image that we want to place the 4th-level ul beneath
	var imgPosition=getPosition(postImg[0]);
	//Get height of same image
	//var imgHeight=getHeight(postImg[0]);
	//Some browsers can't get height of image on page (should always be 380 - added 5 for padding)
	var imgHeight=385;
	//Calculate total distance from bottom of image to top of window
	var yFromTop=imgPosition.y+imgHeight;
	//Calculate difference between y-position of 4th-level navigation ul and bottom of image
	var imgUlDiff=yFromTop-ulPosition.y;
	//Move the 4th-level navigation ul down the appropriate distance
	navUlFour[3].style.top = imgUlDiff+"px";

	//Diagnostics
	/*document.write("<p>UL x position is: "+ulPosition.x+"<br />UL y position is: "+ulPosition.y+"</p>");
	document.write("<p>IMG x position is: "+imgPosition.x+"<br />IMG y position is: "+imgPosition.y+"</p>");
	document.write("<p>IMG height is: "+imgHeight+"px.</p>");
	document.write("<p>Distance between window top and IMG bottom is: "+yFromTop+"px.</p>");
	document.write("<p>Difference between UL y position and IMG bottom is: "+imgUlDiff+"px.</p>");
	document.write("<p>User Agent is: "+$userAgent+"</p>");
	*/
	//alert("UL x position is: "+ulPosition.x+"\n\rUL y position is: "+ulPosition.y+"\n\rIMG x position is: "+imgPosition.x+"\n\rIMG y position is: "+imgPosition.y+"\n\rIMG height is: "+imgHeight+"\n\rDistance between window top and IMG bottom is: "+yFromTop+"\n\rDifference between UL y position and IMG bottom is: "+imgUlDiff+"\n\rUser Agent is: "+$userAgent);
}
