var oMarquee;

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if (node == null)
		node = document;
	if (tag == null)
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (var i = 0, j = 0; i < elsLen; i++) {
		if (pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function init_windMarquee() {
	oMarquee = new Array();
	
	var outerEls = getElementsByClass('scrollOuter', document, 'div');
	var outerElsLen = outerEls.length;
	for (var i=0; i<outerElsLen; i++) {
		innerEls = getElementsByClass('scrollInner', outerEls[i], 'div');
		if (innerEls.length == 1) {
			oMarquee[i] = new windMarquee();
			oMarquee[i].init(outerEls[i], innerEls[0], 50, -1, i);
		}
	}
}

function windMarquee() {
	this.outerDiv = null;
	this.innerDiv = null;
	this.currentLocation = 0;
	this.outerWidth = null;
	this.innerWidth = null;
	this.speed = 0;
	this.dir = -1;
	this.enabled = false;
	this.timer = false;
	this.num = 0;
	
	this.init = _windMarquee_init;
	this.enable = _windMarquee_enable;
	this.disable = _windMarquee_disable;
	this.scroll = _windMarquee_scroll;
}

function _windMarquee_init(outerDiv, innerDiv, speed, dir, num) {
	this.innerDiv = innerDiv;
	this.outerDiv = outerDiv;
	this.innerWidth = this.innerDiv.offsetWidth;
	this.outerWidth = this.outerDiv.offsetWidth;
	this.currentLocation = 0;
	this.speed = speed;
	this.dir = dir;
	this.num = num;
	
	this.enable();
	
	this.outerDiv.onmouseover = function() { oMarquee[num].disable() };
	this.outerDiv.onmouseout = function() { oMarquee[num].enable() };
}

function _windMarquee_enable() {
	if (!this.enabled) {
		if (!this.timer) {
			this.timer = window.setInterval('oMarquee[' + this.num + '].scroll()', this.speed);
		}
		this.enabled = true;
	}
}

function _windMarquee_disable() {
	window.clearInterval(this.timer);
	this.enabled = false;
	this.timer = false;
}

function _windMarquee_scroll() {
	if (this.enabled) {
		var nextLocation = this.currentLocation + (3 * this.dir);
		if (this.dir > 0 && nextLocation > this.outerWidth + 3) {
			nextLocation = this.innerWidth - 3;
		}
		else if (this.dir < 0 && nextLocation < -this.innerWidth - 3) {
			nextLocation = this.outerWidth + 3;
		}
		
		this.currentLocation = nextLocation;
		
		this.innerDiv.style.left = nextLocation + 'px';
	}
}

if (window.addEventListener) {
	window.addEventListener('load', init_windMarquee, false);
}
else if (window.attachEvent) {
	window.attachEvent('onload', init_windMarquee);
}

