// -- programing: Justas Vinevičius --
// -- email: dadka@one.lt --

function Scroll_Draw(content,id,pLeft,pTop,cLeft,cTop,cWidth,cHeight) {
	if (isNN4) {
		document.write('<layer id="'+id+'" left='+pLeft+' top='+pTop+' width='+cWidth+' height='+cHeight+' clip="'+cLeft+','+cTop+','+cWidth+','+cHeight+'" zIndex=1 visibility=hidden>');
		document.write('<ilayer id="'+id+'cont" left=0 top=0>');
		document.write(content);
		document.write('</ilayer>');
		document.write('</layer>');
	}
	if (isIE4||isIE5||isN6) {
		document.write('<div id="'+id+'" style="position:absolute; left:'+pLeft+'px; top:'+pTop+'px; width:'+cWidth+'px; height:'+cHeight+'px; clip:rect('+cTop+' '+cWidth+' '+cHeight+' '+cLeft+'); overflow:hidden; visibility:hidden; z-index:10">');
		document.write('<div id="'+id+'cont" style="position:absolute; left:0px; top:0px;">');
		document.write(content);
		document.write('</div>');
		document.write('</div>');
	}

}

function FindLayerObject(id, doc) {
	var i,layer;
	for (i = 0; i < doc.layers.length; i++) {
		layer = doc.layers[i];
		if (layer.name == id) return layer;
		if (layer.document.layers.length > 0) {	if ((layer = FindLayerObject(id, layer.document)) != null) return layer; }
	}
	return null;
}

function GetLayerObject(id) {
	if (isNN4) return FindLayerObject(id, document);
	if (isIE4) return document.all[id];
	if (isIE5||isN6) return document.getElementById(id);
	return null;
}


function Layer(id) {
	this.id=id;
	if (isIE5||isN6||isIE4) {
		this.objClip=GetLayerObject(id);
		this.objCont=GetLayerObject(id+'cont');
		this.styleClip=this.objClip.style;
		this.styleCont=this.objCont.style;
		if (this.objCont.style.pixelHeight) {
			this.Height=this.styleCont.pixelHeight;
			this.Width=this.styleCont.pixelWidth;
			this.ClipHeight=this.styleClip.pixelHeight;
			this.ClipWidth=this.styleClip.pixelWidth;
		}
		else {
			this.Height=this.objCont.offsetHeight;
			this.Width=this.objCont.offsetWidth;
			this.ClipHeight=this.objClip.offsetHeight;
			this.ClipWidth=this.objClip.offsetWidth;
		}
	}
	if (isNN4) {
		this.objClip=GetLayerObject(id);
		this.objCont=GetLayerObject(id+'cont');
		this.styleClip=this.objClip;
		this.styleCont=this.objCont;

		this.Height=this.objCont.document.height;
		this.Width=this.objCont.document.width;
		this.ClipHeight=this.objClip.clip.height;
		this.ClipWidth=this.objClip.clip.width;
	}
	
	this.Delay=20;
	this.Step=5;
	this.StepDef=5;
	this.Scrolling=false;
	this.TimeOut=null;
	this.accelerate=true;

	this.Defaults=LayerDefaults;
	this.ScrollUp=LayerScrollUp;
	this.ScrollDn=LayerScrollDn;
	this.Stop=LayerStop;
}

function LayerDefaults() { 
	if (Loaded) {
		this.styleCont.left=0;
		this.styleCont.top=0; 
	}
}

function LayerScrollUp() {
	if (Loaded && parseInt(this.styleCont.top)+this.Step<=0) {
		if (this.accelerate) { this.Step+=0.3; }
		CurrentObject=this;
		this.Scrolling=true;
		this.styleCont.top=parseInt(this.styleCont.top)+this.Step;
		this.TimeOut=setTimeout("CurrentObject.ScrollUp()",this.Delay);
	}
	else { this.Defaults(); }
}

function LayerScrollDn() {
	if (Loaded && (parseInt(this.styleCont.top)+this.Height-this.ClipHeight)>=0 ) {
		if (this.accelerate) { this.Step+=0.3; }
		CurrentObject=this;
		this.Scrolling=true;
		this.styleCont.top=parseInt(this.styleCont.top)-this.Step;
		this.TimeOut=setTimeout("CurrentObject.ScrollDn()",this.Delay);
	}
}

function LayerStop() {
	if (Loaded && this.Scrolling) {
		this.Step=this.StepDef;
		this.Scrolling=false;
		clearTimeout(this.TimeOut);
	}
}

