//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';
			
			var yAdjustment = 15;
		
			if( ie && navigator.appVersion.indexOf('MSIE 8.0;') != -1 ) {
				yAdjustment = 0;
			}
			
			parent_left_y = findPosY(parent_control) + yAdjustment + height_of_link + '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.widmer.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 == "widmerstory") // sub_menu categories
			{
				sub_items = ["The Brothers","brothers.aspx",0,"FAQs","faq.aspx",0,"Investor Relations","http://phx.corporate-ir.net/phoenix.zhtml?c=95666&p=irol-IRHome",1];
			}
			else if (section == "beers") //sub_menu categories
			{
				sub_items = ["Widmer Hefeweizen","beer_hefeweizen.aspx",0,"Drifter Pale Ale","beer_drifter.aspx",0,"Broken Halo IPA", "beer_brokenhalo.aspx",0,"Drop Top Amber Ale","beer_droptop.aspx",0,"Deadlift Imperial IPA","beer_deadlift.aspx",0,"&nbsp;&nbsp;&nbsp;Seasonals","#",0,"&nbsp;&nbsp;&nbsp;W\'10","beer_w_series.aspx",0,"&nbsp;&nbsp;&nbsp;Sunburn Summer Brew","beer_sunburn.aspx",0,"&nbsp;&nbsp;&nbsp;Okto","beer_okto.aspx",0,"&nbsp;&nbsp;&nbsp;Brrr","beer_brrr.aspx",0,"Brothers\' Reserve","beer_brothersreserve.aspx",0,"Find Widmer","distributors.aspx",0];
			}
			else if (section == "brewery") //sub_menu categories
			{
				sub_items = ["Scheduled Tours","scheduled_tour.aspx",0,"Virtual Brewery Tour","virtual_tour.aspx",0,"News","news.aspx",0,"Events","events.aspx",0,"Jobs","http://www.craftbrewers.com/Careers.aspx",1,"Kegs & Supplies","kegs_supplies.aspx",0,"Map To Brewery","map.aspx",0,"Portland Favorites","portland_favorites.aspx",0,"Brother Nature","environment.aspx","0", "Contact Widmer","contact.aspx","0", "Sponsorship Request","sponsorship.aspx",0];
			}
			else if (section == "happyhour") //sub_menu categories
			{
				sub_items = ["Beer Goggles","beergoggles.aspx",0,"Send A Prost Card","prost.aspx",0,"Widmer Wallpaper","wallpaper.aspx",0,"Games","games/default.aspx",0,"Widmedia Room","widmedia_room.aspx",0,"Lemon Your Widmer","http://www.lemonyourwidmer.com",1];
			}
			else if (section == "gasthauspub") //sub_menu categories
			{
				sub_items = ["What\'s On Tap","whats_on_tap.aspx",0,"Come To The Pub","map_gasthaus.aspx",0, "Lunch Menu", "menu_lunch.aspx",0, "Dinner Menu","menu_dinner.aspx",0,"Gasthaus Banquet Rooms","host_event.aspx",0,"Recipes","recipes.aspx",0,"Contact Widmer Gasthaus","contact_gasthaus.aspx",0];
			}
			else
			{
				sub_items = [];			
			}
												
			for (var x = 0 ; x < sub_items.length ; x+=3)
			{
				var row = menu.insertRow(x/3);//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';
			    	if (sub_items[x+2] == 0){
					cell.innerHTML = "<a style='margin-left:10px;margin-right:5px;text-decoration:none;color:#E1D198' href=" + (path+sub_items[x+1]) + ">"+ sub_items[x] +"</a>"; 
				} else {

				cell.innerHTML = "<a style='margin-left:10px;margin-right:5px;text-decoration:none;color:#E1D198' href=" + (sub_items[x+1]) + " target = _blank>"+ 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 = "#502F11";
					link.style.color = "#FFE94A";		
					
					//changeOpacity(menu, 80)
					
				}
				else if ( evnt.type == "mouseout" )
				{ 	
					cell.style.backgroundColor = "#000000";
					link.style.color = "#E1D198";
					
					window.status = "";	
					document.body.style.cursor = "";	
										
					//changeOpacity(menu, 70)				
				}
			}			
		}
		
		
	}
	
var opacity = (!ns) ? "filter" : "opacity";

function changeOpacity(node, percent)
{
	percent = (!ns) ? "alpha(opacity=" + percent + ")" : percent/100;
	node.style[opacity] = percent;
}

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;
}
//**************************************************************