var scroll_timer; 

$(function() {
	$('<img />').attr('src', 'imgs/arrow_up_on.gif');
	$('<img />').attr('src', 'imgs/arrow_down_on.gif');

//	$('#image img').fadeIn(2400);
//	$('#content_background').show('drop', {direction:'left'}, 1000, function() {
//		$('#text_wrapper').fadeIn(1000);
		if ($('#text').height() > $('#text_wrapper').height()) $('#scroll_arrows').show();
//	});
});


function scroll_up(wait) {
	var scroll = parseInt($('#text').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($('#text').css('top')) || 0;
	if (scroll > $('#text_wrapper').height() - $('#text').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) {
	$('#text').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);
}

