
var delta = 1;//0.5;
var collection;

function floaters() {
	this.items = [];
	this.addItem = function(id,x,y,content,flag)
	{
		document.write('<DIV id='+id+' style="Z-INDEX: 10; POSITION: absolute; left:'+(typeof(x)=='string'?eval(x):x)+';top:'+(typeof(y)=='string'?eval(y):y)+'">'+content+'</DIV>');

		var newItem = {};
		newItem.object = document.getElementById(id);
		newItem.x = x;
		newItem.y = y;
		newItem.x_step = 1;
		newItem.y_step = 1;
		newItem.bFloat = flag;

		this.items[this.items.length] = newItem;
	}
	
	this.play = function()
	{
		collection = this.items
		setInterval('play()', 10);
	}
}

function play()
{
	for(var i = 0; i < collection.length; i++)
	{
		var followObj = collection[i].object;
		var followObj_bFloat = collection[i].bFloat;
		var followObj_x = (typeof(collection[i].x) == 'string' ? eval(collection[i].x) : collection[i].x);
		var followObj_y = (typeof(collection[i].y) == 'string' ? eval(collection[i].y) : collection[i].y);
		
		if(followObj_bFloat) {
			// ¸¡¶¯ÒÆ¶¯¹ã¸æ
			var c_x = parseInt(followObj.style.left) + collection[i].x_step;;
			var c_y = parseInt(followObj.style.top) + collection[i].y_step;;

			if(c_x <= 0 || c_x == document.body.clientWidth - 100) {
				collection[i].x_step = -1 * collection[i].x_step;
			}
			else if(c_x > document.body.clientWidth - 100) {
				c_x = document.body.clientWidth - 101;
			}

			if(c_y <= 0 || c_y == document.body.clientHeight - 100) {
				collection[i].y_step = -1 * collection[i].y_step;
			}
			else if(c_y > document.body.clientHeight - 100) {
				c_y = document.body.clientHeight - 101;
			}
			//alert(c_x);
			//alert(c_y);
			if(c_x >= 780)
				followObj.style.left = c_x;
			else
				followObj.style.left = 780;
			followObj.style.top = c_y;
		}
		else {
			if(followObj.offsetLeft != (document.body.scrollLeft + followObj_x)) {
				var dx = (document.body.scrollLeft + followObj_x - followObj.offsetLeft) * delta;
				dx = (dx > 0 ? 1 : -1) * Math.ceil(Math.abs(dx));
				followObj.style.left = followObj_x;
				if(followObj_x >= 780)
					followObj.style.left = followObj_x;
				else
					followObj.style.left = 780;
				//followObj.style.left = followObj.offsetLeft + dx;
			}
			

			if(followObj.offsetTop != (document.body.scrollTop + followObj_y)) {
				var dy = (document.body.scrollTop + followObj_y - followObj.offsetTop) * delta;
				dy = (dy > 0 ? 1 : -1) * Math.ceil(Math.abs(dy));
				followObj.style.top = followObj.offsetTop + dy;
			}
		}

		followObj.style.display = '';
	}
}


