// JavaScript Document

var currentSpanObj = 0;
var firstSpanObj = 0;

function MyClickFunction(e)
{
	if (!e) e = window.event;
	thumbMedia = (e.target) ? e.target : e.srcElement;
	spanObj = thumbMedia.nextSibling;
	currentSpanObj.style.visibility = "hidden";
	if (currentSpanObj.parentNode.className == "JavaVideo")
	{
		currentSpanObj.saveChild = currentSpanObj.removeChild(currentSpanObj.firstChild);
	}
	if (spanObj.parentNode.className == "JavaVideo")
	{
		spanObj.appendChild(spanObj.saveChild);
	}
	spanObj.style.visibility = "visible";
	currentSpanObj = spanObj;
}

function ShowTree(path, node)
{
	if (node.id) path = path + "=" + node.id;
	else if (node.className) path = path + "<" + node.className + ">";
	var children = node.childNodes;
	if (!children.length) return path + "\n";
	if (children.length == 1) return ShowTree(path + "/" + children[0].nodeName, children[0]);;
	var tree = "";
	for (var i = 0; i < children.length; i++)
		tree = tree + ShowTree(path + "/" + children[i].nodeName + "(" + (i+1) + ")", children[i]);
	return tree;
}

function MyLoadFunction()
{
    links = document.getElementsByTagName("a");
	anchor = location.hash;
	if (anchor.length) anchor = anchor.substring(1,anchor.length);
	
	for (i = 0; i < links.length; i++)
	{
		linkObj = links[i];
		if (linkObj.className == "imagelink")
		{
			thumbImage = linkObj.firstChild;
			spanImage = linkObj.lastChild;
			fullImage = spanImage.firstChild;
			thumbImage.onclick = MyClickFunction;	
			
			spanImage.style.position = "absolute";
			spanImage.style.left = (hcenter - fullImage.width/2) + "px";
			spanImage.style.top  = (vcenter - fullImage.height/2) + "px";
			if (anchor.length && linkObj.id == anchor)
			{
				currentSpanObj = spanImage;
				spanImage.style.visibility = "visible";
			}
			else
			{
				spanImage.style.visibility = "hidden";
			}
			spanImage.style.color = "#ffffff";
			spanImage.style.fontFamily = "Arial, Helvetica, sans-serif";
			spanImage.style.fontSize = "12px";
			spanImage.style.textDecoration = "none";
			
			fullImage.style.borderWidth = "1px";
			fullImage.style.borderStyle = "solid";
			fullImage.style.borderColor = "#777";
			
			
			linkObj.className = "JavaImg";
			if (!firstSpanObj) firstSpanObj = spanImage;			
		}
		else if (linkObj.className == "videolink")
		{
			// alert(ShowTree(linkObj.nodeName, linkObj));
			thumbVideo = linkObj.firstChild;
			spanVideo = linkObj.lastChild;
			for (k = 0; k < spanVideo.childNodes.length; k++)
				if (spanVideo.childNodes[k].nodeName.toLowerCase() != "object" &&
					 spanVideo.childNodes[k].nodeName.toLowerCase() != "embed")
						spanVideo.removeChild(spanVideo.childNodes[k--])
			videoVideo = spanVideo.firstChild;
			thumbVideo.onclick = MyClickFunction;	
			// alert(ShowTree(linkObj.nodeName, linkObj));
		
			spanVideo.style.position = "absolute";
			spanVideo.style.left = (hcenter - videoVideo.width/2) + "px";
			spanVideo.style.top  = (vcenter - videoVideo.height/2) + "px";
			if (anchor.length && linkObj.id == anchor)
			{
				currentSpanObj = spanVideo;
				spanVideo.style.visibility = "visible";
			}
			else
			{
				spanVideo.style.visibility = "hidden";
				spanVideo.saveChild = spanVideo.removeChild(videoVideo);

			}
			spanVideo.style.color = "#FFFFFF";
			spanVideo.style.fontFamily = "Arial, Helvetica, sans-serif";
			spanVideo.style.fontSize = "12px";
			spanVideo.style.textDecoration = "none";
			
			linkObj.className = "JavaVideo";
			if (!firstSpanObj) firstSpanObj = spanVideo;			
		}
	}
	
	if (!currentSpanObj)
	{
		currentSpanObj = firstSpanObj;
		if (currentSpanObj.parentNode.className == "JavaVideo")
		{
			currentSpanObj.appendChild(currentSpanObj.saveChild);
		}
		currentSpanObj.style.visibility = "visible";
	}
}

if (document.getElementsByTagName) window.onload = MyLoadFunction;
