var defaultStep = 1;
var step = 1;
var height = 187;
var innerHeight;
var Newsticker = function() {
	//this.width = width;
	this.height = 187;
	this.speed = 100;
}

function scrollNews() {
	var container = document.getElementById("newsticker");
	var containerChildren = container.childNodes;
	var len = containerChildren.length;
	for (c = 0; c < len; c++) {
		with (containerChildren[c]) {
			if (containerChildren[c].style) {
				var reg = new RegExp('(.+?)px');
				var regRes = reg.exec(style.top);
				if (regRes != null) {
					var nTop = regRes[1];
				} else {
					nTop = 0;
				}
				if (nTop < -(innerHeight+height)) { 
					nTop = height;
				}
				style.position = 'relative';
				style.top = nTop - step + 'px';
				
			}
		}
	}
}

function stopScrolling(event) {
	step = 0;
}

function recoverScrolling(event) {
	step = defaultStep;
}

function repeatScroll() {
	var len = container.children.length;
	for (c = 0; c < len; c++) {
		with (container.children[c]) {
			if (style) {
				style.top = newsticker.height + 'px';
			}
		}
	}	
}

Newsticker.prototype.start = function() {
	this.container = document.getElementById("newsticker");
	var containerChildren = this.container.childNodes;
	var len = containerChildren.length;
	
	for (c = 0; c < len; c++) {
		if (containerChildren[c].style) {
			containerChildren[c].style.position = 'relative'; 
			containerChildren[c].style.zIndex = 100;
			containerChildren[c].style.top = this.height + 'px';
		}
	}
	
	this.container.style.visibility = 'visible';
	//this.container.style.position = 'relative';
	this.container.style.overflow = 'hidden';
	this.container.style.height = this.height + 'px';
	this.container.onmouseover = stopScrolling;
	this.calculateInnerHeight();
	this.container.onmouseout = recoverScrolling;
	
	setInterval('scrollNews()', this.speed);
	//scrollNews();
}

Newsticker.prototype.calculateInnerHeight = function() {
	var containerChildren = this.container.childNodes;
	var len = containerChildren.length;
	innerHeight = 0;
	for (c = 0; c < len; c++) {
		with (containerChildren[c]) {
			if (containerChildren[c].offsetHeight) {
				innerHeight += offsetHeight;	
			}
		}
	}
}

