var ns = (navigator.appName.indexOf('Netscape')>-1);
var ie = (navigator.appName.indexOf('Microsoft Internet Explorer')>-1);
var path = "http://www.bransontracks.com/";

	function open_action_menu(evnt, parentID) {
	    
	    var x, y;
	    var p;
	    p = document.getElementById(parentID);
	    
	    if( ns ) {
	        x = findPosX(p) + 13;
	        y = findPosY(p) + 26;
	    } else {
	        x = findPosX(p) + 13;
	        y = findPosY(p)  + 26;
	    }

	    create_links(parentID)
	    
	    var menu = document.getElementById("menuDiv")
	    
	    if (menu.style.visibility == 'hidden')
		{
			menu.style.left = x + 'px'; 
			menu.style.top = y + 'px';
		
			menu.style.visibility = 'visible';
			var n = document.getElementById('nav_rides');
            if( n ) {
                n.src = path + 'images/tnav_ridesnmore_on1.gif'
            }     
		}
	
	}
	
	function close_action_menu(evnt)
	{
		var menu = document.getElementById("menuDiv");
		
		if(menu.style.visibility == 'visible')
		{
			menu.style.visibility = 'hidden';
			var n = document.getElementById('nav_rides');
            if( n ) {
                n.src = path +  'images/tnav_ridesnmore_off1.gif'
            }     
			
		}	
	}	
		
	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 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 == "nav_rides") // sub_menu categories
			{
				sub_items = ['blank.gif','', 'tnav_gforce.gif','gforce.asp','tnav_bumperrides.gif','bumper_rides.asp', 'tnav_kidsrides.gif','kids_rides.asp', 'tnav_arcades.gif', 'arcade.asp', 'tnav_eatstreats.gif', 'eats_treats.asp'];
			}
												
			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 href=" + path + sub_items[x+1]  + "><img src="  + path + 'images/'  + sub_items[x] + " style='border:none;'/></a>"
    		}
    		
    		
    		var _brow = menu.insertRow(menu.rows.length)
    		var _cell = _brow.insertCell(0);
    		_cell.className = 'dropdown';
    		_cell.innerHTML = "<img src='" + path + "images/tnav_sub_bottom.gif' />"
    		    		
	}	
	
	function rollover_effect(evnt)
	{
		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
			{
				link = evnt.target.firstChild;
				window.status = link.href;
			}	
			else //<a> is the elemnt producing the event
			{
				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
			{
				link = evnt.srcElement.firstChild;
				window.status = link.href;
			}	
			else //<a> is the elemnt producing the event
			{
				link = evnt.srcElement;	
			}	
			//document.body.style.cursor = 'hand';
		}			
            var n = document.getElementById('nav_rides');
			if ( link != null )
			{

			    if( link.src.indexOf( 'images/tnav_sub_bottom.gif') > 0) {			    
			     if( n ) {
                        n.src = path +  'images/tnav_ridesnmore_on1.gif'
                    }     
			        return 
			    }
			    
				if( evnt.type == "mouseover" && !sourceIsTable  )
				{ 
					if( link.src.indexOf('_on') == -1 ) 
					{						
					    link.src = link.src.substring(0,link.src.indexOf('.gif')) + '_on.gif';
					}								          
        		    if( n ) {
                        n.src = path +  'images/tnav_ridesnmore_on1.gif'
                    }     
				}
				else if ( evnt.type == "mouseout" )
				{ 							
					if( link.src.indexOf('_on') >= 0 ) 
					{
					    link.src = link.src.substring(0,link.src.indexOf('_on')) + '.gif';
					}		
					
					
                    if( n ) {
                        n.src = path +  'images/tnav_ridesnmore_off1.gif'
                    }     
                    
					window.status = "";	
					document.body.style.cursor = "";	
				} else {
				
				}
						
			}
	}

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 ) 
		{
		    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;
}
//**************************************************************
