home *** CD-ROM | disk | FTP | other *** search
- // ⌐Xara Ltd 2002
- // variables used to store info on each menu that is visible
- var ma = new Array();
- var mx = new Array();
- var my = new Array();
- var mc = new Array();
- var mal = 0;
-
- var main = 0;
- var menuw = 200;
- var psrc = 0;
- var pname = "";
- var al="";
-
- // browser sniffer function
- var NS6 = (!document.all && document.getElementById);
- var NS4 = (!document.getElementById);
- var IE5 = (!NS4 && !NS6 && navigator.userAgent.indexOf('MSIE 5.0')!=-1);
- // Opera misbehaves so treat it like NS4
- if (navigator.userAgent.indexOf('Opera')!=-1) NS4=1;
-
- // must be called to start a navbar menu
- // file = the top/left navbar end
- // dir = direction of the navbar 1 for vertical, 2 for horizontal, 3 for nontable vertical and 4 for nontable horizontal
- // space = the spacing between buttons
- // align = 1 right justify the graphics in the table, 2 = center the graphics, anything else and left justify them
- function startMainMenu(file, h, w, dir, space, align)
- {
- if (w>0) menuw = w;
- main = dir;
- if (main == 1 || main == 2) document.write("<table border=\"0\" cellspacing=\"" + space + "\" cellpadding=\"0\">");
- if (file != "")
- {
- al="";
- if (align==1) al=" align=\"right\"";
- if (align==2) al=" align=\"center\"";
- if (main == 1 || main == 2) document.write("<tr><td" + al + ">");
- document.write("<img src=\"" + loc + file + "\" border=\"0\"");
- if (h>0) document.write(" height=\"" + h + "\"");
- if (w>0) document.write(" width=\"" + w + "\"");
- document.write(" />");
- if (main == 1 || main == 2) document.write("</td>");
- if (main == 1) document.write("</tr>");
- if (main == 3) document.write("<br></br>");
- }
- }
-
- // must be called to end a navbar menu
- // file = the graphic of the bottom/right end bar
- // h = height of the end bar graphic if applicable, zero to ignore
- // w = width of the end bar graphic if applicable, zero to ignore
- function endMainMenu(file, h, w)
- {
- if (file != "")
- {
- if (main == 1) document.write("<tr>");
- if (main == 1 || main == 2) document.write("<td" + al + ">");
- document.write("<img src=\"" + loc + file + "\" border=\"0\"");
- if (h>0) document.write(" height=\"" + h + "\"");
- if (w>0) document.write(" width=\"" + w + "\"");
- document.write(" />");
- if (main == 1 || main == 2) document.write("</td></tr>");
- }
- if (main == 1 || main == 2) document.write("</table>");
- main = 0;
- }
-
- // called for each graphic element and source of a menu in the navbar menu
- // name = the unique name of the submenu to create. Also the name of graphic if the ext is ".gif" etc.
- // if so graphics are required for name.ext and possibly name_over.ext
- // ext = the graphic file extention eg ".gif", if it doesnt start with a . is assumed to be a text element in the menu
- // url = the url this item links to
- // tar = the target
- // dir = the direction of the submenu 1 to the right, 2 down, 3 to the left
- // state = number of button states 1 for static graphics, 2 for showing over states
- // s = the css class which controls what this entry looks like in terms of font, colour, rollover, triangle graphics etc
- function mainMenuItem(name, ext, h, w, url, tar, alt, dir, state, s)
- {
- if (NS4 && main==0) return;
- var isgraphic = ext.charAt(0)==".";
-
- if (main == 1) document.write("<tr>");
- if (main == 1 || main == 2) document.write("<td" + al + ">");
-
- document.write("<a ");
- if (url != "" || !isgraphic) document.write("href=\"" + url + "\" ");
- if (tar != "") document.write("target=\"" + tar + "\" ");
- document.write ("onmouseout=\"");
- if (dir > 0) document.write("tidyMenu(event);");
- document.write("\" onmouseover=\"");
- if (dir > 0) document.write("openMenu(event, '" + name + "'," + dir + "," + bc + "," + fc + ");");
- if (state > 1 && isgraphic)
- {
- // cache the over state if required
- document[name+"_over"] = new Image();
- document[name+"_over"].src = loc + name+"_over"+ext;
- // if there is an over state make it select it
- document.write("setGraphic(event, '" + loc + name + "_over" + ext + "');");
- }
- document.write("return false;\"");
-
- if (!isgraphic) document.write(" class=\""+s+"\" style=\"width:" + (w>0?w:menuw) + "px\"");
-
- document.write(">");
- if (isgraphic)
- {
- document.write("<img src=\"" + loc + name + ext + "\" border=\"0\"");
- if (h>0) document.write(" height=\"" + h + "\"");
- if (w>0) document.write(" width=\"" + w + "\"");
- if (alt!="") document.write(" alt=\"" + alt + "\"");
- document.write(" />");
- }
- else
- {
- document.write(" " + ext + " ");
- }
-
- document.write("</a>");
- if (main == 1 || main == 2) document.write("</td>");
- if (main == 1) document.write("</tr>");
- if (main == 3) document.write("<br></br>");
- }
-
- // called first when defining a submenu
- // name = unique name of the submenu
- function startSubmenu(name, style, sw)
- {
- if (NS4) return;
- if (sw>0) menuw = sw;
- document.write("<div id=\"" + name + "\" class=\""+ style + "\" style=\"width:" + (menuw+(NS6?bd*2:0)) + "px\">");
- }
-
- // called to mark the end of a submenu definition
- // name = unique name of the submenu
- function endSubmenu(name)
- {
- if (NS4) return;
- document.write("</div>");
- // register the mouseout from this div
- if (!NS6) document.getElementById(name).onmouseout = tidyMenu;
- }
-
- // called to define each element on the submenu
- // text = the menu items text
- // url = its url
- // tar = its target
- // s = css class name
- function submenuItem(text, url, tar, s)
- {
- if (NS4) return;
- if (text.charAt(0) == '<')
- document.write(text);
- else
- {
- document.write("<a ");
- if (url != "") document.write("href=\"" + url + "\" ");
- if (tar != "") document.write("target=\"" + tar + "\" ");
- document.write("class=\""+s+"\" style=\"width:" + menuw + "px\"> " + text + " </a>");
- }
- }
-
- // change the image that spawned the event to show the graphic 'file'
- function setGraphic(event, name)
- {
- if (NS4) return;
- psrc = (NS6) ? event.target : event.srcElement;
- pname = psrc.src;
-
- if (NS6)
- event.target.src = name;
- else
- event.srcElement.src = name;
-
- }
-
- // open the submenu
- // id = the name of the submenu
- // pos = the relative position of the submenu 1 to right, 2 down, 3 to left
- function openMenu(event, id, pos, bc, fc)
- {
- if (NS4) return;
- var el, x, y;
- //if the menu is still opening up snap it to fully open first then see what we have
- if (mal>0)
- {
- el = document.getElementById(ma[mal-1]);
- if (mx[mal-1] != el.offsetLeft || my[mal-1] != el.offsetTop)
- {
- el.style.left = mx[mal-1];
- el.style.top = my[mal-1];
- }
-
- tidyMenu(event);
- }
-
- if (NS6)
- {
- if (mal == 0)
- {
- x = event.target.x - bd;
- y = event.target.y;
- dx = event.target.offsetWidth;
- dy = event.target.offsetHeight;
- }
- else
- {
- var p = event.target;
- if (p.nodeName != "A" && p.parentNode.nodeName == "A")
- p = p.parentNode;
-
- dx = p.offsetWidth;
- dy = p.offsetHeight;
- el = document.getElementById(ma[mal-1]);
- x = el.offsetLeft - bd;
- y = el.offsetTop + p.offsetTop;
- }
-
- }
- else
- {
- x = event.clientX - event.offsetX + document.body.scrollLeft - document.body.clientLeft;
- y = event.clientY - event.offsetY + document.body.scrollTop - document.body.clientTop - bd;
- dx = event.srcElement.offsetWidth;
- dy = event.srcElement.offsetHeight;
- if (mal>0) x-=2*bd;
-
- }
-
- el = document.getElementById(id);
- if (el && el.style.visibility != "visible")
- {
- if (pos == 1)
- {
- x += dx;
- el.style.left = x-el.offsetWidth;
- el.style.top = y;
- nspeed = el.offsetWidth / frames;
- }
- else if (pos == 2)
- {
- y += dy;
- el.style.left = x;
- el.style.top = y-el.offsetHeight;
- nspeed = el.offsetHeight / frames;
- }
- else if (pos == 3)
- {
- x -= el.offsetWidth;
- el.style.left = x+el.offsetWidth;
- el.style.top = y;
- nspeed = el.offsetWidth / frames;
- }
-
- mx[mal] = x;
- my[mal] = y;
-
- if (NS6 || IE5 || frames==0)
- {
- el.style.left = x;
- el.style.top = y;
- }
-
- if (!IE5) clipMenu(mal, el);
- el.style.visibility = "visible";
- ma[mal] = id;
-
- if (NS6)
- {
- var p = event.target;
- if (p.nodeName != "A" && p.parentNode.nodeName == "A")
- p = p.parentNode;
- mc[mal] = p.style;
- // format the NS6 likes its colours to be in
- //mc[mal].backgroundColor = "#ffffff";
- //mc[mal].color = "#ff0000";
-
- el.onmouseout = tidyMenu;
- }
- else
- {
- mc[mal] = event.srcElement.style;
- if (mal>0)
- {
- mc[mal].backgroundColor = bc;
- mc[mal].color = fc;
- }
- }
- mal++;
- }
- }
-
- // return the name of the menu which contains x,y
- function overMenu(x,y)
- {
- for (i=0; i < mal; i++)
- {
- var el = document.getElementById(ma[i]);
- if (el.offsetLeft + el.offsetWidth > x && el.offsetLeft <= x
- && el.offsetTop + el.offsetHeight > y && el.offsetTop <= y)
- {
- return ma[i];
- }
- }
- return "";
- }
-
- // the cursor has left a menu or a button
- // tidy away menus that the cursor isnt over or arnt parents of a menu the cursor is over
- // the parents are identified by having a name that starts the same as the child
- // eg if the child is called menu2_3_1 the parent would be called menu2_3
- function tidyMenu(e)
- {
- if (NS4) return;
-
- if (NS6)
- {
- t = overMenu(e.pageX, e.pageY);
-
- // remove NS flicker since it defines events when moving between different parts of the same object
- if (t!="" && (e.target.firstChild == e.relatedTarget || e.target == e.relatedTarget.firstChild))
- return;
-
- }
- else
- t = overMenu(event.clientX + document.body.scrollLeft-document.body.clientLeft, event.clientY + document.body.scrollTop-document.body.clientTop);
-
- om = 0;
- for (i=0; i < mal; i++)
- {
- var mail = ma[i].length;
- if (mail > t.length || t.substring(0, mail) != ma[i])
- {
- var el = document.getElementById(ma[i]);
- el.style.visibility = "hidden";
- mc[i].backgroundColor = "";
- mc[i].color = "";
- }
- else
- {
- ma[om] = ma[i];
- mx[om] = mx[i];
- my[om] = my[i];
- om++;
- }
- }
- mal = om;
-
- // replace the button graphic
- if (mal == 0 && psrc) psrc.src = pname;
- }
-
- // function called every 50 millisecs to make the menus slide out
- function animate()
- {
- for (i=0; i < mal; i++)
- {
- var el = document.getElementById(ma[i]);
- if (el.style.visibility == "visible")
- {
- if (el.offsetLeft < mx[i]) el.style.left = Math.min(el.offsetLeft + nspeed, mx[i]) + "px";
- if (el.offsetLeft > mx[i]) el.style.left = Math.max(el.offsetLeft - nspeed, mx[i]) + "px";
- if (el.offsetTop < my[i]) el.style.top = Math.min(el.offsetTop + nspeed, my[i]) + "px";
- clipMenu(i, el);
- }
- }
-
- if (mal!=0 || frames!=0)
- setTimeout("animate()", 50);
- }
-
- // clip the menus while they slide out
- function clipMenu(i, el)
- {
- if (el.offsetLeft > mx[i]) el.style.clip = "rect(" + (my[i]-el.offsetTop) + "px "+ (el.offsetWidth+(mx[i]-el.offsetLeft)) + "px " + el.offsetHeight + "px " + 0 + "px)";
- else el.style.clip = "rect(" + (my[i]-el.offsetTop) + "px "+ el.offsetWidth + "px " + el.offsetHeight + "px " + (mx[i]-el.offsetLeft) + "px)";
- }
-
- // debug function only - not part of the menus at all. Used to probe the DOM.
- // object = enumerate the properties of this object
- function showpropsign(object)
- {
- t = 0;
- str=""
- for (var i in object)
- {
- if (i != "innerHTML" && i != "innerText" && i != "outerText" && i != "outerHTML" && i != "preventBubble"
- && i != "preventCapture" && i != "initEvent" && i != "view")
- {
- str += i + " = " + object[i] + "\n";
- t++;
- if (t > 10)
- {
- alert(str);
- str = "";
- t = 0;
- }
- }
- }
- if (t > 0) alert(str)
- }
-
-