/***********************************************
 * Cross browser Marquee II- © Dynamic Drive (www.dynamicdrive.com)
 * This notice MUST stay intact for legal use
 * Visit http://www.dynamicdrive.com/ for this script and 100s more.
 ***********************************************/
// gik: was hideously ugly, cleaned up so that at least it's encapsulated
// also now works with nodes that have dynamic content...

/**
 * marquee: Makes an element 'marquee' vertically (scroll down to bottom, then reset)
 *
 * In order for this not to look dumb, we need the element immediately inside the
 * container element. The container element should have a fixed height. If the 
 * content element is larger than the container element, the content element
 * will marquee.
 *
 * If the size of the content or parent element change, the marquee will reset to
 * the top.
 * 
 * @param el The content element to marquee.
 * @param speed The speed of marquee when the mouse is not hovering over it
 * @param pauseSpeed The speed of marquee when the mouse hovers over it
 * @param delayBeforeScroll how long to wait before starting scrolling
 */
function marquee(el, speed, pauseSpeed, delayBeforeScroll) {
	var self = this;

	self.alwaysScroll = true;
	self.speed = (typeof(speed) == "undefined") ? 1 : speed;
	self.defaultSpeed = self.speed; // for pause/unpause
	self.pauseSpeed = (typeof(pauseSpeed) == "undefined") ? 0 : pauseSpeed;
	self.element = el;
	self.delayBeforeScroll = (typeof(delayBeforeScroll) == "undefined") ?
		1000 : delayBeforeScroll; 

	self.scroll = function() {
		if (self.lastHeight != self.element.offsetHeight ||
			self.lastParentHeight != self.element.parentNode.offsetHeight) {
			self.lastHeight = self.element.offsetHeight;
			self.lastParentHeight = self.element.parentNode.offsetHeight;
			self.reset();
		} else if (self.alwaysScroll || self.lastHeight >= self.lastParentHeight) {
			if (parseInt(self.element.style.top) > (self.lastHeight*(-1)+8)) {
				self.element.style.top = 
					(parseInt(self.element.style.top) - self.speed)+"px";
			} else { 
				self.element.style.top = (parseInt(self.lastParentHeight)+8)+"px";
			}
		} // else parent's larger than us, so no marquee
	}

	self.reset = function() { self.element.style.top = "0px"; }

	self.initialize = function() {
		self.element.style.top=0;
		self.element.parentNode.style.overflow = "hidden";
		self.element.style.position = 'relative';
		if (navigator.userAgent.indexOf("Netscape/7")!=-1) { 
			self.element.style.overflow="scroll";
			self.element.style.height = self.element.parentNode.style.height;
			return;
		}
		setTimeout(function() { 
				setInterval(function() { self.scroll(); }, 30) 
			}, self.delayBeforeScroll);
		add_event_handler(self.element, 'mouseover', self.pause);
		add_event_handler(self.element, 'mouseout', self.unpause);
	}

	self.pause = function() { self.speed = self.pauseSpeed; }
	self.unpause = function() { self.speed = self.defaultSpeed; }

	self.element.myMarquee = self;
	add_event_handler(window, 'load', self.initialize);

	return self;
}

