// JavaScript Document

function getWinHeight()
{
	var winH = 460;
	
	if (parseInt(navigator.appVersion)>3) 
	{
		if (navigator.appName=="Netscape") 
		{
			winH = window.innerHeight;
		}
		if (window.navigator.appName.indexOf("Microsoft")!=-1) 
		{
			winH = document.body.offsetHeight;
		}
	}
	//alert('Window height is '+winH);
	return winH;
}

function getBackgroundColor(elem)
{
	var backgroundColor = '#FFFFFF';
	
	if (parseInt(navigator.appVersion)>3) 
	{
		if (navigator.appName=="Netscape") 
		{
			// DO NOTHING BECAUSE MACs don't like to play ball!
			//backgroundColor = getStyle(elem);
			//alert(backgroundColor);
		}
		if (window.navigator.appName.indexOf("Microsoft")!=-1) 
		{
			backgroundColor = elem.currentStyle.backgroundColor;
		}
	}
	//alert('Window height is '+winH);
	return backgroundColor;
}

function getElementHeight(Elem) 
{
	var elem = document.getElementById(Elem);
	//xPos = elem.style.pixelHeight;
	xPos = elem.offsetHeight;

	return xPos;
}



function collapseAllPanels()
{
	//document.getElementById('pageContentDiv').setAttribute('class', 'hiddenPanel');  // Mozilla version
	//document.getElementById('pageContentDiv').setAttribute('className', 'hiddenPanel'); // IE version
	
	for(i=1; i<17; i++)
	{
		document.getElementById(i).setAttribute('class', 'hiddenPanel');  
		document.getElementById(i).setAttribute('className', 'hiddenPanel');
	}
	
	document.getElementById('X1').setAttribute('class', 'hiddenPanel');  
	document.getElementById('X1').setAttribute('className', 'hiddenPanel');
}


function findPos(obj) 
{
	//obj = document.getElementById(obj);
	var curleft = curtop = 0;
	
	//If the browser supports offsetParent we proceed.
	if (obj.offsetParent) 
	{
		//Every time we find a new object, we add its offsetLeft and offsetTop to curleft and curtop.
		do 
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	//alert('Panel top is' + curtop);
	return curtop;
}


function expandPanel(panel,sender)
{
	
	// Collapse all
	collapseAllPanels();
	
	document.getElementById(panel).setAttribute('class', 'menuPaddle');  // Mozilla version
	document.getElementById(panel).setAttribute('className', 'menuPaddle'); // IE version
	
	// Set color of the panel to match the sender's
	var desiredColor = getBackgroundColor(sender);
	document.getElementById(panel).style.borderLeft = '6px solid '+desiredColor; // For the benefit of IE

	
	// Position panel according to mouse position
    document.getElementById(panel).style.top = findPos(sender);
	document.getElementById(panel).setAttribute('style', 'top: '+findPos(sender)+'px');
	
	
	// If the bottom of the panel is breaching the bottom of the screen place the panel just above the lowest point
	var heightOfPanel = getElementHeight(panel);
	//alert('Height of panel is '+heightOfPanel);
	// Height Of Screen
	var bottomOfPanel = heightOfPanel + findPos(sender);
	if ( bottomOfPanel > getWinHeight() )
	{
		//alert('Bottom of panel has brached the screen');
		var maxVisiblePos = getWinHeight() - heightOfPanel;
		if (maxVisiblePos <= 0)
			maxVisiblePos = 0;
		document.getElementById(panel).style.top = maxVisiblePos;
		document.getElementById(panel).setAttribute('style', 'top: '+maxVisiblePos+'px');
	}
	

}

function returnToPageContent()
{
	collapseAllPanels();
}
