var downTimeout = null;
var upTimeout = null;

$(document).ready(function() {
	$('body').supersleight();
	$("#sidebar-container").hover(
	    function () {
	    	$("#transparency").animate({left: "0px"}, 800);
	    	$("#sidebar-content").animate({left: "15px"}, 800);
	    },
	    function () {
	    	$("#transparency").animate({left: "-434px"}, 800);
	    	$("#sidebar-content").animate({left: "-419px"}, 800);
	    }
    );
	
	$content = $(".overflow");
	$holder_height = $("#content").height();
	
	if($holder_height < $content.height()) {
		$("#content").append('<div id="arrow_up"><span class="none">Up</span></div><div id="arrow_down"><span class="none">Down</span></div>');
	}
	
	$("#arrow_down").mousedown(function() {
		$height = $content.height();
		move_down();
	});
	$("#arrow_up").mousedown(function() {
		$height = $content.height();
		move_up();
	});
	$("#arrow_down").mouseup(function() {
		stop_down();
	});
	$("#arrow_up").mouseup(function() {
		stop_up();
	});
});

function move_down() {
	$current = $content.css("top");
	$length = $current.length;
	$current_int = parseInt($current.substring(0, $length - 2));
	$next_int = parseInt($current_int - 5);
	$next = $next_int + "px";
	if ($current_int > -$height + $holder_height) {
		$content.css("top", $next);
	}

	downTimeout = window.setTimeout("move_down()", 20);
}

function move_up() {
	$current = $content.css("top");
	$length = $current.length;
	$current_int = parseInt($current.substring(0, $length - 2));
	$next_int = parseInt($current_int + 5);
	$next = $next_int + "px";
	if ($current_int < 0) {
		$content.css("top", $next);
	}

	upTimeout = window.setTimeout("move_up()", 20);
}

function stop_down() {
	window.clearTimeout(downTimeout);
}

function stop_up() {
	window.clearTimeout(upTimeout);
}