// JavaScript Document
function addMove(xs, ys, xe, ye) {
	this.move=true;
	this.xs=xs;
	this.ys=ys;
	this.xe=xe;
	this.ye=ye;
	this.xdiff=xe-xs;
	this.ydiff=ye-ys;
}
function center(xs, ys) {
	this.move=true;
	this.xs=xs-Math.round(this.ws/2);
	this.ys=ys-Math.round(this.hs/2);
	this.xe=xs-Math.round(this.we/2);
	this.ye=ys-Math.round(this.he/2);
	this.xdiff=this.xe-this.xs;
	this.ydiff=this.ye-this.ys;
	
}

function addMargins(ts, te, ls, le, both) {
	this.ts=ts;
	this.te=te;
	this.ls=ls;
	this.le=le;
	this.both=both;
	this.tdiff=te-ts;
	this.ldiff=le-ls;
	this.margins=true;
}

function addFade(fs,fe) {
	this.fs=fs;
	this.fe=fe;
	this.fdiff=fe-fs;
	this.fade=true;
}

function animBox(id, ws,hs,we,he,st) {

	this.id=id;
	this.st=Math.PI/st;
	this.ws=ws;
	this.hs=hs;
	this.we=we;
	this.he=he;
	this.wdiff=we-ws;
	this.hdiff=he-hs;
	this.move=false;
	this.fade=false;
	this.margins=false;
	this.addMove=addMove;
	this.center=center;
	this.addFade=addFade;
	this.addMargins=addMargins;

	this.ds=null;
	this.de=null;
		
}

var animObj = new Object;
var curVal= new Object;
var timer= null;

function startAnim(o) {

	animObj[o.id]=null;
	animObj[o.id]=o;
	curVal[o.id]=0;
	if (o.ds) document.getElementById(o.id).style.display=o.ds;
	if (! timer) timer=setInterval(animTimer,3);

}

function animTimer() {
	var cnt=0;
	var o, d;
	var w,h,x,y,f,t,l;
	//var db=document.getElementById("debug");
	//db.innerHTML="";

	for (var oId in animObj) {
	
		//db.innerHTML=db.innerHTML+"<br>"+oId+" ("+(animObj[oId]!=null)+")";
		ao=animObj[oId];
		if (ao) {
			cnt+=1;
			
			o=document.getElementById(ao.id);
			d=((Math.cos(curVal[ao.id])*-0.5) +0.5);
			w=Math.round(ao.ws+ao.wdiff*d);
			h=Math.round(ao.hs+ao.hdiff*d);
		
			if (ao.fade) {
				f=Math.round(ao.fs+ao.fdiff*d);
				o.style.filter="alpha(opacity="+f+")";
				o.style.opacity=f/100;
				o.style.MozOpacity=f/100;
			}		
			//-moz-opacity:1.00;
			//-khtml-opacity: 1.00;
			//opacity: 1.00;
		
		
			if (ao.move) {
				x=Math.round(ao.xs+ao.xdiff*d);
				y=Math.round(ao.ys+ao.ydiff*d);
				if (ao.xdiff) o.style.left=x+"px";
				if (ao.ydiff) o.style.top=y+"px";
			}	
			if (ao.margins) {
				t=Math.round(ao.ts+ao.tdiff*d);
				l=Math.round(ao.ls+ao.ldiff*d);
				if (ao.tdiff) o.style.marginTop=t+"px";
				if (ao.ldiff) o.style.marginLeft=l+"px";
				if (ao.both) {
					if (ao.tdiff) o.style.marginBottom=t+"px";
					if (ao.ldiff) o.style.marginRight=l+"px";
				}
			}	
			if (ao.wdiff) o.style.width=w+"px";
			if (ao.hdiff) o.style.height=h+"px";
			
			curVal[ao.id]=curVal[ao.id]+ao.st;
			
			if (curVal[ao.id]>Math.PI || curVal[ao.id]<0) {
				animObj[oId]=null;
				animObj[ao.id]=null;
				curVal[ao.id]=0;
				if (ao.move) {
					if (ao.xdiff) o.style.left=ao.xe+"px";
					if (ao.ydiff) o.style.top=ao.ye+"px";
				}	
				if (ao.margin) {
					if (ao.ldiff) o.style.marginLeft=ao.le+"px";
					if (ao.tdiff) o.style.marginTop=ao.te+"px";
					if (ao.both) {
						if (ao.tdiff) o.style.marginBottom=ao.te+"px";
						if (ao.ldiff) o.style.marginRight=ao.le+"px";
					}
				}	
				if (ao.wdiff) o.style.width=ao.we+"px";
				if (ao.hdiff) o.style.height=ao.he+"px";
				if (ao.de) o.style.display=ao.de;
			}
		}
	}
	if (cnt==0) {
//		alert("Deactivate Timer");
		clearInterval(timer);
		timer=null;

	}
	//alert ("pause");
}

function getCenter(pos, size) {
	return pos+Math.round(size/2);
	
}


