// JavaScript Document

var scroll_timer;

$(window).load(function() {
	var img = new Image();
	img.src = 'imgs/arrow_up_on.gif';
	img.src = 'imgs/arrow_down_on.gif';

	$('#content_background').show('drop', {direction:'left'}, 1000, function() {
		$('#content_background').fadeTo(1000, 0.8);
		$('#links').fadeIn(1000);
		if ($('#links ul').height() > $('#links').height()) $('#scroll_arrows').show();
	});
});

function scroll_up(wait) {
	var scroll = parseInt($('#links ul').css('top')) || 0;
	if (scroll < 0) {
		if ($('#arrow_up').attr('src') != 'imgs/arrow_up_on.gif') $('#arrow_up').attr('src', 'imgs/arrow_up_on.gif');
		scroll_timer = setTimeout(function() {
			scroll_to(scroll + 1, 'up', wait);
		}, wait);
	} else scroll_stop('up');
}

function scroll_down(wait) {
	var scroll = parseInt($('#links ul').css('top')) || 0;
	if (scroll > $('#links').height() - $('#links ul').height()) {
		if ($('#arrow_down').attr('src') != 'imgs/arrow_down_on.gif') $('#arrow_down').attr('src', 'imgs/arrow_down_on.gif');
		scroll_timer = setTimeout(function() {
			scroll_to(scroll - 1, 'down', wait);
		}, wait);
	} else scroll_stop('down');
}

function scroll_to(scroll, direction, wait) {
	$('#links ul').css('top', scroll.toString() +'px');
	if (direction == 'up') scroll_up(wait);
	else scroll_down(wait);
}

function scroll_stop(direction) {
	if (direction == 'up') $('#arrow_up').attr('src', 'imgs/arrow_up_off.gif');
	else if (direction == 'down') $('#arrow_down').attr('src', 'imgs/arrow_down_off.gif');

	clearTimeout(scroll_timer);
}
