var scrollers = new Array();
var nextScrollerId = 0;
var isNS4 = (document.layers) ? true: false;

function makeScrolly(node, frameDelay, framePixelIncrement, stopOnMouseOver) {
	if (!frameDelay) { frameDelay = 10; }
	if (!framePixelIncrement) { framePixelIncrement = 1; }
	if (stopOnMouseOver != true && stopOnMouseOver != false) { stopOnMouseOver = true; }

	if (isNS4) {
		node.contentNode = node.document.layers[0];
	} else {
		node.contentNode = node.getElementsByTagName("DIV")[0];
	}

	node.frameDelay = frameDelay;
	node.framePixelIncrement = framePixelIncrement;
	node.stopOnMouseOver = stopOnMouseOver;
	
	node.isScroller = true;
	node.isPaused = false;
	node.scrollerId = nextScrollerId++;
	scrollers[node.scrollerId] = node;

	if (isNS4) {
		node.contentNode.left = node.document.width;
	} else {
		node.contentNode.style.left = "" + node.offsetWidth + "px";
		node.style.overflow = "hidden";
	}
	if (isNS4) {
		node.contentNode.clip.left = -node.document.width;
		node.contentNode.clip.right = node.contentNode.clip.top + node.document.width;
	}
	node.startScrolling = function() {
		this.timer = setInterval("scrollScroller(" + this.scrollerId + ")", this.frameDelay);
		if (isNS4) {
			this.contentNode.visibility = "show";
			this.visibility = "show";
		} else {
			this.contentNode.style.visibility = "visible";
			this.style.visibility = "visible";
		}
	}
	node.stopScrolling = function() {
		clearInterval(this.timer);
		if (isNS4) {
			this.contentNode.visibility = "hide";
		} else {
			this.contentNode.style.visibility = "hidden";
		}
	}
	node.pause = function() {
		this.isPaused = true;
	}
	node.resume = function() {
		this.isPaused = false;
	}
	node.scroll = function() {
		if (this.isPaused) {
			return;
		}
		// Move the content
		if (isNS4) {
			if (this.contentNode.left - this.framePixelIncrement < -this.contentNode.document.width) {
				this.contentNode.left = this.document.width;
			} else {
				this.contentNode.left -= this.framePixelIncrement;
			}
			this.contentNode.clip.left = -this.contentNode.left;
			this.contentNode.clip.right = this.contentNode.clip.left + this.document.width;

		} else {
			var currentLeft = parseInt(this.contentNode.style.left);
			if (this.contentNode.offsetWidth + (currentLeft - this.framePixelIncrement) < 0) {
				this.contentNode.style.left = "" + this.offsetWidth + "px";
			} else {
				this.contentNode.style.left = "" + currentLeft - this.framePixelIncrement + "px";
			}
		}
	}
	if (node.stopOnMouseOver) {
		if (isNS4) {
			node.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
		}
		node.onmouseover = function(evt) {
			this.pause();
		}
		node.onmouseout = function(evt) {
			this.resume();
		}
	}
}

function scrollScroller(scrollerId) {
	scrollers[scrollerId].scroll();
}

var originalOnload = window.onload;
var onloadHandlers = new Array();
window.onload = function() {
    if (originalOnload) {
        originalOnload();
    }
    init();
    for (var i = 0; i < onloadHandlers.length; i++) {
				onloadHandlers[i](this);
    }
}

function onLoadCall() {

	init();
    for (var i = 0; i < onloadHandlers.length; i++) {
				onloadHandlers[i](this);
    }
    
 }

function init() {
    var potentialScrollers;
    if (isNS4) {
        potentialScrollers = document.layers;
    } else {
        potentialScrollers = document.getElementsByTagName("DIV");
    }
    for (var i = 0; i < potentialScrollers.length; i++) {
        if (potentialScrollers[i].id.indexOf("scroller") == 0) {
	        makeScrolly(potentialScrollers[i], 30, 2, true);
        }
    }
	for (var i = 0; i < scrollers.length; i++) {
		scrollers[i].startScrolling();
	}
}

// Fix for Netscape 4 window resize bug.

var origWidth;
var origHeight;

if (isNS4) {
	origWidth  = window.innerWidth;
	origHeight = window.innerHeight;
	window.onresize = scrollerReload;
}

function scrollerReload() {
	if (origWidth == window.innerWidth && origHeight == window.innerHeight) {
    	return;
    }
	window.location.href = window.location.href;
}
