function moveElement(elementID,final_x,final_y,interval)
{
	if(!document.getElementById) return false;
	if(!document.getElementById(elementID)) return false;
	var elem = document.getElementById(elementID);
	if (elem.movement)
	{
		clearTimeout(elem.movement);
	}
	if (!elem.style.left)
	{
		elem.style.left = "0px";
	}
	if (!elem.style.top)
	{
		elem.style.top = "0px";
	}
	var xpos = parseInt(elem.style.left);
	var ypos = parseInt(elem.style.top);
	if (xpos == final_x && ypos == final_y)
	{
		return true;
	}
	if (xpos < final_x)
	{
		var dist = Math.ceil((final_x - xpos)/2)
		xpos += dist;
	}
	if (xpos > final_x)
	{
		var dist = Math.ceil((xpos - final_x)/2)
		xpos -= dist;
	}
	if (ypos < final_y)
	{
		var dist = Math.ceil((final_y - ypos)/2)
		ypos += dist;
	}
	if (ypos > final_y)
	{
		var dist = Math.ceil((ypos - final_y)/2)
		ypos -= dist;
	}
	elem.style.left = xpos + "px";
	elem.style.top = ypos + "px";
	var repeat = "moveElement('"+elementID+"',"+final_x+", "+final_y+", "+interval+")";
	elem.movement = setTimeout(repeat,interval);
}

function prepareSlideshow()
{
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("secondaryContent")) return false;
	
	var secCont = document.getElementById("secondaryContent");
	var slideshow = document.createElement("div");
	slideshow.setAttribute("id", "slideshow");
	
	var preview = document.createElement("img");
	preview.setAttribute("src","pics/home/sitemap.gif");
	preview.setAttribute("alt","sitemap");
	preview.setAttribute("id","preview");
	
	slideshow.appendChild(preview);
	secCont.appendChild(slideshow);
	
	var first = -5;
	var second = -225;
	var third = -445;
	var fourth = -665;
	
	// get links
	var navHome = document.getElementById("navHome");
	var divs = navHome.getElementsByTagName("div");		
	
	for (var i=0; i<divs.length; i++)
	{			
		divs[i].onmouseover = function()
		{	
			
			var destination = this.getAttribute("id");
			if (destination.indexOf("one") != -1)
			// first row
			{
				moveElement("preview",first,first,2);
			}
			if (destination.indexOf("two") != -1)
			{
				moveElement("preview",second,first,2);
			}
			if (destination.indexOf("three") != -1)
			{
				moveElement("preview",third,first,2);
			}
			if (destination.indexOf("four") != -1)
			{
				moveElement("preview",fourth,first,2);
			}
			
			// second row
			if (destination.indexOf("five") != -1)
			{
				moveElement("preview",first,second,2);
			}
			if (destination.indexOf("six") != -1)
			{
				moveElement("preview",second,second,2);
			}
			if (destination.indexOf("seven") != -1)
			{
				moveElement("preview",third,second,2);
			}
			if (destination.indexOf("eight") != -1)
			{
				moveElement("preview",fourth,second,2);
			}
			
			// third row
			if (destination.indexOf("nine") != -1)
			{
				moveElement("preview",first,third,2);
			}
			if (destination.indexOf("ten") != -1)
			{
				moveElement("preview",second,third,2);
			}
			if (destination.indexOf("eleven") != -1)
			{
				moveElement("preview",third,third,2);
			}
			if (destination.indexOf("twelve") != -1)
			{
				moveElement("preview",fourth,third,2);
			}
			
			// fourth row
			if (destination.indexOf("thirteen") != -1)
			{
				moveElement("preview",first,fourth,2);
			}
			if (destination.indexOf("fourteen") != -1)
			{
				moveElement("preview",second,fourth,2);
			}
			if (destination.indexOf("fifteen") != -1)
			{
				moveElement("preview",third,fourth,2);
			}
			if (destination.indexOf("sixteen") != -1)
			{
				moveElement("preview",fourth,fourth,2);
			}
		}
	}
}

function colourPics()
{
	
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("navHome")) return false;
	
	var navHome = document.getElementById("navHome");
	var images = navHome.getElementsByTagName("img");
	for (var i=0; i<images.length; i++)
	{
		images[i].oldClassName = images[i].className;
		
		images[i].onmouseover = function()
		{
			this.className = "slideLeft";
		}
		
		images[i].onmouseout = function()
		{
			this.className = "slideRight";
	
		}
	}
}
addLoadEvent(colourPics);
addLoadEvent(prepareSlideshow);

