////////////////////////////////////////////////////////////////////////////////
// ehrenburg.js
//

	window.onload = function()
	{
		init();	
	}
	function init()
	{
		// Menus
		initMenus();
		
		// Resize Content
		resizeContent();
	}
	
	var menus = new Array( "about", "why", "homes", "gallery", "contact" );
	var menuTimer;
	var curMenu = "";
	var animation = new Array();
	var mnuTween;
	function initMenus()
	{
		document.getElementById( "content" ).onclick = hideMenusAlt;
		
		for( var m = 0; m < menus.length; m++ )
		{
			var btnMenu = document.getElementById( "menu_" + menus[m] );
				btnMenu.onclick = function()
				{
					var parts = this.id.split( "_" );
					
					
					curMenu = parts[1];
					
					
					//if( curMenu != "" )
						hideMenusAlt();
					
					showMenu( parts[1] );
				}
				btnMenu.onmouseout = function()
				{
					//startHideMenus();
					//hideMenus();
				}
				btnMenu.style.cursor = "pointer";
			
			
			
			/*	
			var menu = document.getElementById( "mnu_" + menus[m] );
				menu.onmouseover = function()
				{
					//this.stopPropagation();
					var parts = this.id.split( "_" );
						curMenu = parts[1];
						
					stopHideMenus();	
				}
				menu.onmouseout = function()
				{
					//this.stopPropagation();
					startHideMenus();
				}
			
			var menu_children = menu.getElementsByTagName( "*" );
			for( var c = 0; c < menu_children.length; c++ )
			{
				menu_children[c].onmouseover = function()
				{
					curMenu = "";
					stopHideMenus();
				}
				menu_children[c].onmouseout = function()
				{
					curMenu = "";
					startHideMenus();
				}
				
				// Container
				if( menu_children[c].className == "mnu_items_container" )
					var mnu_dims = findDimensions( menu_children[c] );
					
				if( menu_children[c].className == "mnu_items_bkg" )
					menu_children[c].style.height = mnu_dims[1] + "px";
			}
			*/
		}
		
		var smenus = document.getElementsByTagName( "div" );
		for( var z = 0; z < smenus.length; z++ )
		if( smenus[z].className == "menu" )
		{
			//alert( smenus[z].id );
			smenus[z].onclick = hideMenusAlt;
			//smenus[z].onmouseover = stopHideMenus;
			smenus[z].style.cursor = "pointer";
		}
	}
	function hideMenusAlt( menu )
	{
		if( mnuTween != undefined )
			mnuTween.stop();
		
		for( var m = 0; m < menus.length; m++ )
		if( menus[m] != menu )
		{
			//if( curMenu != menus[m] )
				hideMenu( menus[m] );
			
		}
	}
	function showMenu( menu )
	{
			var mnu = document.getElementById( "mnu_"+ menu );
			var mnu_dims = findDimensions( mnu );
			var start_pos = (mnu_dims[1] * (-1));
				mnu.style.top = start_pos + "px";
				mnu.style.visibility = "visible";
				
				if( navigator.appName != "Microsoft Internet Explorer" )
				{
					mnu.style['opacity'] = 0.80;
					mnu.style['-moz-opacity'] = 0.80;
				}
				
			//var mnu_dims = findDimensions( mnu );
		
			animation.push( 1 );
				mnuTween = new Tween( mnu.style, "top", Tween.strongEaseOut, start_pos, 0, 1.00, "px" );
				mnuTween.start();
				mnuTween.onMotionFinished = function()
				{
					animation.pop();	
				}
	}
	function hideMenu( menu )
	{
		var mnu = document.getElementById( "mnu_"+ menu );
			//mnu.style.visibility = "visible";
		var mnu_pos = findPos( mnu );
		var mnu_dims = findDimensions( mnu );
		
		var start_pos = (mnu_dims[1] * (-1))
		
		//if( mnu_pos[1] == 0 )
		//{
			/*
			animation.push( 1 );
			var mnuTween = new Tween( mnu.style, "top", Tween.strongEaseOut, 0, start_pos, 1.25, "px" );
				mnuTween.start();
				mnuTween.onMotionFinished = function()
				{
					animation.pop();	
				}
				
			if( navigator.appName != "Microsoft Internet Explorer" )
			{
				animation.push( 1 );
				var mnuTween2 = new OpacityTween( mnu, Tween.regularEaseOut, 80, 0, 1.00 );
					mnuTween2.start();
					mnuTween2.onMotionFinished = function()
					{
						animation.pop();	
					}
			}
			*/
			mnu.style.top = start_pos + "px";
		//}
	}
	function hideMenus()
	{
		for( var m = 0; m < menus.length; m++ )
		{
			//if( curMenu != menus[m] )
				hideMenu( menus[m] );
		}
		//clearTimeout( menuTimer );
	}
	function startHideMenus()
	{
		menuTimer = setTimeout( "hideMenusAlt()", 5000 );
	}
	function stopHideMenus()
	{
		var ctr = 0;
		
		while( menuTimer != undefined && ctr++ < 10 )
			clearTimeout( menuTimer );
	}
	function resizeContent()
	{
		var minHeight = 400;
		var begHeight = 345;
		var content = document.getElementById( "content" );
		var conHeight = findDimensions( content );
			conHeight[1] += 90;
		
		if( conHeight[1] > (minHeight+begHeight) )
			document.getElementById( "bkgRedImg" ).style.height = (conHeight[1]-begHeight) + "px";
	}
	// -- Element Properties --------------------------------------------------
	function findPos( obj )
	{
		var curleft = 0;
		var curtop = 0;
		
		if( obj.offsetParent )
		{
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while( (obj = obj.offsetParent) )
			{
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		return [curleft,curtop];
	}
	function findPosRelativeParent( obj, parent )
	{
		var curleft = 0;
		var curtop = 0;
		
		if( obj.offsetParent )
		{
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while( (obj = obj.offsetParent) && obj != parent )
			{
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		return [curleft,curtop];
	}
	function findDimensions( obj )
	{
		var width = obj.offsetWidth;
		var height = obj.offsetHeight;
		
		return [width,height];
	}
	function findWindowDimensions()
	{
		var width = document.documentElement.clientWidth;
		var height = document.documentElement.clientHeight
		
		return [width,height];
	}
	function findZIndex( obj )
	{
		var zIndex = 0;
		var cStyle;
		
		if( obj.currentStyle )
			cStyle = obj.currentStyle;
		else if( document.defaultView && document.defaultView.getComputedStyle )
			cStyle = document.defaultView.getComputedStyle( obj, "" );
		
		if( cStyle != undefined )
			zIndex = cStyle.zIndex;
		else
			zIndex = obj.style.zIndex;
		
		return zIndex;
	}
	function findScrollXY()
	{
		var scrOfX = 0, scrOfY = 0;
		if( typeof( window.pageYOffset ) == "number" )
		{
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		}
		else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
		{
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		}
		else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
		{
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}
		
		return [scrOfX,scrOfY];
	}
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	function selectAllSelect( obj, id )
	{
		var elem = document.getElementById( id );
		for( var i = 0; i < elem.options.length; i++ )
			elem.options[i].selected = obj.selected;
	}
	// -----------------------------------------------------------------------------

//
//
////////////////////////////////////////////////////////////////////////////////