
/*

POKDynScroll is a scroll document inside a HTML page.

author: mAd (Damien Terrier, dterrier@hfp.fr)

date: 14/01/2001 14:21

bugs: 

- if div's overflow is set to hidden, the content is not refresh when the div moves (IE4)

todo: 

- make it works for newer browsers (getElementId?)

- add support for x-axis

- add misc. functions (ValueOf, setvisibility, setclipping, animate)

- move is not complete yet. don't take this.step_y as parameter as it should.



comments: to be completed, to be documented

*/



var NS4 = (document.layers);

var IE4 = (document.all);

var NS6 = ((navigator.appName=='Netscape') && (parseInt(navigator.appVersion.toString())==5));

function POKDynScroll(name, width, height, top, left, bgcolor) {

// a few properties, more to add	

	this.name = name;

	this.bgcolor = bgcolor;

	

	this.width = width;

	this.height = height;

	this.left = left;

	this.top = top;

	this.bottom = top + height;



	if (NS4) {

	this.top += 3;

	}



	this.MAX_TOP = this.top;

	this.MAX_BOTTOM = this.height - 10;

	

	this.ClipLeft = 0;

	this.ClipRight = this.width;

	this.ClipTop = 0;

	this.ClipBottom = this.height;

	

	this.idTimeout = 0;

	

	this.step_y = 2;

	this.delay_y = 15;

	

// add the layer to the page with a document.write

	var buffer = "";

	if (NS4) {

 		buffer += ("<layer id='" + this.name + "' ");

 		buffer += ("width='"+ this.width + "' ");

 		buffer += ("height='"+ this.height + "' ");

 		buffer += ("top='" + this.top + "' ");

 		buffer += ("left='" + this.left + "' ");

	 	buffer += ("bgcolor='" + this.bgcolor + "' ");

 		buffer += ("clip='"+ this.ClipLeft + "," + this.ClipTop + "," + this.ClipRight + "," + this.ClipBottom + "'");

		buffer += ">";

	}

	if (IE4 || NS6) {

		buffer += "<div id='" + this.name + "' ";

		buffer += "style='position:absolute; ";

		buffer += "width:" + this.width + "px; ";

		buffer += "height:" + this.height + "px; ";

		buffer += "z-index:1; ";

		buffer += "clip: rect(" + this.ClipTop + " " + this.ClipRight + " " + this.ClipBottom + " " + this.ClipLeft + "); "; 

		buffer += "left: " + this.left + "px; "

		buffer += "top: " + this.top + " px; ";

		//buffer += "backgroundColor: #666666; ";

		buffer += "visibility:visible; ";


		//buffer += "overflow:hidden; ";

		buffer += "'>";

	}

	document.write(buffer);

}



// move this layer to the direction given in parameter

// TODO: makes it works for the x-axis and after, in both in the same time

// ie should be this.name.move('up', 'right')

// BUG in IE5 (IE4 as well I suppose)



POKDynScroll.prototype.move = function(direction) {

	this.idTimeout = 0;

	if (direction == "top") {

		temp = - this.step_y; // don't do anything to this.step_y

		if ((this.top - temp) > this.MAX_TOP)

		  return; // exit, the layer is in place.

		}			

	else if (direction  == "bottom") {

		temp = this.step_y; // reverse the direction

		if ((this.bottom - temp) < this.MAX_BOTTOM)

		  return;

		};

	this.top -= temp;

	this.bottom -= temp;

	this.ClipTop += temp;

	this.ClipBottom += temp;

	if (NS4) {

		document.eval(this.name).clip.top = this.ClipTop;

		document.eval(this.name).clip.bottom = this.ClipBottom;

		document.eval(this.name).top = this.top;

	}

	if (IE4) {

		eval(this.name).style.clip = 'rect(' + this.ClipTop + ' ' +  this.ClipRight + ' ' + this.ClipBottom + ' ' + this.ClipLeft +')';

		eval(this.name).style.pixelTop = this.top;

	}

	if (NS6) {

		document.getElementById(this.name).style.top = this.top;

		document.getElementById(this.name).style.clip = 'rect('+ this.ClipTop + 'px, '+this.ClipRight + 'px, ' + this.ClipBottom + 'px,' + this.ClipLeft +'px)';

	}

	this.idTimeout= setTimeout("o_" + this.name + ".move('" + direction + "')",this.delay_y);

}

POKDynScroll.prototype.stop = function() {

	clearTimeout(this.idTimeout);

}

POKDynScroll.prototype.toString = function() {

	var buffer = "";

	buffer += this.name +"\n";

	buffer += "height: " + this.height + " width: " + this.width + " left: " + this.left + " top: " + this.top + " bottom: " + this.bottom + "\n";

	buffer += "clip: left = " + this.ClipLeft + " right = " + this.ClipRight + " top = " + this.ClipTop + " bottom = " + this.ClipBottom +"\n";

	return(buffer);

}

POKDynScroll.prototype.close = function () {

	if (NS4)

		document.write("</layer>"); //WHY THE FUCK NETSCAPE DON'T WANT TO WRITE !!!

	if (IE4 || NS6)

		document.write("</div>");

}

