var unfolded	= false;
var busy		= false;

function togglemenu( menuItemID )
{
	if ( busy )
	{
		return
	}
	else
	{
		busy = true;	
	}
	
	if ( unfolded && ( document.getElementById( menuItemID ) != unfolded ) )
	{
		fold( unfolded );
		
		check( menuItemID );
	}
	else
	{
		toggle( menuItemID );
	}
}

function toggle(menuItemID)
{
	var menuitem	= document.getElementById( menuItemID );
	var elements	= menuitem.getElementsByTagName("DIV");
	var length		= elements.length;
	var height		= 0;
	
	for ( var x = 0; x < length; x++ )
	{
		height += elements[x].offsetHeight;
	}
	
	var CSSHeight = menuitem.style.height;
	CSSHeight = parseInt( CSSHeight.substr( 0, CSSHeight.length - 2 ) );

	if (CSSHeight > 20 )
	{
		//alert ( "fold" );
		//alert ( menuitem.style.height );
		//alert ( menuitem.offsetHeight );
		fold( menuitem );
	}
	else
	{
		//alert ( "unfold" );
		menuitem.style.height = "15px";
		unfolded = menuitem;
		unfold( menuitem, height );
	}
}

function unfold( menuitem, height )
{
	var CSSHeight = menuitem.style.height;
	CSSHeight = parseInt( CSSHeight.substr( 0, CSSHeight.length - 2 ) );
	
	if ( CSSHeight < height )
	{
		menuitem.style.height = ( CSSHeight + 10 ) + "px";
		setTimeout(function(){unfold( menuitem, height )}, 20);
	}
	else
	{
		menuitem.style.height = height + "px";
		busy		= false;
	}
}


function fold( menuitem )
{
	var CSSHeight = menuitem.style.height;
	CSSHeight = parseInt( CSSHeight.substr( 0, CSSHeight.length - 2 ) );
	
	if ( CSSHeight > 15 )
	{
		menuitem.style.height = ( CSSHeight - 10) + "px";
		setTimeout(function(){fold( menuitem )}, 20);
	}
	else
	{
		menuitem.style.height = "15px";
		busy		= false;
		unfolded	= false;
	}
}

function check(menuItemID)
{
	if (busy)
	{
		setTimeout(function(){check(menuItemID)}, 10);
	}
	else
	{
		toggle(menuItemID);
	}
}


var opc = 0;

function showHeader(strUrl)
{
	bgObj = document.getElementById('backgroundimage');

	if ( bgObj.src == "" )
	{
		if(strUrl == "")
		{
			images	= ["001-hawedo-headers.jpg", "002-hawedo-headers.jpg", "003-hawedo-headers.jpg", "004-hawedo-headers.jpg", "005-hawedo-headers.jpg", "006-hawedo-headers.jpg", "007-hawedo-headers.jpg", "008-hawedo-headers.jpg", "009-hawedo-headers.jpg", "010-hawedo-headers.jpg", "011-hawedo-headers.jpg"];
			randomi	= Math.floor(Math.random() * images.length);
			bgObj.src = "/images/" + images[randomi];
		}
		else
		{
			bgObj.src = strUrl;
		}
		
	}
	
	loadCheck( bgObj );
}

function loadCheck( bgObj )
{
	if ( bgObj.complete == false )
	{
		setTimeout(function(){loadCheck(bgObj)}, 20);	
	}
	else
	{
		bgObj.style.opacity			= "0";
		bgObj.style.MozOpacity		= "0";
		bgObj.style.KhtmlOpacity	= "0";
		bgObj.style.filter			= "alpha(opacity=0)";
		bgObj.style.visibility		= "visible";
		
		fadeIn( bgObj );
	}
}

function fadeIn(id1)
{
	if ( opc < 100 )
	{
		opc += 5;
		changeOpacity(id1);
		setTimeout(function(){fadeIn(id1)}, 20);
	}
}
	
function changeOpacity(obj)
{
	if (opc == 0)
	{
		opacity = 0;
	}
	else
	{
		opacity = opc / 100;
	}

	obj.style.opacity		= opacity;
	obj.style.MozOpacity	= opacity;
	obj.style.KhtmlOpacity	= opacity;
	obj.style.filter		= "alpha(opacity=" + opc + ")";
}
