/*
	Settings (default)
*/
var bgcolorMenuNormal = '#ccc';
var bgcolorMenuSelected = '#aaa';

/* ============================================== *\
	Menu show/hide
	
	version:	1.1
	copyright:	(C) 2005-2006 Maciej Jaros
	license:	GNU General Public License v2,
				http://opensource.org/licenses/gpl-license.php
\* ============================================== */

/* ===================================================== *\
	Show menu element

	Params
	------
	 element_id - this is the prefix given in the id of some
		of some block (like thingy in <div id="thingy_links">)
	
		sufix is added automatically
			_content - all menu elements holder
			_title	- for the title element that is normally visible
			_links	- for the links element that is to be shown
					  (for link only use _title)
\* ===================================================== */
function showMenuEl(element_id)
{
	//setOpacity(element_id, 80)
	var objTitle = document.getElementById(element_id+'_content');
	var objLinks = document.getElementById(element_id+'_links');
	if (objLinks)
	{
		var documentWidth;
		var elementWidth;
		var objDocumentElem = document.documentElement;
		if (!objDocumentElem)
		{
			objDocumentElem = document.body;
		}
		documentWidth = objDocumentElem.clientWidth + objDocumentElem.scrollLeft;
		//documentWidth = findPosX(objTitle) +  objTitle.offsetWidth;
		// trzeba go pokazać, żeby miał wymiary
		objLinks.style.display = 'block';
		elementWidth = objLinks.offsetWidth;
		
		if (findPosX(objLinks)+elementWidth > documentWidth)
		{
			// What does (2) mean? Idaknow, but it works :).
			// rest is understandable for right align
			objLinks.style.left = (2 + findPosX(objLinks) 
				+ objTitle.offsetWidth - elementWidth) + 'px';
		}
// 		dbgJS('X');
	}
	objTitle.style.backgroundColor = bgcolorMenuSelected;
}

/* ===================================================== *\
	Hide menu element

	Params
	------
	 see above
\* ===================================================== */
function hideMenuEl(element_id)
{
	//fadeOut(element_id, 80);
	var objLinks = document.getElementById(element_id+'_links')
	var objTitle = document.getElementById(element_id+'_content')
	if (objLinks)
	{
		objLinks.style.display = 'none';
		objLinks.style.left = 'auto';		// if window is resized then maybe 
											// the correction is not needed any more
	}
	objTitle.style.backgroundColor = bgcolorMenuNormal;
}


/* ===================================================== *\
	Fade In / Out
	
	From 0 to max (ranges form 0 to 100)

	Params
	------
	 element_id - this is the name given in the id of some
		of some block (like <div id="thingy">)
\* ===================================================== */
function fadeIn(element_id, max)
{
	var obj_style;
	obj_style = document.getElementById(element_id).style;
	
	for (var i=0;i<max;i+=10)
		setTimeout('setOpacity('+i+')',50)
	;
	return false;
}
/* ===================================================== *\
\* ===================================================== */
function fadeOut(element_id, max)
{
	//var obj_style;
	//obj_style = document.getElementById(element_id).style;
	
	for (var i=max;i>=0;i-=1)
		setTimeout('setOpacity(\''+element_id+'\', '+i+')',50)
	;
	return false;
}
/* ===================================================== *\
\* ===================================================== */
function setOpacity(element_id, value)
{
	var obj_style;
	obj_style = document.getElementById(element_id).style;

	obj_style.opacity = value/100;						// mozilla
	obj_style.filter = 'alpha(opacity=' + value + ')';	// exploder
}

/* ===================================================== *\
	Finding Left X position 
	
	Extra function from:
	http://www.quirksmode.org/js/findpos.html
	
	Params
	------
		obj - object of which you want to find
			the position of
\* ===================================================== */
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;
}
