/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +--------------------------------------------------------+
// | Internet Explorer 5.5 & Firefox 1.0                    |
// +--------------------------------------------------------+
// | Copyright (c) 2007 Song Hyo-Jin                        |
// +--------------------------------------------------------+
// | This source file is BSD license.                       |
// +--------------------------------------------------------+
// | Author : Song Hyo-Jin <crosser at hanmail dot net>     |
// |                                  (MSN Messengerable)   |
// +--------------------------------------------------------+
//
// $Id: follow_banner.js, v 0.0.1 2007/03/13 19:00:00 crosser Exp $
//
// follow banner

function follow_banner(obj_id, div_id, scrollType, x, y)
{
	this.obj_id = obj_id;
	this.div_id = document.getElementById(div_id);
	this.x = false;
	this.y = false;
	this.bounds = getBounds(this.div_id);
	this.status = getStatus();

	if(!scrollType) {
		scrollType = 1;
	}
	if(scrollType & 1) {
		if(!this.div_id.style.top) {
			this.div_id.style.top = "0";
		}
		this.top = this.bounds.top;
		this.y = true;
		if(y) {
			this.bounds.top = y;
		}
	}
	if(scrollType & 2) {
		if(!this.div_id.style.left) {
			this.div_id.style.left = "0";
		}
		this.left = this.bounds.left;
		this.x = true;
		if(x) {
			this.bounds.left = x;
		}
	}

	this.loop = function() {
		this.status = getStatus();
		var gab;
		var oldBounds = getBounds(this.div_id);
		if(this.y) {
			if(this.bounds.top >= 0) {
				var newTop = this.status.scrollTop + this.bounds.top;
			} else {
				var newTop = this.status.scrollTop + this.status.clientHeight + this.bounds.top - this.bounds.height;
				if(document.all) {
					newTop -= 5;
				}
			}
			if(oldBounds.top != newTop) {
				gab = newTop - oldBounds.top;
				gab = Math.ceil(gab * .3);
				if(gab == 0) {
					gab = -1;
				}
				this.div_id.style.top = (oldBounds.top + gab - this.top) + "px";
			}
		}
		if(this.x) {
			if(this.bounds.left >= 0) {
				var newLeft = this.status.scrollLeft + this.bounds.left;
			} else {
				var newLeft = this.status.scrollLeft + this.status.clientWidth + this.bounds.left - this.bounds.width;
				if(document.all) {
					newLeft -= 6;
				}
			}
			if(oldBounds.left != newLeft) {
				gab = newLeft - oldBounds.left;
				gab = Math.ceil(gab * .3);
				if(gab == 0) {
					gab = -1;
				}
				this.div_id.style.left = (oldBounds.left + gab - this.left) + "px";
			}
		}
		setTimeout(this.obj_id + ".loop();", 10);
	}
}

