/* $Id: layout.js,v 1.7 2007/07/01 15:09:02 hg Exp $ */
function layout_add(n){
if(!n.nodeName)return;
layout_registerDocPos(n);
n.START_SLOW=1;
n.START_FAST=2;
n.START_CURVE=3;
n.START_SLOW_END_SLOW=4;
var papa=n.parentNode;
n.style.position="absolute";
    n.posX=n.offsetLeft
    n.posY=n.offsetTop
if(papa.nodeName.toLowerCase()!='body' && !papa.style.position)papa.style.position='relative'
n.getPosition=function(){return new Point(this.posY||0,this.posX||0)}
n.posTo=function(x,y,save){this.posToPoint(new Point(x,y),save)}
n.moveToPoint=function(p,kind,duration,steps,save){this.moveTo(p.left,p.top,kind,duration,steps,save)}
n.moveTo=function(x,y,kind,duration,steps,save){
clearTimeout(this.movesTimeout);
this.finalX=x||0
this.finalY=y||0
this.startX=this.posX||0
this.startY=this.posY||0
this.moveCount=0
this.lastMove=(steps||12)
this.moveSpeed=((isNaN(duration))?375:duration)/this.lastMove
this.moveKind=kind||this.START_SLOW_END_SLOW
this.bend=Math.round(Math.random())
if(this.onMoveStart)this.onMoveStart(this.finalX,this.finalY)
this.moveStep(save)
this.moving=true
}
n.posToPoint=function(p,save){
var ia,br,x,y;
if(!isNaN(save)&&save!=null){
br=this.docGetRelativeBottomRight();
if(papa.nodeName.toLowerCase()=='body')ia=Box.getInnerArea().br;
else{
if(!papa.docGetRelativeBottomRight)layout_registerDocPos(papa);
ia=papa.docGetRelativeBottomRight()
}
x=Math.min(ia.left-save-br.left+getScrollLeft(),Math.max(p.left,save));
y=Math.min(ia.top-save-br.top+getScrollTop(),Math.max(p.top,save))
}else{
x=p.left
y=p.top
}
this.setPos(x,y)
}
n.setPos=function(x,y){
this.posX=(isNaN(x))?0:x
this.posY=(isNaN(y))?0:y
eval("this.style."+((this.right)?"right":"left")+"="+this.posX+"+'px'");
eval("this.style."+((this.bottom)?"bottom":"top")+"="+this.posY+"+'px'");
}
n.moveStep=function(save){
var f,g,z,r,x,y;
clearTimeout(this.movesTimeout);
this.moveCount+=1
if(this.moveCount>=this.lastMove){
this.moving=false;
this.posToPoint(new Point(this.finalY,this.finalX),save)
if(this.onMoveEnd)this.onMoveEnd(this.startX,this.startY)
return;
}
r=this.moveCount/this.lastMove
if(this.moveKind==this.START_FAST) g=f=sinCurve(r)
else if(this.moveKind==this.START_SLOW_END_SLOW) g=f=aufAbCurve(r)
else g=f=cosCurve(r)
if(this.moveKind==this.START_CURVE){
if(this.bend)g=sinCurve(r)
else f=sinCurve(r)
}   
x=this.startX+(this.finalX-this.startX)*f;
y=this.startY+(this.finalY-this.startY)*g;
this.posToPoint(new Point(y,x),save)
this.movesTimeout=setTimeout("document.getElementById('"+getId(this)+"').moveStep("+save+");",this.moveSpeed);
}
}
Point=function(top,left){
this.top=top;
this.left=left;
this.TOP_RIGHT=1
this.BOTTOM_RIGHT=2
this.BOTTOM_LEFT=3
this.TOP_LEFT=4
this.toString=function(){return "top: "+this.top+" / left: "+this.left}
this.isInMyQuadrant=function(otherPoint){
if (this.top>=otherPoint.top&&this.left<=otherPoint.left) return this.TOP_RIGHT
else if(this.top<otherPoint.top&&this.left<=otherPoint.left) return this.BOTTOM_RIGHT
else if(this.top<otherPoint.top&&this.left>otherPoint.left) return this.BOTTOM_LEFT
else return this.TOP_LEFT
}
this.isItTopLeft=function(otherPoint){return this.isInMyQuadrant(otherPoint)==this.TOP_LEFT}
this.isItTopRight=function(otherPoint){return this.isInMyQuadrant(otherPoint)==this.TOP_RIGHT}
this.isItBottomRight=function(otherPoint){return this.isInMyQuadrant(otherPoint)==this.BOTTOM_RIGHT}
this.isItBottomLeft=function(otherPoint){return this.isInMyQuadrant(otherPoint)==this.BOTTOM_LEFT}
this.subtract=function(otherPoint){return this.clone().subtractMe(otherPoint)}
this.add=function(otherPoint){return this.clone().addMe(otherPoint)}
this.divide=function(by){return this.clone().divideMe(by)}
this.multiply=function(by){return this.clone().multiplyMe(by)}
this.subtractMe=function(otherPoint){this.top-=otherPoint.top;this.left-=otherPoint.left;return this}
this.addMe=function(otherPoint){this.top+=otherPoint.top;this.left+=otherPoint.left;return this}
this.divideMe=function(by){this.top/=by;this.left/=by;return this}
this.multiplyMe=function(by){this.top*=by;this.left*=by;return this}
this.clone=function(){return new NewPoint(this)}
}
EventPagePoint.prototype=new Point()
EventPagePoint.prototype.constructor=EventPagePoint;
function EventPagePoint(e){this.top=e.pageY;this.left=e.pageX}
NewPoint.prototype=new Point()
NewPoint.prototype.constructor=NewPoint;
function NewPoint(p){this.top=p.top;this.left=p.left}
function layout_registerDocPos(e){
if(!e.nodeName)return;
var box=null,centerPoint=null,centerRelPoint=null,relBR=null,docPos_Left=null,docPos_Top=null;
e.docPosHere=function(top,left,renew){return new Point(top-this.docPosTop(renew),left-this.docPosLeft(renew))}
e.docPosCursor=function(e,renew){return this.docPosHere(e.pageY,e.pageX,renew)}
e.docGetBox=function(renew){var p;if(renew||box==null)box=new Box(p=this.docGetTopLeft(renew),p.add(this.docGetRelativeBottomRight(renew)));return box.clone()}
e.docIsInside=function(p,renew){return(this.docGetBox(renew).isInside(p))}
e.docGetCenter=function(renew){if(renew||centerPoint==null)centerPoint=new Point(this.docPosTop(renew),this.docPosLeft(renew)).addMe(this.docGetRelativeCenter());return centerPoint.clone()}
e.docGetTopLeft=function(renew){return new Point(this.docPosTop(renew),this.docPosLeft(renew))}
e.docGetRelativeCenter=function(renew){if(renew||centerRelPoint==null)centerRelPoint=this.docGetRelativeBottomRight(renew).divide(2);return centerRelPoint.clone()}
e.docPosLeft=function(renew){
if(docPos_Left==null||renew){
var b=0,p=this;
do{b+=p.offsetLeft;}while((p=p.offsetParent)!=null)
docPos_Left=b+((document.all)?2:0);
}
return docPos_Left;
}
e.docPosTop=function(renew){
if(docPos_Top==null||renew){
var b=0,p=this;
do{b+=p.offsetTop;}while((p=p.offsetParent)!=null)
docPos_Top=b+((document.all)?2:0);
}
return docPos_Top;
}
e.docGetRelativeBottomRight=function(renew){
var p,hide=false,v
if(renew||relBR==null){
if(this.style.display=='none'){
v=this.style.visibility;
this.style.visibility='hidden'
this.style.display='block'
hide=true;
}
relBR=new Point(this.offsetHeight,this.offsetWidth)
if(hide){
this.style.visibility=v
this.style.display='none'
}
}
return relBR.clone()
}
}
function Box(topLeft,bottomRight){
var center=null;
this.tl=topLeft;
this.br=bottomRight;
if(!this.tl.isItBottomRight(this.br)){alert("TopLeft ("+this.tl+") muss kleinere Werte Haben als BottomRight ("+this.br+")")}
this.isInside=function(p){return this.tl.isItBottomRight(p) && this.br.isItTopLeft(p)}
this.isOutside=function(p){return !this.isInside(p)}
this.toString=function(p){return "TopLeft=["+this.tl+"] / BottomRight=["+this.br+"]"};
this.getCenter=function(){return (center==null)?this.cernter=this.tl.add(this.br).divideMe(2):center};
this.clone=function(){return new Box(this.tl,this.br)};
}
Box.getInnerArea=function(){
var x,y;
if (self.innerHeight){x=self.innerWidth;y=self.innerHeight}
else if(document.documentElement && document.documentElement.clientHeight){x=document.documentElement.clientWidth;y=document.documentElement.clientHeight}
else if (document.body){x=document.body.clientWidth;y=document.body.clientHeight}
return new Box(new Point(0,0),new Point(y,x))
}
function getScrollTop(){
if (document.documentElement && document.documentElement.scrollTop)return document.documentElement.scrollTop;
else if (document.body)return document.body.scrollTop
return 
}
function getScrollLeft(){
if (document.documentElement && document.documentElement.scrollLeft)return document.documentElement.scrollLeft;
else if (document.body)return document.body.scrollLeft
return 
}

