// context menu data objectsvar cMenu = new Object();cMenu["lookup1"] = {menuID:"contextMenu1", hrefs:["http://www.m-w.com/cgi-bin/dictionary?book=Dictionary&va=sesquipedalian","http://www.m-w.com/cgi-bin/dictionary?book=Thesaurus&va=sesquipedalian"]};cMenu["lookup2"] = {menuID:"contextMenu2", hrefs:["http://www.wyomingtourism.org/","http://www.pbs.org/weta/thewest/places/states/wyoming/","http://cnn.looksmart.com/r_search?l&izch&pin=020821x36b42f8a561537f36a1&qc=&col=cnni&qm=0&st=1&nh=10&rf=1&venue=all&keyword=&qp=&search=0&key=wyoming","http://google.com","http://search.yahoo.com"]};cMenu["lookup3"] = {menuID:"contextMenu3", hrefs:["http://www.wyomingtourism.org/","http://www.pbs.org/weta/thewest/places/states/wyoming/","http://cnn.looksmart.com/r_search?l&izch&pin=020821x36b42f8a561537f36a1&qc=&col=cnni&qm=0&st=1&nh=10&rf=1&venue=all&keyword=&qp=&search=0&key=wyoming","http://google.com","http://search.yahoo.com"]};cMenu["lookup4"] = {menuID:"contextMenu4", hrefs:["http://www.wyomingtourism.org/","http://www.pbs.org/weta/thewest/places/states/wyoming/","http://cnn.looksmart.com/r_search?l&izch&pin=020821x36b42f8a561537f36a1&qc=&col=cnni&qm=0&st=1&nh=10&rf=1&venue=all&keyword=&qp=&search=0&key=wyoming","http://google.com","http://search.yahoo.com"]};cMenu["lookup5"] = {menuID:"contextMenu5", hrefs:["http://www.wyomingtourism.org/","http://www.pbs.org/weta/thewest/places/states/wyoming/","http://cnn.looksmart.com/r_search?l&izch&pin=020821x36b42f8a561537f36a1&qc=&col=cnni&qm=0&st=1&nh=10&rf=1&venue=all&keyword=&qp=&search=0&key=wyoming","http://google.com","http://search.yahoo.com"]};cMenu["lookup6"] = {menuID:"contextMenu6", hrefs:["http://www.wyomingtourism.org/","http://www.pbs.org/weta/thewest/places/states/wyoming/","http://cnn.looksmart.com/r_search?l&izch&pin=020821x36b42f8a561537f36a1&qc=&col=cnni&qm=0&st=1&nh=10&rf=1&venue=all&keyword=&qp=&search=0&key=wyoming","http://google.com","http://search.yahoo.com"]};// position and display context menufunction showContextMenu(evt) {    // hide any existing menu just in case    hideContextMenus();    evt = (evt) ? evt : ((event) ? event : null);    if (evt) {        var elem = (evt.target) ? evt.target : evt.srcElement;         if (elem.nodeType == 3) {            elem = elem.parentNode;        }        if (elem.className == "contextEntry") {            var menu = document.getElementById(cMenu[elem.id].menuID);            // turn on IE mouse capture            if (menu.setCapture) {                menu.setCapture();            }            // position menu at mouse event location            var left, top;            if (evt.pageX) {                left = evt.pageX;                top = evt.pageY;            } else if (evt.offsetX || evt.offsetY) {                left = evt.offsetX;                top = evt.offsetY;            } else if (evt.clientX) {                left = evt.clientX;                top = evt.clientY;            }			//Get the source of the event (lookup1, lookup2, etc)			//This will update the leftPos offset			//var topMenu = document.getElementById("lookup1");			/*			else if (window.event && window.event.srcElement)    alert(window.event.srcElement + ': ' + window.event.srcElement.tagName + ': ' + window.event.srcElement.id);IE version of getting this stupid event!!????? This is all thats needed... Firefox is fine, IE dies*/			var topMenu;			if (evt.target.id != null)				topMenu = document.getElementById(evt.target.id);			else if (window.event && window.event.srcElement)				topMenu = document.getElementById(window.event.srcElement.id);						var toolBar = document.getElementById("product_toolbar");			var leftPos = toolBar.style.left + topMenu.offsetLeft;			            menu.style.left = leftPos + "px";            //menu.style.top = top + "px";			menu.style.top = "15px";			            menu.style.visibility = "visible";            if (evt.preventDefault) {                evt.preventDefault();            }            evt.returnValue = false;        }    }}// retrieve URL from cMenu object related to chosen itemfunction getHref(tdElem) {    var div = tdElem.parentNode.parentNode.parentNode.parentNode;    var index = tdElem.parentNode.rowIndex;    for (var i in cMenu) {        if (cMenu[i].menuID == div.id) {            return cMenu[i].hrefs[index];            }    }    return "";}// navigate to chosen menu itemfunction execMenu(evt) {    evt = (evt) ? evt : ((event) ? event : null);    if (evt) {        var elem = (evt.target) ? evt.target : evt.srcElement;        if (elem.nodeType == 3) {            elem = elem.parentNode;        }        if (elem.className == "menuItemOn") {            location.href = getHref(elem);        }        hideContextMenus();    }}// hide all context menusfunction hideContextMenus() {    if (document.releaseCapture) {        // turn off IE mouse event capture        document.releaseCapture();    }    for (var i in cMenu) {        var div = document.getElementById(cMenu[i].menuID)        div.style.visibility = "hidden";    }}// rollover highlights of context menu itemsfunction toggleHighlight(evt) {    evt = (evt) ? evt : ((event) ? event : null);    if (evt) {        var elem = (evt.target) ? evt.target : evt.srcElement;        if (elem.nodeType == 3) {            elem = elem.parentNode;        }        if (elem.className.indexOf("menuItem") != -1) {            elem.className = (evt.type == "mouseover") ? "menuItemOn" : "menuItem";        }    }}// set tooltips for menu-capable and lesser browsersfunction setContextTitles() {    var cMenuReady = (document.body.addEventListener || typeof document.oncontextmenu != "undefined")    var spans = document.body.getElementsByTagName("span");    for (var i = 0; i < spans.length; i++) {        if (spans[i].className == "contextEntry") {            if (cMenuReady) {                var menuAction = (navigator.userAgent.indexOf("Mac") != -1) ? "Click and hold " : "Right click ";                spans[i].title = menuAction + "to view relevant links"            } else {                spans[i].title = "Relevant links available with other browsers (IE5+/Windows, Netscape 6+)."                spans[i].style.cursor = "default";            }        }    }}// bind events and initialize tooltipsfunction initContextMenus() {    if (document.body.addEventListener) {        // W3C DOM event model        document.body.addEventListener("contextmenu", showContextMenu, true);        document.body.addEventListener("click", hideContextMenus, true);    } else {        // IE event model        document.body.oncontextmenu = showContextMenu;    }    // set intelligent tooltips    setContextTitles();}
