//version 1.0; created 2/2005

var ns = (navigator.appName.indexOf('Netscape')>-1);
var ie = (navigator.appName.indexOf('Microsoft Internet Explorer')>-1);
				
	function open_action_menu(evnt)
	{	
	    var callingControlID;
	    var calling_control;
		var parent_control;
		var height_of_link;
		var width_of_link;
		var parent_left_x;
		var parent_left_y;
		
		if ( ns )
		{		
			callingControlID = evnt.target.id;
			calling_control = document.getElementById(callingControlID);
			parent_control = document.getElementById(callingControlID).offsetParent;
			height_of_link = evnt.target.offsetHeight;
			width_of_link = evnt.target.offsetWidth;
			
			parent_left_x = findPosX(calling_control) +  ( width_of_link * .58 ) + 'px';
			parent_left_y = findPosY(parent_control) + 'px';
		}
		else
		{		
			callingControlID = evnt.srcElement.id;		
			calling_control = document.getElementById(callingControlID);
			parent_control = document.getElementById(callingControlID).offsetParent;
			height_of_link = evnt.srcElement.offsetHeight;
			width_of_link = evnt.srcElement.offsetWidth;
			
			parent_left_x = findPosX(calling_control) + ( width_of_link * .58 ) + 'px';
			parent_left_y = findPosY(parent_control) + 'px';
		}
		
		
		var menu = document.getElementById("menu_table"); 
		if ( menu != null )
		{
			create_links(callingControlID)
			
			if (document.getElementById("menuDiv").style.visibility == 'hidden')
			{
		
				document.getElementById("menuDiv").style.left = parent_left_x; 
				document.getElementById("menuDiv").style.top = parent_left_y;
			
				document.getElementById("menuDiv").style.visibility = 'visible';
			}
		
		}
		else
		{

		}
		
	}
	
	
	function close_action_menu(evnt)
	{
		var menu_cont = document.getElementById("menuDiv");
		
		if(menu_cont.style.visibility == 'visible')
		{
			menu_cont.style.visibility = 'hidden';
		}	
		
		document.body.style.cursor = "";
	}	
		
	function browse_action_menu()
	{
		var menu_cont = document.getElementById("menuDiv");
		menu_cont.style.visibility = 'visible';
	}
	
	function create_links(sectionID)
	{	

		var section = sectionID;
		var menu = document.getElementById("menu_table"); 
		var path = "http://www.powellvalley.net/";
		var sub_items;				
		var rows = menu.rows.length;
			
			//delete all rows in table, so we can start a new sub_menu
			if (rows >= 1)
			{	
				for(var x = 1 ; x <= rows ; x ++)
				{	
					menu.deleteRow(rows - x);
				}
			}
			
			/*rules for sub_items ..  
			  The element at the even position must be the <a> inner text while the element at the odd position 
			  will be the actual link			
			*/

			if (section == "services") // sub_menu categories
			{
				sub_items = ["Assisted Living Services","services_assisted.asp","Memory Care Services","services_memory.asp"];
			}
			else if (section == "amenities") // sub_menu categories
			{
				sub_items = ["Assisted Living Amenities","amenities_assisted.asp","Memory Care Amenities","amenities_memory.asp"];
			}
			else
			{
				sub_items = [];			
			}
												
			for (var x = 0 ; x < sub_items.length ; x+=2)
			{
				var row = menu.insertRow(x/2);//insert row at next position avail
												
				var cell = row.insertCell(0);//insert cell at position 0
				
				if( sub_items[x+1] == "#" ) //we are looking at a heading
				{
					cell.className = 'bodytext';
					cell.innerHTML = "<div style=';margin-left:10px;margin-right:5px;'>" + sub_items[x] + "</div>"
				}
				else //we are looking at a link
				{
					cell.className = 'dropdown';
			    	cell.innerHTML = "<a style='margin-left:10px;margin-right:5px;text-decoration:none;color:#FFFFFF' href=" + (path+sub_items[x+1]) + ">"+ sub_items[x] +"</a>"; 
				}
				
				
    		}
			
	}	
	
	function rollover_effect(evnt)
	{
		//ensure that the menu is visible, ie bug can allow menu to lose visibility
		var menu_cont = document.getElementById("menuDiv");
		menu_cont.style.visibility = 'visible';
	
		var cell;
		var link; 
		var sourceIsTable = false;
			
		if ( ns ) //user is using Netscape
		{		
			if ( evnt.target.tagName == "TABLE" )//<table> is the element producing the event
			{
				sourceIsTable = true;
			}
			else if ( evnt.target.tagName == "TD" ) //<td> is the element producing the event
			{
				cell = evnt.target;
				link = evnt.target.firstChild;
				window.status = link.href;
			}	
			else //<a> is the elemnt producing the event
			{
				cell = evnt.target.parentNode;
				link = evnt.target;	
			}
			document.body.style.cursor = 'pointer';
		}
		else //user is using ie
		{			
			if ( evnt.srcElement.tagName == "TABLE" )//<table> is the element producing the event
			{
				sourceIsTable = true;	
			}
			else if ( evnt.srcElement.tagName == "TD" ) //<td> is the element producing the event
			{
				cell = evnt.srcElement;
				link = evnt.srcElement.firstChild;
				window.status = link.href;
			}	
			else //<a> is the elemnt producing the event
			{
				cell = evnt.srcElement.parentNode;
				link = evnt.srcElement;	
			}	
			//document.body.style.cursor = 'hand';
		}			
		
		var menu = document.getElementById("menuDiv"); 

		if ( link != null )
		{
			if ( link.href != null ) 
			{	
				if( evnt.type == "mouseover" && !sourceIsTable  )
				{ 				
					cell.style.backgroundColor = "#879877";
					link.style.color = "#FFFFFF";	
				}
				else if ( evnt.type == "mouseout" )
				{ 	
					cell.style.backgroundColor = "#9BAC8A";
					link.style.color = "#FFFFFF";
					
					window.status = "";	
					document.body.style.cursor = "";		
				}
			}			
		}
		
		
	}

function process_cell_click(evnt)
{
	var url;
	var calling_link;
	
	if ( ns )
	{	
		calling_link = evnt.target.firstChild;
	}
	else
	{
		calling_link = evnt.srcElement.firstChild;
	}
	
	if ( calling_link != null )
	{
		if (  calling_link.href != null ) 
		{
			if ( calling_link.href == "javascript:void(0)" ) //processing javascript function
			{	
				calling_link.click();
			}
			else //processing normal href
			{	
				location.href = calling_link;
			} 
		}
	}	
}

//found at http://www.quirksmode.org/js/ *********************
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;
		
			
				//alert(obj.tagName + ' - ' + obj.offsetTop + ' ' + obj.id + ' - ' + curtop )

		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
//**************************************************************