// ---------------------------------------------------------------------------
// this script is copyright (c) 2001/2002 by Michael Wallner!
// http://www.wallner-software.com
// mail:"info - dhtml @ wallner - software . com" (remove Blanks)
//
// you may use this script on web pages of your own
// you must not remove this copyright note!
//
// Sie dürfen dieses Script auf Ihren Webseiten verwenden
// Sie dürfen diesen Copyright Hinweis jedoch nicht entfernen!
// ---------------------------------------------------------------------------

// ---------------------------------------------------------------------------
//                   circel menu version 1.1
//
// supported browsers:  IE4+, IE5+, IE6+, NS4+, NS6+, NS7+, MOZ, OP5+, OP6+
// needed script files: crossbrowser.js
//                      infofader.js
// ---------------------------------------------------------------------------


//create a circelMenu object
//erzeugen eines circleMenü Objektes
//name     : id of the menu
//centerx  : x-position of circle center
//centery  : y-position of circle center
//radius   : radius of 'button' circle
//radi     : radius of 'info' circle (optional)
function createCircleMenu(name,centerx, centery, radius, radi){
  this.name=name
  this.angle=0;
  this.cx=centerx;
  this.cy=centery;
  this.rad=radius;
  this.radi=radius+10;
  if (radi) this.radi=radi;
  this.currentangle=0;
  this.currentButton=0;
  this.lastx=0
  this.lasty=0
  this.buttons=new Array();
  this.effekt=b_menuEffekt;
  this.show=false
  this.action=b_menuAction;
  this.initEffekt=b_initEffekt;
  this.addButton = b_addButton;
  this.open= b_open;
  this.autoClose = 0;     //autoclose menu after xxxx ms 0=no autoclose
  this.inMove=false;

  this.v = name + "var";
  eval(this.v + "=this");

  this.info = new createInfoArray(name+'_info');

  return this

}

//Einen Menübutton hinzufügen
//Add one menubutton
//pict:   Image name
//action: Javascript onClick
//over:   Javascript onmouseOver
//out:    Javascript onmouseOut
//info:   Label text
function b_addButton(pict,action,over,out,info) {
  this.buttons[this.buttons.length] = new b_createButton(this,pict,action,over,out,info);
}

function b_createButton(parent,pict,action,over,out,info) {
var b
var n
  n = parent.name+parent.buttons.length;
  l = parent.buttons.length;
  j = "if (bt.ie4 || bt.ie5) this.blur(); "+parent.v+".action("+l+"); return false;";
  b='<a href="#" onClick="'+j+'" onMouseOver="'+over
  b = b +'" onMouseOut="'+out+'"><IMG src="'+pict+'" id='+n+'img border=0></A>';

  if (bt.ns4)
    document.write("<LAYER name="+n+" visibility='hide'>"+b+"</LAYER>");
  else
    document.write("<DIV id="+n+" style='visibility=hidden'>"+b+"</DIV>");
  this.action=action
  this.parent=parent;
  this.obj=getObj(n);
  if (bt.ns4)
    this.img=this.obj.document.images[0];
  else
   this.img=getObj(n+'img');
  this.css=(bt.ns4)?this.obj:this.obj.style;
  this.css.visibility='hidden';
  this.stop=0;
  this.x=0;
  this.y=0;
  this.setAngle=b_setAngle;
  this.setInfo=b_setInfo;
  this.moveTo=b_moveTo;

  parent.info.addInfo(l,info,'binfo',20*l,10);
  this.ind=l;
  return this;
}

function b_menuAction(button) {
  if (!this.inMove) {
    if (this.autoClose!=0) {
      if (this.show) this.open(button);
    }
    else {
      this.open(button);
    }
  }
}


function b_open(button) {
    this.show=!this.show
    if (this.buttons[this.currentButton].x != this.lastx)
       this.buttons[this.currentButton].moveTo(this.lastx,this.lasty);
    this.initEffekt(button);
}

function b_setInfo(angle) {
  var x1
  var y1
  var width
  if (ns4) {
    //width=this.parent.info.infos[this.ind].obj.clip.right;
    width=this.parent.info.infos[this.ind].obj.document.width;
  }
  else {
    if (this.parent.info.infos[this.ind].obj.style.pixelWidth)
      width=this.parent.info.infos[this.ind].obj.style.pixelWidth;
    else
      width=this.parent.info.infos[this.ind].obj.offsetWidth;
  }
  x1=this.parent.cx-(this.parent.radi)*Math.cos(angle*Math.PI/180);

  if ((angle%360)>=270 || (angle%360)<90) x1=x1-width
  x1=x1+(this.parent.radi-this.parent.rad)/2;
  y1=this.parent.cy-(this.parent.radi+5)*Math.sin(angle*Math.PI/180);
  y1=y1-(this.parent.radi-this.parent.rad)/4;
  this.parent.info.infos[this.ind].moveTo(x1,y1);
}

function b_setAngle(angle) {
  this.x=this.parent.cx-this.parent.rad*Math.cos(angle*Math.PI/180);
  this.y=this.parent.cy-this.parent.rad*Math.sin(angle*Math.PI/180);
  this.moveTo(this.x,this.y);
  this.parent.lastx=this.x
  this.parent.lasty=this.y
}


function b_initEffekt(button) {
  this.inMove=true;
  step=360/this.buttons.length;		        //winkel pro button
  this.angle=90+step*button			//Kreis Anfang
  stop=90+step*(button+1)			//Startwinkel
     this.currentButton=button			//aktuellen Button merken
  //endwinkel festlegen
  for (i=button+1;i<this.buttons.length;i++){
    this.buttons[i].stop=stop
    this.buttons[i].setAngle(stop);
    this.buttons[i].setInfo(stop);
    if (this.show) {
      this.buttons[i].css.visibility='hidden';
    }
    else
      this.buttons[i].css.visibility='visible';
    this.buttons[i].zIndex=0;
    stop=stop+step;
  }
  for (i=0;i<=button;i++){
    this.buttons[i].stop=stop
    this.buttons[i].setAngle(stop);
    this.buttons[i].setInfo(stop);
    if (this.show)
      this.buttons[i].css.visibility='hidden';
    else
      this.buttons[i].css.visibility='visible';
    this.buttons[i].zIndex=90;
    stop=stop+step;
  }
  this.buttons[button].css.visibility='visible';
  this.buttons[button].css.zIndex=99;
  this.effekt();
}


function b_menuEffekt(){
  this.angle=this.angle+5;
  this.buttons[this.currentButton].setAngle(this.angle);
  for (i=0;i<this.buttons.length;i++) {
    if (this.angle>=this.buttons[i].stop) {
      if (!this.show) {
        if (i!=this.currentButton) {
          this.buttons[i].css.visibility='hidden';
          this.info.showInfo(this.buttons[i].ind,false);
        }
      }
      else {
        this.buttons[i].css.visibility='visible';
        this.info.showInfo(this.buttons[i].ind,true);
     }
    }
  }
  if (this.angle<this.buttons[this.currentButton].stop)
    setTimeout(this.v+'.effekt()',30)
  else {
    this.inMove=false;
    if (!this.show) {
      eval(this.buttons[this.currentButton].action);
      if (this.autoClose!=0) window.setTimeout(this.v+".open("+this.currentButton+")",this.autoClose);
    }
  }
}




