//
// scrollchaser.js
//
// 2008.2.4
//
//
function ScrollChaser(id,int)
{
	this.interval = int;
	this.id = id;
	return this;
}
//
ScrollChaser.prototype.init = function()
{
	var callback = this.setting;
	var scope = this;
	//
	try {
		window.addEventListener('load', function(){ callback.call(scope)}, false);
	} catch (e) {
		window.attachEvent('onload', function(){ callback.call(scope)});
	}
}
ScrollChaser.prototype.setting = function()
{
	var callback = this.scrollEvent;
	var scope = this;
	//
	this.el = document.getElementById(this.id);
	this.el.style.position = 'absolute';
	this.initTop = this.el.offsetTop;
	//
	try {
		window.addEventListener('scroll', function(){ callback.call(scope)}, false);
	} catch (e) {
		window.attachEvent('onscroll', function(){ callback.call(scope)});
	}
}
ScrollChaser.prototype.scrollEvent = function()
{
	var el = this.el;
	var init = this.initTop;
	//
	var myInt = setInterval(function()
		{
			var cur = (document.body.scrollTop||document.documentElement.scrollTop)+20;
			var myTop = el.offsetTop;
			var d = cur-myTop;
			if(Math.abs(d)>1) {
				if( cur >= init )
				{
					var y = myTop + d/3;
					el.style.top = y+"px";
				} else {
					el.style.top = init+"px";
					clearInterval(myInt);
				}
			} else {
				el.style.top = cur+"px";
				clearInterval(myInt);
			}
		},this.interval);
}
//
var sc = new ScrollChaser('sub_menu',188);
sc.init();
