//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 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;
			
			parent_left_x = findPosX(calling_control) + 'px';
			parent_left_y = findPosY(parent_control) + height_of_link  + 'px';
		}
		else
		{		
			callingControlID = evnt.srcElement.id;		
			calling_control = document.getElementById(callingControlID);
			parent_control = document.getElementById(callingControlID).offsetParent;
			height_of_link = evnt.srcElement.offsetHeight;
			
			parent_left_x = findPosX(calling_control)+ 'px';
			parent_left_y = findPosY(parent_control) + height_of_link + 'px';
		}


		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';
		}
		
	}
	
	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.substring(0,4); //4 char code representing parent menu
		var id = sectionID.substring(4,sectionID.length); //# representing current item
		var menu = document.getElementById("menu_table"); 
		var ob_path = "http://www.oliviabeach.com/";
		//var ob_path = "http://localhost/olivia_beach/";
		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 == "neig") // sub_menu categories
			{
				sub_items = ["Neighborhood Map", "our_neighborhood.asp", "Photo Gallery", "photo_gallery.asp","Directions", "directions.asp", "Area Links","area_links.asp"];
			}
			else if (section == "home") //sub_menu categories
			{
				sub_items = ["Map of Homes", "homes.asp" , "Home Listings", "home_listings.asp"]
			}
			else if (section == "rent") //sub_menu categories
			{
				sub_items = []
			}
			else if (section == "team") //sub_menu categories
			{
				sub_items = ["The Team", "team.asp", "Financing Partners", "financing_partners.asp", "Testimonials", "testimonials.asp"]
			}
			else if (section == "news") //sub_menu categories
			{
				sub_items = ["Olivia Beach News", "news.asp","FAQs", "faqs.asp","Media Kit", "mediakit.asp"]
			}
			else if (section == "cont") //sub_menu categories
			{
				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
				cell.className = 'dropdown';
			
				// create <a> 				
		    	cell.innerHTML = "<a  style='margin-left:10px;margin-right:5px;text-decoration:none;color:#666666'  href=" + (ob_path+sub_items[x+1]+id) + ">"+ sub_items[x] +"</a>"; 
			
    		}
			
			//alert(menu.innerHTML)
	}	
	
	function rollover_effect(evnt)
	{
		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';
		}			

			if ( link != null )
			{
				if ( link.href != null ) 
				{	
					if( evnt.type == "mouseover" && !sourceIsTable  )
					{ 
						cell.style.backgroundColor = "#E6F8FF";
						link.style.color = "#0066cc";						
					}
					else if ( evnt.type == "mouseout" )
					{ 	
						cell.style.backgroundColor = "#FFFFFF";
						link.style.color = "#666666";
						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)
		{		
			if ( obj.offsetParent.tagName == "BODY" )
			{
				obj = obj.offsetParent;
			}
			else
			{
				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)
		{
		
			if ( obj.offsetParent.tagName == "BODY" )
			{
				obj = obj.offsetParent;
			}
			else
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
*/
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)
		{
			obj = obj.offsetParent;
			curtop += obj.offsetTop		
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
//**************************************************************
