/*--------------------------------------------------------------------------
 * Copyright © 2008
 * Author(s): Helge Gerischer
 *--------------------------------------------------------------------------*/

function KeepCenter(webObjID, objID) {

	this.objID = objID;
	this.webObjID = webObjID;
	this.startWidth = 0;
	this.startHeigth = 0;
	this.objWidth = 500;
	this.objHeight = 500;
	this.objVariationTop = 0;
	this.objVariationLeft = 0;
	this.intervalID = 0;
	
	//alert(this.webObjID);

	
	this.winWidth = function  () {
	  if (window.innerWidth) {
		return window.innerWidth;
	  } else if (document.body && document.body.offsetWidth) {
		return document.body.offsetWidth;
	  } else {
		return 0;
	  }
	}
	
	this.winHeight = function() {
	  if (window.innerHeight) {
		return window.innerHeight;
	  } else if (document.body && document.body.offsetHeight) {
		return document.body.offsetHeight;
	  } else {
		return 0;
	  }
	}

	this.centerTopPos = function(y) {return(Math.round((this.winHeight()/2)-(y/2)+this.objVariationTop));}
	this.centerLeftPos = function(x) {return(Math.round((this.winWidth()/2)-(x/2)+this.objVariationLeft));}
	
	this.fullScreen = function() {
		document.getElementById(this.webObjID).style.height = "100%";
		document.getElementById(this.webObjID).style.width = "100%";
	}
	
//	this.setAlpha() document.getElementById(this.webObjID).style.
	
	this.setObjPos = function() {
		document.getElementById(this.webObjID).style.top = this.centerTopPos(this.objHeight).toString()+"px";
		document.getElementById(this.webObjID).style.left = this.centerLeftPos(this.objWidth).toString()+"px";
	}
	
	this.drawObj = function() {
	  //alert(this.objHeight.toString());
		
		document.getElementById(this.webObjID).style.height = this.objHeight.toString()+"px";
		document.getElementById(this.webObjID).style.width = this.objWidth.toString()+"px";	
	}
/*	
	this.setOpasity = function(opacity) {
		document.getElementById(this.webObjID).style.height = this.objHeight.toString()+"px";
		document.getElementById(this.webObjID).style.MozOpacity = opacity;
		document.getElementById(this.webObjID).style.filter = 'alpha(opacity='+ opacity*100 +')';
		document.getElementById(this.webObjID).style.opacity = opacity;
		document.getElementById(this.webObjID).style.KHTMLOpacity = opacity*100;"
	}
*/	

	this.hideObj = function() {
		x=0;
		document.getElementById(this.webObjID).style.height = x.toString()+"px";
		document.getElementById(this.webObjID).style.width = x.toString()+"px";	
	}
	
	this.sizeContainer = function(func)	{
		if(func == "open") this.intervalID = setInterval(this.objID+".animOpen('"+this.webObjID+"')", this.speed);
		if(func == "close") this.intervalID = setInterval(this.objID+".animClose('"+this.webObjID+"')", this.speed);
	}

	this.animOpen = function ()
	{
	  var step = 40;
		var x = this.objWidth - this.startWidth;
		var y = this.objHeight - this.startHeigth;	
		
		if (this.startWidth <= this.objWidth) {
			if (x >= step) {
				this.startWidth = this.startWidth + step;
				this.pl = this.pl - (step/2);
			}
			else {
				this.startWidth = this.startWidth + x;
				this.pl = this.pl - (x/2);
			}
			document.getElementById(this.webObjID).style.width = this.startWidth.toString() + "px";
			document.getElementById(this.webObjID).style.left = Math.round((this.winWidth()/2)-(this.startWidth/2)+this.objVariationLeft).toString() + "px";
		}
		
		if (this.startHeigth <= this.objHeight) {
			if (x >= step) this.startHeigth = this.startHeigth + step;
			else this.startHeigth = this.startHeigth + x;
			document.getElementById(this.webObjID).style.height = this.startHeigth.toString() + "px";
		}
		
		if ((this.startHeigth >= this.objHeight) && (this.startWidth >= this.objWidth)) window.clearInterval(this.intervalID);
	}
}
