
var Marquee =
{
	_private_functions:
	{
		_init : function()
		{
			while (this._base_div.firstChild != null)
			{
				this._base_div.removeChild(this._base_div.firstChild);
			}

			this._base_div.style.position = "relative";
			this._base_div.style.left = "0px";
			this._base_div.style.top = "0px";
			this._base_div.style.overflow = "hidden";

			var base_width = parseInt(this._base_div.offsetWidth);
			var used_width = 0;
			this._span_width = null;

			var count = 0;

			while (used_width < (base_width + (this._span_width == null ? 0 : this._span_width)) 
				|| count < 2)
			{
				var span = document.createElement("SPAN");
				span.innerHTML = this._marquee_text;
				span.setAttribute("style", "padding-right: 10px; white-space: nowrap");

				this._base_div.appendChild(span);

				if (this._span_width == null)
				{
					var sw = span.offsetWidth;

					this._span_width = parseInt(sw);
				}

				span.style.position = "relative";
				span.style.top = "0px";
				span.style.left = "0px";
			
				if (this._span_width <= 0)
					break;

				used_width += this._span_width;

				count++;
			}

			var b = this;
			var callback = function () { Marquee._private_functions._callback(b) };

			this._intervalid = setInterval(callback, this._interval);
		},

		_callback: function(marquee)
		{
			var sw = marquee._span_width;
			var child;

			var left = null;
			
			for (child = marquee._base_div.firstChild; child != null; child = child.nextSibling)
			{
				if (left == null)
				{
					left = parseInt(child.style.left);
					left = left - marquee._pixels;

					if (left + sw < 0)
					{
						left += sw;
					}
				}
				child.style.left = left + "px";
			}
		}
	},

	inst: function(div, pixels, interval, text)
	{
		this._base_div = div;
		this._pixels = pixels;
		this._interval = interval;
		this._marquee_text = text;

		this._init = Marquee._private_functions._init;
		this._init();
	}
};
			

