
var clipTop = 10;
var clipWidth = 200;
var clipBottom = 205;
var step = 1;
var topper = 0;
var lyrheight = theHeight = 0;
var theLayer = null;
var layerContent = null;
var amount,theHeight;

function initNewsticker() {
	theLayer = document.getElementById('news_content');
	if (!theLayer) {
		return;
	}
	initNewstickerSize();

	theHeight = lyrheight = theLayer.offsetHeight;
	theLayer.style.clip = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
	
	layerContent = theLayer.innerHTML;

	window.setInterval("scrollayer(" + step + ")", 125);
}

function initNewstickerSize() {
	var wrap = document.getElementById('news_wrap');

	if (wrap) {
		if (wrap.style && (wrap.style.width || wrap.style.height)) {
			if (wrap.style.width) {
				clipWidth  = parseInt(wrap.style.width);
			}
			if (wrap.style.height) {
				clipBottom = parseInt(wrap.style.height) - 5;
			}
		} else {
			for (var i = 0; i < document.styleSheets.length; i++) {
				var css   = document.styleSheets[i];
				var rules = (css.cssRules ? css.cssRules : css.rules);

				for (var j = 0; j < rules.length; j++) {
					if (rules[j].selectorText == '#news_wrap') {
						if (rules[j].style.width) {
							clipWidth  = parseInt(rules[j].style.width);
						}
						if (rules[j].style.height) {
							clipBottom = parseInt(rules[j].style.height) - 5;
						}
						return;
					}
				}
			}
		}
	}
}

function scrollayer(amt) {
	amount = amt;
	realscroll();
}

function realscroll() {

	clipTop    += amount;
	clipBottom += amount;
	topper     -= amount;
	
	if (clipTop >= (lyrheight - clipBottom)) {
		theLayer.innerHTML += layerContent;
		lyrheight += theHeight;
	}

	theLayer.style.clip = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0px)';
	theLayer.style.top = topper + 'px';
}