/**********************************************************************************   
DotMenu 
*   Copyright (C) 2001 <a href="/dhtmlcentral/dan_pupius.asp">Dan Pupius</a>
*   This script was released at DHTMLCentral.com
*   Visit for more great scripts!
*   This may be used and changed freely as long as this msg is intact!
*   We will also appreciate any links you could give us.
*
*   Made by <a href="/dhtmlcentral/dan_pupius.asp">Dan Pupius</a> 
*   Modified to tree by Markus Altmann (C) Jan2004
*
*	Die Menudefinition befindet sich am Ende dieses Listings 
*
*********************************************************************************/

//====================================== provides cross-browser functionality
function getObjectRef(name) {
  if(document.getElementById) return document.getElementById(name);
  else if(document.all) return document.all[name];
  else return null;
}

//======================================== 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); }  
  if(el) { el.style.top = parseInt(y); el.style.marginLeft = 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); }  
  if(el) { el.style.top = parseInt(el.style.top) + parseInt(y); el.style.marginLeft = parseInt(el.style.marginLeft) + parseInt(x); }  
}

//==========================  Creates the menu objects
var lastDot="divDot0";
var xPosCorrect = 200;
var menuCount = 0;
var outText = "";
function menuObject(name,x,y,caption,r,parent) {	
  x = x+ xPosCorrect;
  if ( (!document.getElementById&&!document.all) || navigator.userAgent.indexOf("Opera")>-1) return;
  // alte Positionierung mit Referenz zum linken Rand
  //document.write('<div id="divDot' + menuCount + '" class="dotempty" style="top: ' + y + 'px; left: ' + x + 'px;"></div>');
  //document.write('<div id="divCap' + menuCount + '" class="caption" style="top: 0px; left: 0px;">' + caption + '</div>');
  //-- neue Positionierung zentriert zum Fenster
  document.write('<div id="divDot' + menuCount + '" class="dotempty" style="top: ' + y + 'px; left: 50%; margin-left: -' + x + 'px;"></div>');
  document.write('<div id="divCap' + menuCount + '" class="caption" style="top: 0px; left: 50%;">' + caption + '</div>');
  
  this.name = name;
  this.parent = parent;
  this.ref = "divDot" + menuCount;
  this.caption = "divCap" + menuCount
  if(r) this.radius = r; 
  else this.radius = 400;
  this.subMenus = new Array();
  this.state = 0;
  this.moving = false;
  if(this.parent) this.action = "null";
  else this.action = "toggle";
  if(this.parent) this.startAngle = parent.startAngle;
  else this.startAngle = 0;
  this.message=""

  getObjectRef(this.ref).objRef = this.name;
  
  this.show = function() { show(this.ref); }
  this.hide = function() { hide(this.ref); }
  this.moveMe = function(x,y) { if(this.parent) { x += this.parent.x(); y += this.parent.y(); } moveMe(this.ref,x,y); }
  this.moveBy = function(x,y) { moveBy(this.ref,x,y); }
  //this.x = function() { return parseInt(getObjectRef(this.ref).style.left); }
  this.x = function() { return parseInt(getObjectRef(this.ref).style.marginLeft); }
  this.y = function() { return parseInt(getObjectRef(this.ref).style.top); }
  this.w = function() { return getWidth(this.ref); }
  this.h = function() { return getHeight(this.ref); }

  // ------------------------------------------ Caption zum Punkt positionieren und einblenden 
  // Die Caption position relativ zum Menupunkt wird hier festgelegt
  this.showCaption = function() {
    //moveMe(this.caption, this.x() - (getWidth(this.caption)/2) + (this.w()/2), (this.y() + this.h()));
    moveMe(this.caption, this.x()+10, this.y()-5);
    show(this.caption);
  }
  
  // ------------------------------------------ Caption ausblenden
  this.hideCaption = function() {
    hide(this.caption);
  }
  
  this.setCaption = function(c) { getObjectRef(this.caption).innerHTML = c;}
 
  // ---------------------------------------------------- New menu item
  this.addItem = function(c,action,r) {
    getObjectRef(this.ref).className = "dot";
    if(!r) r = this.radius*0.8;
    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;
  }
  
  // ----------------------------------------------------- Expand sub menu
  this.expand = function() {
	var opak1 = "30";
	var opak2 = "60";
	var opak3 = "100";
	var opak_1 = opak1+"%";
	var opak_2 = opak2+"%";
	var opak_3 = opak3+"%";
	var alpha_1 = "alpha (opacity="+opak1+")"
	var alpha_2 = "alpha (opacity="+opak2+")"
	var alpha_3 = "alpha (opacity="+opak3+")"
	// wenn der Menupunkt ein Submenu hat
    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;    
      if((!this.parent || this.parent.state == this.parent.subMenus.length) && p) {
        if(this.parent) this.collapseAll(this.name);        
        var diff = this.spreadAng / this.subMenus.length;
        for(var i=0;i<this.subMenus.length;i++){
          this.subMenus[i].moveMe(0,0);
          this.subMenus[i].show();
          this.moving = true;
          this.subMenus[i].slide(this.subMenus[i].radius * cos(degToRad((diff*i)+this.startAngle)), this.subMenus[i].radius * sin(degToRad((diff*i)+this.startAngle)), this.name + ".subMenus[" + i + "].showCaption();" + this.name + ".moving=false;" + this.name + ".state+=1;");
        }		
		// Wenn der geklickte Menupunkt zu einem Untermenu gehört
		if(this.parent){
		  // Der geklickte Menupunkt (ausser wenn es der Hauptmenupunkt ist)
          getObjectRef(this.ref).className = "doton"; //marc
	      getObjectRef(this.caption).className = "captionOn"; //marc
		  // Alle Menupunkte in der Ebene vom geklickten
          for(i=0;i<this.parent.subMenus.length;i++) {
              getObjectRef(this.parent.subMenus[i].ref).style.filter = alpha_2;
              getObjectRef(this.parent.subMenus[i].ref).style.MozOpacity = opak_2;
              getObjectRef(this.parent.subMenus[i].caption).style.filter = alpha_2;
              getObjectRef(this.parent.subMenus[i].caption).style.MozOpacity = opak_2;        
          }
          // Der Ansatz-Menupunkt in der Ebene drüber
          getObjectRef(this.parent.ref).className = "dotoff";
          getObjectRef(this.parent.ref).style.filter = alpha_1;
          getObjectRef(this.parent.ref).style.MozOpacity = opak_1;
          getObjectRef(this.parent.caption).style.filter = alpha_1;
          getObjectRef(this.parent.caption).style.MozOpacity = opak_1;		  
		  // Wenn der geklickte Menupunkt zu einem Unter-Untermenu gehört
          if(this.parent.parent) {
			// Alle Menupunkte in der Ebene über der des geklickten
            for(i=0;i<this.parent.parent.subMenus.length;i++) {
              getObjectRef(this.parent.parent.subMenus[i].ref).style.filter = alpha_1;
              getObjectRef(this.parent.parent.subMenus[i].ref).style.MozOpacity = opak_1;
              //getObjectRef(this.parent.parent.subMenus[i].ref).className = "dotoff";
              getObjectRef(this.parent.parent.subMenus[i].caption).style.filter = alpha_1;        
              getObjectRef(this.parent.parent.subMenus[i].caption).style.MozOpacity = opak_1;
            }
			// Der Ansatz-Menupunkt in der 2ten Ebene drüber
            getObjectRef(this.parent.parent.ref).style.MozOpacity = opak_1;
            getObjectRef(this.parent.parent.ref).style.MozOpacity = opak_1;
            //getObjectRef(this.parent.parent.ref).className = "dotoff";
          }
        }
		// Der geklickte Menupunkt
        getObjectRef(this.ref).style.filter = alpha_3;
        getObjectRef(this.ref).style.MozOpacity = opak_3;
        getObjectRef(this.caption).style.filter = alpha_3;  
        getObjectRef(this.caption).style.MozOpacity = opak_3; 
      }
    }
  }

  // ----------------------------------------------------- Collapse sub menu
  this.collapse = function() {
	var opak1 = "80";
	var opak2 = "100";
	var opak3 = "80";
	var opak_1 = opak1+"%";
	var opak_2 = opak2+"%";
	var opak_3 = opak3+"%";
	var alpha_1 = "alpha (opacity="+opak1+")"
	var alpha_2 = "alpha (opacity="+opak2+")"
	var alpha_3 = "alpha (opacity="+opak3+")"
    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);    
    if(p && this.subMenus.length > 0) {
      for(var i=0;i<this.subMenus.length;i++){
        this.subMenus[i].hideCaption();
        this.moving = true;
        this.subMenus[i].slide(0, 0, this.name + ".subMenus[" + i + "].hide();" + this.name + ".moving=false;" + this.name + ".state-=1;");
      }
     // Wenn der geklickte Menupunkt zu einem Untermenu gehört
      if(this.parent){
		// Alle Menupunkte in der Ebene vom geklickten
        for(i=0;i<this.parent.subMenus.length;i++) {
          getObjectRef(this.parent.subMenus[i].ref).style.filter = alpha_3;
          getObjectRef(this.parent.subMenus[i].ref).style.MozOpacity = opak_3;
		  // Unterschiedliches Design je nach dem ob der Menupunkt ein Untermenu besitzt oder nicht
          if(this.parent.subMenus[i].subMenus.length != 0) 
            getObjectRef(this.parent.subMenus[i].ref).className = "dot";
          else
            getObjectRef(this.parent.subMenus[i].ref).className = "dotempty";
          getObjectRef(this.parent.subMenus[i].caption).style.filter = alpha_2;        
          getObjectRef(this.parent.subMenus[i].caption).style.MozOpacity = opak_2;
        }
        // Der Ansatz-Menupunkt in der Ebene drüber
		getObjectRef(this.parent.ref).style.filter = alpha_1;
        getObjectRef(this.parent.ref).style.MozOpacity = opak_1;
        if(this.parent.subMenus.length != 0)
          getObjectRef(this.parent.ref).className = "dot";
        else
          getObjectRef(this.parent.ref).className = "dotempty";
		getObjectRef(this.parent.caption).style.filter = alpha_1;
        getObjectRef(this.parent.caption).style.MozOpacity = opak_1;
		// Wenn der geklickte Menupunkt zu einem Unter-Untermenu gehört
        if(this.parent.parent) {
		  // Alle Menupunkte in der Ebene über der des geklickten	
          for(i=0;i<this.parent.parent.subMenus.length;i++) {
            getObjectRef(this.parent.parent.subMenus[i].ref).style.filter = alpha_1;
            getObjectRef(this.parent.parent.subMenus[i].ref).style.MozOpacity = opak_1;
			// Unterschiedliches Design je nach dem ob der Menupunkt ein Untermenu besitzt oder nicht
            if(this.parent.parent.subMenus[i].subMenus.length != 0)
              getObjectRef(this.parent.parent.subMenus[i].ref).className = "dot";
            else
              getObjectRef(this.parent.parent.subMenus[i].ref).className = "dotempty";       
            getObjectRef(this.parent.parent.subMenus[i].caption).style.filter = alpha_1;        
            getObjectRef(this.parent.parent.subMenus[i].caption).style.MozOpacity = opak_1;
          }
        }
      }
	  // Der geklickte Menupunkt
      getObjectRef(this.caption).className = "caption"; //marc 
      getObjectRef(this.ref).style.filter = alpha_2;
      getObjectRef(this.caption).style.filter = alpha_2;       
      getObjectRef(this.ref).style.MozOpacity = opak_2;
      getObjectRef(this.caption).style.MozOpacity = opak_2;
    }
  }

  this.collapseAll = function(except) {
    for(var i=0;i<this.parent.subMenus.length;i++) {
      if(this.parent.subMenus[i].name!=except && this.parent.subMenus[i].state==this.parent.subMenus[i].subMenus.length) {
        this.parent.subMenus[i].collapse();
      }    
    }
  }
 
  // ------------------------------------------- Den derzeit geklickten Menupunkt aktiv setzen
  // und das Caption als visited kennzeichnen
  this.aktuell = function() {
	getObjectRef(lastDot).className = "dot";
    getObjectRef(this.ref).className = "dotActive";
	getObjectRef(this.caption).className = "captionActive";
	lastDot = this.ref;
  }
 
  this.toggle = function(e) {
    if(document.all) id = window.event.srcElement;
    else id = e.target;
    var dot = eval(id.objRef);    
    if(dot.state==0 && !dot.moving) {dot.expand(); if(dot.parent)outText=dot.message;}
    else if(dot.state==dot.subMenus.length && !dot.moving) {dot.collapse(); if(dot.parent)outText="";}
  }
  
  this.doAction = function(e) {
    if(document.all) id = window.event.srcElement;
    else id = e.target;
    var dot = eval(id.objRef);   
    if(dot.action == "toggle") dot.toggle(e);
    else {dot.aktuell(); eval(dot.action);}
    //dot.toggle(e);
    //if(dot.action != "toggle") eval(dot.action);
  }
  
  // ----------------------------------------------- Meldung ein-aus
  function textAnzeigen(elem,text){
	if (document.all) {
	  document.all[elem].innerHTML = text;
	} else {
	  var ihatenetscape = document.getElementById(elem);
	  ihatenetscape.innerHTML = text;  
	}
  }
  
  this.showMessage = function(e) {
    if(document.all) id = window.event.srcElement;
    else id = e.target;
    var dot = eval(id.objRef);   
	if (!dot.message=="") textAnzeigen('Message',dot.message);
	textAnzeigen('gruezi','');
  }
  
  this.hideMessage = function(e) {
    if(document.all) id = window.event.srcElement;
    else id = e.target;
    var dot = eval(id.objRef);   
	textAnzeigen('Message',outText); 
  }
  
  //change these if you want to change the events that trigger the actions
  //========================================================================
  getObjectRef(this.ref).onmouseout = this.hideMessage;
  getObjectRef(this.ref).onmouseover = this.showMessage;
  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));  
    var v = d/8;
    if(v<1) v = 1;        
    if( (Math.abs(x) < v) && (Math.abs(y) < v) ) {
      moveMe(this.ref,xx + px,yy + py);      
      if(func != "") eval(func);
    } else {    
      var a = round(atan(x,y));
      dx = round(v * cos(degToRad(a)));
      dy = round(v * sin(degToRad(a)));
      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
//
//====================================================================================

//get dimentions of the page
if(document.all) pageWidth = document.body.offsetWidth-20;
else pageWidth = innerWidth;
if(document.all) pageHeight = document.body.offsetHeight-4;
else pageHeight = innerHeight;

//Create main menu
//var menu = new menuObject("menu",pageWidth/2,pageHeight/2,"Ansi+Lumen",pageHeight/2,winkel);
var menu = new menuObject("menu",130,180,"GO",110);
menu.startAngle = -70;
menu.spreadAng = 100;

//show menu and caption
menu.show();
menu.showCaption();

//Add submenus
c = menu.addItem("news","window.open('News.htm', 'textwin', 'height=420,width=500')");
c.message="Was im Moment bei uns los ist";

c = menu.addItem("Kunst","toggle");
c.message="Kunst mit Farbe, Form und Transparenz";
c.startAngle = -45;
c.spreadAng = 40;
menu.subMenus[1].addItem("Dämmerungslichter","window.open('Baustelle2.html', 'smallwin', 'height=220,width=500')");
menu.subMenus[1].addItem("Letzte Momente","window.open('Baustelle2.html', 'smallwin', 'height=220,width=500')");
menu.subMenus[1].addItem("Wo zu sehen","window.open('Baustelle2.html', 'smallwin', 'height=220,width=500')");

c = menu.addItem("Design","toggle");
c.message="Objekte der besonderen Art";
c.startAngle = 20;// -20;
c.spreadAng = 20;
c = menu.subMenus[2].addItem("Intro","window.open('Design.htm', 'textwin', 'height=420,width=500')",170);
c.message="Unsere Meinung über Design"
c = menu.subMenus[2].addItem("LUM","window.open('LUMdet1.html')",170);
c.message="LUM the SWISS LOVELITE &nbsp; &nbsp; + &nbsp; &nbsp; Das Antidot zum Taschenmesser"
c = menu.subMenus[2].addItem("EL'MOS","window.open('Baustelle2.html', 'smallwin', 'height=220,width=500')",170);
c.message="EL'MOS das spannbare ElektroLumineszente LichtMOSaik"

c = menu.addItem("Events","toggle");
c.message="Ausstattungen für Konzerte, Partys, usw.";
c.startAngle = -20;
c.spreadAng = 25;
c = menu.subMenus[3].addItem("Intro","window.open('Events.htm', 'textwin', 'height=420,width=500')",120);
c.message="Allgemeines über unsere Teilnahme an Events"
c = menu.subMenus[3].addItem("Lichtgarten","window.open('Baustelle2.html', 'smallwin', 'height=220,width=500')",120);
c.message="Der Lichtgarten - (work in progress)"
c = menu.subMenus[3].addItem("Freischwimmer@ganges","window.open('atGanges.html')",170);
c.message="Indien-Event im Rahmen der Asien-Pazifik-Wochen 2003 in Berlin"

c = menu.addItem("Über uns","window.open('AundL1.htm', 'textwin', 'height=420,width=500')");
c.message="Ein paar kurze Sätze über uns, wer wir sind, was wir tun";
c.startAngle = -30;
//c = menu.subMenus[4].addItem("Cool Sites","toggle");
//c.startAngle = -30;
//menu.subMenus[4].subMenus[0].addItem("Comercial Sites","window.open('/resources/default.asp?catid=5&cattitle=Commercial+sites')");
//menu.subMenus[4].subMenus[0].addItem("Personal Sites","window.open('/resources/default.asp?catid=6&cattitle=Personal+sites')");
