var bannerPos = 0;
var bannerTimeout = null;
var bannerWidth = 230;
var bannersVisible = 2;
function scrollBanners(direction){
	clearTimeout(bannerTimeout);
	var direction = (!direction ? null : direction);
	var b = document.getElementById('banners');
	var bTotalWidth = b.scrollWidth;
	var bCount = bTotalWidth/bannerWidth;
	
	if(bTotalWidth > bannerWidth*bannersVisible){
		if(direction == "left" && bannerPos > -(bTotalWidth-bannerWidth*bannersVisible)){
			bannerPos -= bannerWidth;
		} else if (direction == "right" && bannerPos < 0){
			bannerPos += bannerWidth;
		}
	}
	
	if(parseInt(b.style.left) !== bannerPos){
		var step = (bannerPos-parseInt(b.style.left))/10;
		step = (step < 1 && step > 0 ? 1 : (step > -1 && step < 0 ? -1 : Math.round(step)));
		b.style.left = parseInt(b.style.left)+step+"px";
		bannerTimeout = setTimeout(scrollBanners, 10);
	}
}

var newsTimeout = null;
document.onmouseup = function (){
	clearTimeout(newsTimeout);
}

/*
function scrollNews(s){
	clearTimeout(newsTimeout);
	
	if(!s){
		return false;
	}
	
	var n = document.getElementById('news');
	var nb = document.getElementById('newsbox');
	var scrollAmount = n.scrollHeight-parseInt(nb.style.height);
	var newPos = parseInt(n.style.top)+s;
	newPos = (newPos < -scrollAmount ? -scrollAmount : (newPos > 0 ? 0 : newPos));
	n.style.top = newPos+"px";
	
	newsTimeout = setTimeout("scrollNews("+(s)+")", 10);
}
*/

function scrollNews(s){
    clearTimeout(newsTimeout);
    
    if(!s){
        return false;
    }
    
    var n = document.getElementById('news');
    var nb = document.getElementById('newsbox');
    var scrollAmount = n.scrollHeight-parseInt(nb.style.height);
    var newPos = parseInt(n.style.top)+s;
    newPos = (newPos < -scrollAmount ? -scrollAmount : (newPos > 0 ? 0 : newPos));
    if(scrollAmount > 0){
        n.style.top = newPos+"px";
    }
    
    newsTimeout = setTimeout("scrollNews("+(s)+")", 10);
}
