//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 -4 + '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 -4 + '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;
		var menu = document.getElementById("menu_table"); 
		var path = "http://www.seabrookwa.com/";		
		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 == "town") // sub_menu categories
			{
				sub_items = ["Master Plan","town_masterplan.asp","Art of Town Making","town_art.asp","Gallery","town_gallery.asp","What's with the Bikes?","town_bikes.asp"]
			}
			else if (section == "homesforsale") // sub_menu categories
			{
				sub_items = ["Search Homes","homes_search.asp","Architecture","homes_architecture.asp","Green Building","homes_greenbuilding.asp","Owning at Seabrook","homes_owning.asp"]
			}
			else if (section == "cottagerentals") // sub_menu categories
			{
				sub_items = ["*Reserve a Cottage","http://www.bellabeach.com/seabrookrentals"]
			}
			else if (section == "news") // sub_menu categories
			{
				sub_items = ["FAQs","news_faqs.asp","News Articles","news_articles.asp","Newsletter","news_newsletters.asp","Events Calendar","news_calendar.asp","Media Kit","news_mediakit.asp"]
			}	
			else if (section == "aboutus") // sub_menu categories
			{
				sub_items = ["Team","about_team.asp","Testimonials","about_testimonials.asp","Seabrook&nbsp;Foundation","about_foundation.asp","Employment","about_employment.asp"]
			}
			else if (section == "thearea") // sub_menu categories
			{
				sub_items = ["History","area_history.asp","Olympic&nbsp;National&nbsp;Park","area_olympic.asp","Attractions","area_attractions.asp","Activities","area_activities.asp","The Weather","area_weather.asp"]
			}
			else if (section == "contactus") // sub_menu categories
			{
				sub_items = ["Location Map","contact_map.asp","Contact Us Form","contact_form.asp"];
				// removed on 2/1/2007
				//,"Preferred&nbsp;Buyer&nbsp;Form","homes_preferredbuyer_form.asp"
			}
			else  //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';
				
				 if (sub_items[x].substring(0,1) == "*")//hyperlink
				 {
					
				   var temp = sub_items[x]
				   cell.innerHTML = "<a class='subnav' style='margin-left:10px;margin-right:5px;text-decoration:none;color:#714C1D' href=" + (sub_items[x+1]) + ">"+ temp.substring( 1 , temp.length )  +"</a>"; 
									
				 }
				 else
				 {			
					// create <a> 				
		    		cell.innerHTML = "<a class='subnav' style='margin-left:10px;margin-right:5px;text-decoration:none;color:#714C1D' href=" + (path+sub_items[x+1]) + ">"+ 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 = "#f0e7cd";
						link.style.color = "#714C1D";						
					}
					else if ( evnt.type == "mouseout" )
					{ 	
						cell.style.backgroundColor = "#F1EFE9";
						link.style.color = "#714C1D";
						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)
		{
			obj = obj.offsetParent;
			curtop += obj.offsetTop		
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
//**************************************************************
