<!--
/////////////////////////////
// © Leo Koivistoinen 2005 //
/////////////////////////////

var newsdiv;
var helper;
var helper2;
var container;
var timer;
var helperwidth;
var good = (document.getElementById) ? true : false;
var first = true;
var fromleft;
var fromtop;
var rightside = fromleft + helperwidth;
var allover = fromleft - rightside;
var currentposition = rightside;

function tickinit() {

	if(good) {

		helper = document.images['nhelp'];
		helper2 = document.images['nhelp2'];
		newsdiv = document.getElementById('uutiset').style;
		container = document.getElementById('container').style;

		fromleft = getLeft(helper);
		fromtop = getTop(helper);
		helperwidth = helper.width;
		helper2width = helper2.width;

		container.width = helperwidth+'px';
		container.left = fromleft+'px';
		container.top = fromtop+5+'px';
		container.visibility = "visible";

		rightside = helperwidth;
		allover = 0 - helper2width;
		currentposition = rightside;
	
		timer = setInterval('tick()', 30);

		if(getCookie('scroller') == 'no') {
			 
			clearInterval(timer);
			container.display = "none";

		}

	} else {

		//

	}

}

function rehash() {

	if(good) {

		clearInterval(timer);

		fromleft = getLeft(helper);
		//fromtop = getTop(helper);
		helperwidth = helper.width;

		container.width = helperwidth+'px';
		container.left = fromleft+'px';
		//container.top = fromtop-8+'px';

		rightside = helperwidth;
		allover = 0 - helper2width;
		
		if(currentposition > rightside) currentposition = rightside;

		timer = setInterval('tick()', 30);

	}

}


function stop() {

	clearInterval(timer);
	timer = setInterval('tick()', 50);

}

function togglescroller(domain) {
	
	if(container.display == "none") {

		container.display = "block";
		rehash();
		document.cookie = "scroller=yes; path=/; domain=." + domain;

	} else {

		clearInterval(timer);
		container.display = "none";
		document.cookie = "scroller=no; path=/; domain=." + domain;

	}

}

function start() {

	clearInterval(timer);
	timer = setInterval('tick()', 30);

}

function getLeft(ll) {
	
	if (ll.offsetParent) return (ll.offsetLeft + getLeft(ll.offsetParent));
	else return (ll.offsetLeft);

}

function getTop(ll) {
	
	if (ll.offsetParent) return (ll.offsetTop + getTop(ll.offsetParent));
	else return (ll.offsetTop);

}

function tick() {

	if(helperwidth != helper.width) rehash();

	currentposition = currentposition - 1;
	
	if (currentposition < allover) currentposition = rightside;

	cl = fromleft - currentposition;
	cr = rightside - currentposition;
		
	newsdiv.left = currentposition+"px";
	
	if (first) { newsdiv.visibility = "visible"; first = false; }

}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

// -->
