///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//	¢Æ R2Slider 1.0
//
//	- 2008-03-20 by zardsama
//
// ************************************************************************************************************
//
// Usage)
//		var º¯¼ö¸í = new R2Slider("·¹ÀÌ¾î ID","º¯¼ö¸í", ¼Óµµ, »ó´Ü¸¶Áø);
//		º¯¼ö¸í.slide();
//
//		- ¼Óµµ, »ó´Ü¸¶ÁøÀº »ý·« °¡´É / ÃßÈÄ º¯°æ °¡´É
//		- 'º¯¼ö¸í.limitTop' È¤Àº 'º¯¼ö¸í.limitBottom' À¸·Î »ó/ÇÏ´Ü ÇÑ°è ÁöÁ¡ ¼³Á¤°¡´É
//
//
//	Example )
//		<div id="scroll" style="position:absolute; width: 100px; height: 400px;"></div>
//		<script type="text/javascript">
//			var test = new R2Slider ("scroll","test",null,null,null);
//			test.limitTop = 100;
//			test.slide();
//		</script>
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

R2Slider = function(id, slider, divPitch, marginTop, dElement) {
	if (isNaN(parseInt(marginTop))) marginTop = 0;	// »ó´Ü ¸¶Áø µðÆúÆ®
	if (isNaN(parseInt(divPitch))) divPitch = 15;	// ÀÌµ¿ °£°Ý µðÆúÆ®
	if (!dElement) dElement = document.documentElement; // DTD strict ÀÏ¶§ ( Transitional ÀÏ¶§´Â document.body )

	this.timer;	// Å¸ÀÌ¸Ó º¯¼ö
	this.slider = slider;	// °´Ã¼ º¯¼ö¸í
	this.obj = document.getElementById (id);	// ¿ÀºêÁ§Æ®
	this.marginTop = parseInt(marginTop);	// »ó´Ü ¸¶Áø
	this.divPitch = parseInt(divPitch);	// ÀÌµ¿ °£°Ý
	this.dElement = dElement; // DTD ¿¡ µû¸¥ µµÅ¥¸ÕÆ® ¿¤¸®¸ÕÆ®
	this.limitTop;	 // »ó´Ü ÇÑ°èÁ¡
	this.limitBottom;	 // ÇÏ´Ü ÇÑ°èÁ¡
}

R2Slider.prototype.moveIt = function(){
	var pitch = (parseInt(this.dElement.scrollTop)+ parseInt(this.marginTop)) - parseInt(this.obj.style.top);

	if (pitch == 0) return;
	else nextPos = parseInt(this.obj.style.top) + pitch / this.divPitch
	nextPos = (pitch > 0) ? Math.ceil(nextPos) : Math.floor(nextPos);

	var limitBottom = this.dElement.scrollHeight - parseInt(this.limitBottom)- parseInt(this.obj.offsetHeight);
	if ( this.limitTop && nextPos  < this.limitTop ) nextPos = this.limitTop;
	if ( this.limitBottom && nextPos  > limitBottom ) nextPos = limitBottom;
	if (nextPos < this.marginTop) nextPos = this.marginTop;
	if (isNaN(nextPos)) nextPos = 0;

	this.obj.style.top = nextPos+"px";
}

R2Slider.prototype.slide = function() {
	this.timer = setInterval(""+this.slider+".moveIt()", 10);
}