var currentActiveMenu = 0;


//////////////////////////////////////////////////////////////////////////////////////////////////////


function flipChamImageLoad(filename)
{
	document.getElementById('load' + filename).style.display = 'none'; document.getElementById('image' + filename).style.display = 'inline';
}


//////////////////////////////////////////////////////////////////////////////////////////////////////


function showEnlargeAndPrint(specifier, sel)
{
	var windowHandle = window.open("enlarge.cfm?specifier=" + specifier + "&sel=" + sel, "enlargeandprintwindow", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=790,height=550,top=5,left=5");
	windowHandle.focus();
}


//////////////////////////////////////////////////////////////////////////////////////////////////////


function GetXmlHttpObject(handler)
{ 
	var objXMLHttp = null;
	if(window.XMLHttpRequest)
	{
		objXMLHttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp
}	


//////////////////////////////////////////////////////////////////////////////////////////////////////

	
function AJAXReplace(elementid, url)
{
	var xmlHttp = GetXmlHttpObject();
	var baseElement = document.getElementById(elementid);
	if(xmlHttp == null || baseElement == null)
	{
		return;
	}
	baseElement.innerHTML = "Loading, please wait...";
	baseElement.xmlHttpObject = xmlHttp;
	eval("baseElement.xmlHttpFunction = function() { baseElement = document.getElementById(\"" + elementid + "\"); if(baseElement.xmlHttpObject.readyState==4 || baseElement.xmlHttpObject.readyState==\"complete\")	{ 			baseElement.innerHTML = baseElement.xmlHttpObject.responseText;	} }");
	xmlHttp.onreadystatechange = baseElement.xmlHttpFunction;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}


//////////////////////////////////////////////////////////////////////////////////////////////////////

	
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}


//////////////////////////////////////////////////////////////////////////////////////////////////////


function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


//////////////////////////////////////////////////////////////////////////////////////////////////////


function toggleMenu(menunum)
{
	var baseElement = document.getElementById("surfacepopup" + menunum);
	baseElement.style.left = (findPosX(document.getElementById("surfacebutton" + menunum)) - (baseElement.offsetWidth + 5)) + "px";
	baseElement.style.top = findPosY(document.getElementById("surfacebutton" + menunum)) + "px";
	if(currentActiveMenu != menunum && currentActiveMenu > 0)
	{
		deactivateMenu("surfacepopup" + currentActiveMenu);
		document.getElementById("surfacebutton" + currentActiveMenu).className = "surfacebutton";
		currentActiveMenu = 0;
	}
	if(baseElement.fadePosition)
	{
		if(baseElement.fadePosition > 0)
		{
			deactivateMenu("surfacepopup" + menunum);
			document.getElementById("surfacebutton" + menunum).className = "surfacebutton";
			if(currentActiveMenu == menunum)
			{
				currentActiveMenu = 0;
			}
		}
		else
		{
			activateMenu("surfacepopup" + menunum);
			document.getElementById("surfacebutton" + menunum).className = "surfacebuttonon";
			currentActiveMenu = menunum;
		}
	}
	else
	{
		activateMenu("surfacepopup" + menunum);
		document.getElementById("surfacebutton" + menunum).className = "surfacebuttonon";
		currentActiveMenu = menunum;
	}
}


//////////////////////////////////////////////////////////////////////////////////////////////////////


function activateMenu(menuid)
{
	var baseElement = document.getElementById(menuid);
	if(baseElement)
	{
		if(baseElement.ajaxUrl)
		{
			if(baseElement.ajaxLoaded == false)
			{
				AJAXReplace(menuid.replace("surfacepopup", "surfacepopupcontents"), baseElement.ajaxUrl);
				baseElement.ajaxLoaded = true;
			}
		}
		if(baseElement.fadeIntervalHandle)
		{
			clearInterval(baseElement.fadeIntervalHandle);
			baseElement.fadeIntervalHandle = null;
		}
		baseElement.fadePosition = 1;
		baseElement.fadeDirection = 1;
		baseElement.fadeIntervalHandle = setInterval("fadeProgression(\"" + menuid + "\");", 50);
	}
}


//////////////////////////////////////////////////////////////////////////////////////////////////////


function deactivateMenu(menuid)
{
	var baseElement = document.getElementById(menuid);
	if(baseElement)
	{
		if(baseElement.fadeIntervalHandle)
		{
			clearInterval(baseElement.fadeIntervalHandle);
			baseElement.fadeIntervalHandle = null;
		}
		baseElement.fadePosition = 9;
		baseElement.fadeDirection = -1;
		baseElement.fadeIntervalHandle = setInterval("fadeProgression(\"" + menuid + "\");", 50);
	}
}


//////////////////////////////////////////////////////////////////////////////////////////////////////


function fadeProgression(menuid)
{
	var baseElement = document.getElementById(menuid);
	if(baseElement)
	{
		baseElement.style.height = (baseElement.fadePosition * 35) + "px";
//			baseElement.style.width = (baseElement.fadePosition * 60) + "px";
//			baseElement.style.height = ((baseElement.fadePosition * 60) > 350 ? 350 : (baseElement.fadePosition * 60)) + "px";
		baseElement.style.opacity = (baseElement.fadePosition * 0.1);
		if(baseElement.style.filter || 1 == 1)
		{
			baseElement.style.filter = "alpha(opacity=" + (baseElement.fadePosition * 10) + ")";
		}
		baseElement.fadePosition += baseElement.fadeDirection;
		if(baseElement.fadePosition < 0 || baseElement.fadePosition >= 11)
		{
			clearInterval(baseElement.fadeIntervalHandle);
			baseElement.fadeIntervalHandle = null;
		}
	}
}


//////////////////////////////////////////////////////////////////////////////////////////////////////


function enhanceClasses()
{
	var allTags, classes, i, j, k;
	if(document.all)
	{
		allTags = document.all
	}
	else
	{
		allTags = document.getElementsByTagName("*");
	}
	for(i=0;i<allTags.length;i++)
	{
		// This "if" block is necessary because Opera 9 sometimes breaks on className.split(). For some reason, className can be a null or "undefined" object in Opera. Other browsers don't have this problem.
		if(allTags[i].className)
		{
			classes = allTags[i].className.split(" ");
		}
		else
		{
			classes = new Array();
			classes[0] = "";
		}
		for(j=0;j<classes.length;j++)
		{
			if(classes[j] == "vmiddle")
			{
				allTags[i].style.position = "relative";
				allTags[i].style.top = ((allTags[i].parentNode.offsetHeight / 2) - (allTags[i].offsetHeight / 2)) + "px";
				allTags[i].className = allTags[i].className + " vmiddleprocessed";
			}
			if(classes[j] == "shadowed")
			{

				var goahead = true;
				if(allTags[i].previousSibling)
				{
					if(allTags[i].previousSibling.className.indexOf("dropshadowtext") > -1)
					{
						goahead = false;
					}
				}
				if(goahead == true)
				{					
					var tempElement = allTags[i].cloneNode(true);
					tempElement.style.color = "black";
					tempElement.style.marginTop = allTags[i].style.marginTop;
					tempElement.style.marginRight = allTags[i].style.marginBottom;
					tempElement.style.marginBottom = "-" + allTags[i].offsetHeight + "px";						
					tempElement.style.marginLeft = allTags[i].style.marginLeft;
					var baseLeft = 0;
					var baseTop = 0;
					if(allTags[i].style.position == "relative")
					{
						baseLeft = allTags[i].style.left.replace("px", "");
						baseTop = allTags[i].style.top.replace("px", "");
					}
					tempElement.style.position = "relative";
					tempElement.style.left = (baseLeft + 1) + "px";
					tempElement.style.top = (baseTop + 1) + "px";
					tempElement.className = "dropshadowtext";
					tempElement.style.zIndex = "1";
					
					allTags[i].style.position = "relative";
					allTags[i].style.zIndex = "2";
					allTags[i].className = allTags[i].className + " shadowedprocessed";
					allTags[i].parentNode.insertBefore(tempElement, allTags[i]);
				}
			}
		}
	}		
}


//////////////////////////////////////////////////////////////////////////////////////////////////////


function setupPage()
{
	if(document.getElementById("maincontent").clientHeight > (document.getElementById("rightsidebar").clientHeight + 2))
	{
		document.getElementById("rightsidebar").style.height = document.getElementById("maincontent").clientHeight;
	}
	enhanceClasses();
}
	

//////////////////////////////////////////////////////////////////////////////////////////////////////


window.onload = setupPage;

