var animate_event = navigator.appVersion.match(/msie[ ]?6/i) ? "load" : "domready";

window.addEvent(animate_event,function () 
{
	var timeout = 25;
	var offset = 1;
	var ticker = "ticker";

	var container_width = $(ticker).offsetWidth;
	var left_offset = container_width;

	// position all elements initially off the edge of the container
        $(ticker).getElements("dd").each(function(item, i)
		{
			// position first item differently from the rest
				item.setStyle("left", left_offset + "px");

			left_offset+= item.offsetWidth;

			item.setStyle("visibility", "visible");
        });

	// function to move the news items
		var DoTicker = function () 
		{
			var first = $(ticker).getFirst();

			// check where first story is
				if (parseInt(first.getStyle("left")) + first.offsetWidth < 0)
				{
					// get position of last one
						var last = $(ticker).getLast();
						var right = parseInt(last.getStyle("left")) + last.offsetWidth;

					// clone this one and then append to the end (either chain or if the last one is too far in, edge of container)
						var clone = first.clone();
						clone.setStyle("left", Math.max(right, container_width) + "px");

					clone.inject($(ticker), "bottom");
					first.dispose();
				}

			// move all items to the left
				$(ticker).getElements("dd").each(function(item)
				{
					var left = parseInt(item.getStyle("left"));
					item.setStyle("left", (left - offset) + "px");
				});
		}

	// run DoTicker every timeout milli-seconds
		var ticker_timeout = DoTicker.periodical(timeout);

	// add start and stop mouseover feature
		$(ticker).addEvent("mouseenter",function () 
		{
			$clear(ticker_timeout);
		});

		$(ticker).addEvent("mouseleave",function () 
		{
			if (ticker_timeout) $clear(ticker_timeout);
			ticker_timeout = DoTicker.periodical(timeout);
		});
});

