function newsScroll(direction) {
	var scrollAmount = direction * 10;
	var scrollDiv = document.getElementById('news-scroll');
	var scrollMax = scrollDiv.scrollHeight - scrollDiv.offsetHeight;
	scrollDiv.scrollTop += scrollAmount;
	if (scrollDiv.scrollTop == 0) {
		$('a#up-arrow').addClass('disabled');
	} else {
		$('a#up-arrow').removeClass('disabled');
	}
	if (scrollDiv.scrollTop == scrollMax) {
		$('a#down-arrow').addClass('disabled');
	} else {
		$('a#down-arrow').removeClass('disabled');
	}
	return false;
}
var columnsAdjusted = false;
function matchColumns() {
	// match column heights
	if (window.TOOLSCONTEXT_editFlags) return;
	if (columnsAdjusted) return;
	
	var diff = $('#content').height() - $('#sidebar').height();
	if (diff > 0) {
		columnsAdjusted = true;
		var addHeight = Math.floor(diff / $('div.sidebar-links a').length);
		var lineHeight = $('div.sidebar-links a').css('line-height');
		lineHeight = lineHeight.substr(0, lineHeight.length - 2) - 0 + addHeight;
		$('div.sidebar-links a').css('line-height', lineHeight + "px");
		diff = $('#content').height() - $('#sidebar').height();
		$('div.sidebar-links').height($('div.sidebar-links').height() + diff);
	}
}
$(function(){
	if (window.TOOLSCONTEXT_editFlags) return;
	
	// news scroller
	$('div#news-scroll').addClass('active');
	$('div#sidebar div.sidebar-links a:last').addClass('last');
	$('div#news-scroll-controls').html('<a id="up-arrow" href="#" class="disabled"><span>Up</span></a><a id="down-arrow" href="#"><span>Down</span></a>');
	$('a#up-arrow').click(function(){return newsScroll(-1)});
	$('a#down-arrow').click(function(){return newsScroll(1)});
	var scrollDiv = document.getElementById('news-scroll');
	scrollDiv.scrollTop = 0;
	
	matchColumns();
});
$(window).load(function(){
	matchColumns();
});
