var ms_step = 15;
var ms_timer;
var ms_x = 0;
var ms_wcon = 541;
var ms_browser = "";

if (navigator.appName.indexOf('Microsoft') != -1)
	ms_browser = "IE";
else if (navigator.appName.indexOf('Netscape') != -1)
	ms_browser = "NS";
else ms_browser = "FF";

DomReady.ready(initScroll);

function initScroll() {

    if (!document.getElementById('merkenScroller')) return;
    
    var ms_target = document.getElementById('scrollContent');
    var spanner = document.getElementById('spanner');
    if (ms_browser == "IE") spanner.style.width = spanner.offsetWidth + 10;
    ms_target.style.left = ms_x + 'px';
    ms_target.style.width = spanner.offsetWidth + 'px';
    
    /*
    setCookie('pos', 10);
    ms_x = getCookie('pos');
    if(ms_x == null){
    ms_x = 10;
    setCookie('pos', ms_x);
    }
    */     
}

function scroll(dir) {
	var ms_target = document.getElementById('scrollContent');
	if(ms_browser == "IE")	var w = (ms_target.offsetWidth * -1) + (ms_wcon / 1.2);
	else var w = (ms_target.offsetWidth * -1) + (ms_wcon / 1.5);
	if(dir < 0){
		if(ms_x <= w){
			scrollStop();
			return;
		}
		else{
			ms_x-=parseInt(ms_step);
			ms_target.style.left = ms_x + 'px';
			//setCookie('pos',ms_x);
			ms_timer = setTimeout('scroll(-1)',50);
		}
	}
	if(dir > 0){
		if(ms_x > (ms_wcon/3)){
			scrollStop();
			return;
		}
		else{
			ms_x+=parseInt(ms_step);
			ms_target.style.left = ms_x + 'px';
			//setCookie('pos',ms_x);
			ms_timer = setTimeout('scroll(1)',50);
		}
	}
}

function scrollStop(){
	clearTimeout(ms_timer);
}

function getCookie(sName)
{
    var aCookie = document.cookie.split('; '), i = aCookie.length, aCrumb;
    while (i--)
    {
         aCrumb = aCookie[i].split('=');
        if (sName == aCrumb[0])
            return typeof aCrumb[1] != 'undefined'? unescape(aCrumb[1]) : null;
    }

    return null;
}

function setCookie(sName, sValue)
{
    document.cookie = sName + '=' + escape(sValue) + '; expires=Fri, 31 Dec 2099 23:59:59 GMT; path=/';
}
	


