Scrollers = {};
Scroller.speed=100;

function Scroller(outer,inner,table){
	this.id=outer;
	Scrollers[this.id]=this;
	this.animString="Scrollers."+this.id;
	this.load(inner,table);
};

Scroller.loadLayer=function(outer,id,table){
	if(Scrollers[outer])Scrollers[outer].load(id,table);
};

Scroller.prototype.load=function(inner,table){
	if(!document.getElementById)return;
	var wndo,lyr;
	if(this.inner){
		lyr=document.getElementById(this.inner);
		lyr.style.visibility="hidden";
	}
	lyr=document.getElementById(inner);
	wndo=document.getElementById(this.id);
	lyr.style.top=this.y=0;
	lyr.style.left=this.x=0;
	this.maxY=(lyr.offsetHeight-wndo.offsetHeight>0)?lyr.offsetHeight-wndo.offsetHeight:0;
	this.wd=table?document.getElementById(table).offsetWidth:lyr.offsetWidth;
	this.maxX=(this.wd-wndo.offsetWidth>0)?this.wd-wndo.offsetWidth:0;
	this.inner=inner;
	lyr.style.visibility="visible";
	this.on_load();
	this.ready=true;
};

Scroller.prototype.on_load=function(){};

Scroller.prototype.shiftTo=function(lyr,x,y){
	if(!lyr.style)return;
	lyr.style.left=(this.x=x)+"px";
	lyr.style.top=(this.y=y)+"px";
};

Scroller.BrowserFix=function(){
	var ua=navigator.userAgent;
	if(ua.indexOf("Gecko")>-1 && ua.indexOf("Firefox")==-1 && ua.indexOf("Safari")==-1 && ua.indexOf("Konqueror")==-1){
		Scroller.hold=[];
		for(var i=0;arguments[i];i++){
			if(Scrollers[arguments[i]]){
				var wndo=document.getElementById(arguments[i]);
				var holderId=wndo.parentNode.id;
				var holder=document.getElementById(holderId);
				document.body.appendChild(holder.removeChild(wndo));
				wndo.style.zIndex=1000;
				var pos=getPageOffsets(holder);
				wndo.style.left=pos.x+"px";
				wndo.style.top=pos.y+"px";
				Scroller.hold[i]=[arguments[i],holderId];
			}
		}
		window.addEventListener("resize",Scroller.resizeFix,true);
	}
};

Scroller.resizeFix=function(){
	if(Scroller.hold){
		for(var i=0;Scroller.hold[i];i++){
			var wndo=document.getElementById(Scroller.hold[i][0]);
			var holder=document.getElementById(Scroller.hold[i][1]);
			var pos=getPageOffsets(holder);
			wndo.style.left=pos.x+"px";
			wndo.style.top=pos.y+"px";
		}
	}
};

function getPageOffsets(el){
	var left=el.offsetLeft;
	var top=el.offsetTop;
	if(el.offsetParent&&el.offsetParent.clientLeft||el.offsetParent.clientTop){
		left+=el.offsetParent.clientLeft;
		top+=el.offsetParent.clientTop;
	}
	while(el=el.offsetParent){
		left+=el.offsetLeft;
		top+=el.offsetTop;
	}
	return{x:left,y:top};
};


