// general functions to assist the script
//========================================
function show(name) {
var el = getObjectRef(name);
if(el) el.style.visibility = "visible";
}
function hide(name) {
var el = getObjectRef(name);
if(el) el.style.visibility = "hidden";
}
function getWidth(name) {
var el = getObjectRef(name);
return el.offsetWidth;
}
function getHeight(name) {
var el = getObjectRef(name);
return el.offsetHeight;
}
function moveMe(name,x,y) {
var el = getObjectRef(name);
if(el) { el.style.top = parseInt(y); el.style.left = parseInt(x); }
}
function moveBy(name,x,y) {
var el = getObjectRef(name);
if(el) { el.style.top = parseInt(el.style.top) + parseInt(y); el.style.left = parseInt(el.style.left) + parseInt(x); }
}
// Creates the menu objects
//==========================
var menuCount = 0;
function menuObject(name,x,y,caption, r, parent) {
if ( (!document.getElementById&&!document.all) || navigator.userAgent.indexOf("Opera")>-1) return;
document.write('<div id="divDot' + menuCount + '" class="dotempty" style="top: ' + y + '; left: ' + x + '"></div>');
document.write('<div id="divCap' + menuCount + '" class="caption" style="top: 0; left: 0">' + caption + '</div>');
this.addItem = function(c,action,r) {
getObjectRef(this.ref).className = "dot";
if(!r) r = this.radius/2;
var sub = new menuObject(this.name + ".subMenus[" + this.subMenus.length + "]",0,0,c,r,this);
sub.parent = this;
sub.action = action;
sub.moveMe(0,0);
this.subMenus[this.subMenus.length] = sub;
return sub;
}
this.expand = function() {
if(this.subMenus.length > 0) {
var p = true;
if(this.parent) {
p = !this.parent.moving;
for(var i=0; i<this.parent.subMenus.length;i++)
p = p && ((this.parent.subMenus[i].state==0) || (this.parent.subMenus[i].state==this.parent.subMenus[i].subMenus.length)) && (this.parent.subMenus[i].moving==false);
} else var o = false;
this.collapse = function() {
var p = true;
p = !this.moving;
for(var i=0; i<this.subMenus.length;i++)
p = p && (this.subMenus[i].state==0) && (this.subMenus[i].moving==false);
//change these if you want to change the events that trigger the actions
//========================================================================
//getObjectRef(this.ref).onmousemove = this.toggle;
getObjectRef(this.ref).onmouseup = this.doAction;
this.slide = function(xx,yy,func) {
if(!func) func = "";
var px = this.parent.x();
var py = this.parent.y();
var x = xx - this.x() + px;
var y = yy - this.y() + py;
var d = sqrt(square(xx-this.x() + px) + square(yy-this.y() + py));
this.moveBy(dx,dy);
setTimeout(this.name + ".slide(" + xx + "," + yy + ", '" + func + "');",10);
}
}
// Preoading the windows filters.
if (menuCount==0 && document.all) document.all[this.ref].style.filter = "alpha (opacity=100)";
menuCount++;
return this;
}
// Math functions
//================
var pi = Math.PI;
function square(x) { return (x*x); }
function sqrt(x) { return Math.sqrt(x); }
function round(x) { return Math.round(x); }
function rand(x,y) { return (round(Math.random()*(y-x)) + x); }
function cos(x) { return Math.cos(x) }
function sin(x) { return Math.sin(x) }
function degToRad(x) { return ( x/(360/(2*pi)) ); }
function radToDeg(x) { return ( x*(360/(2*pi)) ); }
function atan(s,t) {
if( s == 0.0 && t > 0.0)
angle = 90.0;
else if(s == 0.0 && t < 0.0)
angle = 270.0;
else if (s < 0.0 )
angle = 180.0 + radToDeg(Math.atan(t/s));
else if (s > 0.0 && t < 0.0)
angle = 360.0 + radToDeg(Math.atan(t/s));
else {
if(s==0.0) s=0.00001;
angle = radToDeg(Math.atan(t/s));
}
if(angle < 0.0) angle += 360.0;
return angle;
}
//====================================================================================
// make the menus and provide information on usage
//====================================================================================
//
// In order to customise your menus all you need to do is:
// - edit the styles .dot, .dotoff and .caption
// - add the main menu using the following code
// var [menu_name] = new menuObject("[menu_name]", [x position], [y position], [caption], [spacing between sub menus]);
// - add the subemus using:
// var [sub_menu] = [menu_name].addItem([caption],[action],[spacing]);
// OR
// var [sub-sub_menu] = [sub_menu].addItem([caption],[action],[spacing]);
// OR
// [menu_name].subMenus[x].addItem([caption],[action],[spacing]);
//
// - where action is string that get's evaluated when the dot is clicked
//
// (NOTE the spacing is optional and if left blank gets inherited
// and is equal to the (parent's value)/2 - the default for
// the main menu item uis 400)
//
// - the following allow extra manipulation of the menus:
// + menuItem.show() - show's the menu's dot
// + menuItem.showCaption() - show's the menu's caption
// + menuItem.hide()
// + menuItem.hideCaption()
// + menuItem.startAngle = x - default is 0-degrees which means the first submenu appears
// directly to the right, the following items are traced in a
// clockwise direction
// + menuItem.setCaption("text") - allows you to change a menus caption
// + menuItem.expand() - opens a menus submenus (if they exist)
// + menuItem.collapse() - closes a menu's subItems (unless one of them is open)
//
// + menuItem.moveMe(x,y) - moves a menu to coordinates (x,y)
// + menuItem.moveBy(x,y) - moves a menu by (x,y)-pixels
// + menuItem.x() & menuItem.y() - retrieve a menus coordinates
//
//====================================================================================