var scrollTop;
var scrollBottom;

var speedFast = 500;
var speedSlow = 3000;

$(document).ready(function(){
	var item = $("#news_block .news_item");
	
	var itemTop = cssDimenssion(item.css("paddingTop"));
	var itemBottom = cssDimenssion(item.css("paddingBottom"));
	var itemHeight = cssDimenssion(item.css("height"));
	itemHeight = parseInt(itemHeight)+parseInt(itemTop)+parseInt(itemBottom);
	var viewHeight = cssDimenssion($("#news_block .news_list").css("height"));
	var itemCount = item.size();

	var scrollPx = (itemHeight * itemCount) - viewHeight + 20;
	scrollTop = "-"+scrollPx;
	scrollBottom = 0;

//up	
	$("#scroll_up").mouseup(function(){
		sptScrollContentStart('up', speedSlow);
    }).mousedown(function(){
    	sptScrollContentStart('up', speedFast);
    });
	
	$("#scroll_up").hover(function(){
		sptScrollContentStart('up', speedSlow);
	},function(){
		sptScrollContentStop();
	});
	
//down
	$("#scroll_down").mouseup(function(){
		sptScrollContentStart('down', speedSlow);
    }).mousedown(function(){
    	sptScrollContentStart('down', speedFast);
    });
	
	$("#scroll_down").hover(function(){
		sptScrollContentStart('down', speedSlow);
	},function(){
		sptScrollContentStop();
	});
});

cssDimenssion = function (dim)
{
	if ((dim) && (dim.length > 1))
		return dim.substr(0, dim.length-2);
	else
		return 0;
}


sptScrollContentStart = function (direction, speed)
{
	if (!direction || direction == "undefined")
	return false;
	
	if (direction == "down")
	{
		$("#news_block .news_list .scroller").stop();
		$("#news_block .news_list .scroller").animate({"marginTop": scrollTop+"px"}, speed);
	}
	else if (direction == "up")
	{
		$("#news_block .news_list .scroller").stop();
		$("#news_block .news_list .scroller").animate({"marginTop": scrollBottom+"px"}, speed);
	}
}

sptScrollContentStop = function()
{
	$("#news_block .news_list .scroller").stop();
}