function menudisplay(e)
{
        alert(e.tagName);
}

var ns = (navigator.appName.indexOf('Netscape') > -1);
var ie = (navigator.appName.indexOf('Microsoft Internet Explorer') > -1);
var ProgramMenuItems= new Array(
        ["Perl","http://imac-252a.stanford.edu/programs/Perl","Perl"],
	["Python","http://imac-252a.stanford.edu/programs/Python","Python"],
        ["VBScript","http://imac-252a.stanford.edu/programs/VBScript","VBScript"],
        ["AppleScript","http://imac-252a.stanford.edu/programs/AppleScripts","AppleScript"],
	["Matlab","http://imac-252a.stanford.edu/programs/Matlab","Matlab"],
	["IDL","http://imac-252a.stanford.edu/programs/IDL","IDL"],
	["C","http://imac-252a.stanford.edu/programs/C","C"],
	["JavaScript","http://imac-252a.stanford.edu/programs/JavaScript","JavaScript"]);

var PictureMenuItems= new Array(
	["Rae Lakes Loop","http://imac-252a.stanford.edu/pictures.html","Rae Lakes Loop"],
	["Ophelia's Bday","http://imac-252a.stanford.edu/Ophelia_Bday.html","Ophelia"],
	["Halloween","http://imac-252a.stanford.edu/Halloween.html","Halloween"],
	["Thanksgiving","http://imac-252a.stanford.edu/Thanksgiving_05.html","Thanksgiving"],
	["Chrsitmas","http://imac-252a.stanford.edu/Christmas_05.html","Christmas"],
        ["Science_Olympics","http://imac-252a.stanford.edu/Science_Olympics.html","Science Olympics"],
	["Manitoba_06","http://imac-252a.stanford.edu/pictures/Manitoba_06.html","Molson Lake 06"],
        ["Evolution_Valley_8_06","http://imac-252a.stanford.edu/pictures/Evolution_Valley_8_06.html","Evolution Valley"],
        ["Enchanted_Gorge_9_07","http://imac-252a.stanford.edu/pictures/EnchantedGorgeSep07Web.html","Enchanted Gorge"], 
	["Kitt_Peak_12_07","http://imac-252a.stanford.edu/pictures/KPNO_Photos.html","Kitt Peak"],
        ["PimaCanyone_6_08","http://imac-252a.stanford.edu/pictures/PimaCanyonTucsonAz_6_9_08.html", "Pima Canyon"],
        ["SequoiaMineralKing_Jul08", "http://imac-252a.stanford.edu/pictures/SequoiaMineralKing_Jul08/", "Mineral King"],
        ["IsleRoyal_Aug08", "http://imac-252a.stanford.edu/pictures/IsleRoyalAndEmma_8_08", "Isle Royal 08"], 
        ["AnzaBorrego_Dec08", "http://imac-252a.stanford.edu/pictures/AnzaBorrego_12_08", "Anza Borrego 08"],
        ["HappyIslesToTuolumne_Apr09", "http://imac-252a.stanford.edu/pictures/HappyIslesToTuolumne_4_09", "Yosemite 09"],
        ["HighSierraTrail_Sep09", "http://imac-252a.stanford.edu/pictures/HighSierraTrailPhotos_9_09", "Nine Lakes Basin"],
        ["GrandCanyonTuolomne_10_09", "http://imac-252a.stanford.edu/pictures/GrandCanyonTuolomne_10_09", "Grand Canyon Tuolomne"]);

function createMenu(menuName,menuItems)
{
        var divHTML= '<DIV ID="' +menuName + 'MenuDiv" CLASS="DivMenu"';
        divHTML = divHTML + 'onmouseout="return hideMenu(this, ' + menuName.length+',event)">';

        var tableHTML='<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1 ID="'+ menuName+ 'Table"><TBODY ID="'+ menuName + 'TableBody">';
        
        var tableRowHTML="";
        var rowCount;
        var totalNoRows=menuItems.length;

        for (rowCount=0; rowCount < totalNoRows; rowCount++)
        {
                tableRowHTML = tableRowHTML + '<TR ID="' + menuName+ menuItems[rowCount][0]+ 'TR"><TD ID="' +menuName+menuItems[rowCount][0];
                tableRowHTML=tableRowHTML+'" onclick="goPage(\''+menuItems[rowCount][1]+'\')"';
                tableRowHTML=tableRowHTML+'CLASS="TDMenu">' + menuItems[rowCount][2]+'</TD></TR>';
        }
        return divHTML + tableHTML + tableRowHTML + '</TBODY></TABLE></DIV>';
}

function showMenu(menuToShow,e,name)
{
        if (ns)
        {
                var srcElement=e.target;
        }
        else
        {
                var srcElement=event.srcElement;
        }
	if (name=='programs'){
           var tab=document.getElementById("program_tab");
        }
	else{
	   var tab=document.getElementById("picture_tab");
	}
	var xPos1=parseInt(tab.style.left);
        var yPos1=parseInt(tab.style.top);
        var xPos=parseInt(srcElement.style.left);
        var yPos=parseInt(srcElement.style.top);
        //alert(xPos1+" "+yPos1);       
        //This will display the position returned
        //alert(tab.tagName);
        menuToShow.style.left=xPos1;
        menuToShow.style.top=yPos1+20;
        return false;

}
function hideMenu(menuToHide, menuIDLength,e)
{
        var toElementID;
        if (ns)
        {
                var mouseLastIn=e.relatedTarget;
        }
        else
        {
                var mouseLastIn=event.toElement;
        }
        if (mouseLastIn != null)
        {
                if (mouseLastIn.nodeType == 3)
                {
                        mouseLastIn=mouseLastIn.parentNode;
                }
        toElementID=mouseLastIn.id;
        }
        else
        {
                return false;
        }

        if (typeof(toElementID) == "undefined")
        {
                toElementID="UNDEF";
        }
        toElementID=toElementID.substr(0,menuIDLength);
        var divMenuID=menuToHide.id;
        divMenuID=divMenuID.substr(0,menuIDLength);
        if (toElementID != divMenuID)
        {
                menuToHide.style.left= -200 + 'px';
                menuToHide.style.top= -1000 + 'px';
        }
}

function document_onmouseover(e)
{
        if (ns)
        {
                var srcElement=e.target;
        }
        else
        {
                var srcElement=event.srcElement;
        }

        if (srcElement.nodeType == 3)
        {
                srcElement=srcElement.parentNode;
        }
        
        if (srcElement.parentNode.id=="myTable")
        {
                srcElement.style.color="991100";
                srcElement.style.backgroundColor="FFFFFF";
        }
}
function document_onmouseout(e)
{
        if (ns)
        {
                var srcElement=e.target;
        }
        else
        {
                var srcElement=event.srcElement;
        }

        if (srcElement.nodeType == 3)
        {
                srcElement=srcElement.parentNode;

        }
        if (srcElement.parentNode.id == "myTable")
        {
                srcElement.style.color="FFFFFF";
                srcElement.style.backgroundColor="991100";
        }
        
}

function goPage(src)
{
        window.location.href=src;
}               


