var posts = new Array();
var timer = null;
var rotateInterval = 10000;

function initializePosts(id)
{
	var postsElement = document.getElementById(id);
	if(postsElement == null || !postsElement || postsElement == 'undefined')
		return;

	for(i = 0; i < postsElement.childNodes.length; i++) 
		if(postsElement.childNodes[i].className == "post")
			posts[posts.length] = postsElement.childNodes[i].id;

	Element.observe(postsElement, 'mouseover', holdScroll);
	Element.observe(postsElement, 'mouseout', resumeScroll);
	timer = setTimeout('rotatePosts()', rotateInterval);
}

function holdScroll()
{
	if(timer != null || timer == "undefined")
		clearTimeout(timer);
}
function resumeScroll()
{
	timer = setTimeout('rotatePosts()', rotateInterval);
}

function rotatePosts()
{
	var obj = document.getElementById('postscanvas');
	var top = obj.style.top;
	if(top == null || top == "undefined")
		top = 0;
	else
		top = top.replace('px', '');

	if(top == getPostsMaxDown()) {
		moveAllDown();
	} else {
		moveUp();
	}

	timer = setTimeout('rotatePosts()', rotateInterval);
}

function getPostsMaxDown() {
	var obj = document.getElementById('postscanvas');
	var maxdown = -1 * ((posts.length-1) * 120);
	return maxdown;
}
function moveUp() {
	var obj = document.getElementById('postscanvas');
	new Effect.Move(obj, {x: 0, y: -120 });
}
function moveDown() {
	var obj = document.getElementById('postscanvas');
	new Effect.Move(obj, {x: 0, y: 120 });
}
function moveAllDown() {
	var obj = document.getElementById('postscanvas');
	var maxdown = -1 * getPostsMaxDown();
	new Effect.Move(obj, {x: 0, y: maxdown});
}
function moveAllUp() {
	var obj = document.getElementById('postscanvas');
	var maxdown = getPostsMaxDown();
	new Effect.Move(obj, {x: 0, y: maxdown});
}

function initializeProgramma() {
	var canvas = document.getElementById('canvas');
	var currentDate = new Date();
	var startDate = new Date(2010, 7, 26);
	var endDate = new Date(2010, 8, 7);

	if(currentDate <= startDate)
		return;
	if(currentDate >= endDate)
		return;

	var day = currentDate.getDate();
	if(currentDate.getMonth() == 8)
		day = day + 5;
	else
		day = day - 26;

	new Effect.Move(canvas, {x: 0 + (day * -490), y: 0});
}
function naarBegin() {
	var canvas = document.getElementById('canvas');
	var x = $('canvas').style.left.replace('px', '');
	var offset = 0 - x;
	new Effect.Move(canvas, {x: offset, y: 0 });
}
function naarEinde() {
	var canvas = document.getElementById('canvas');
	var x = parseInt($('canvas').style.left.replace('px', ''));
	var offset = (-5880 - x);
	if(isNaN(offset))
		offset = -5880;
	new Effect.Move(canvas, {x: offset, y: 0 });
}
function gisteren() {
	var canvas = document.getElementById('canvas');
	var x = $('canvas').style.left.replace('px', '');
	if(x >= 0)
		return;
	new Effect.Move(canvas, {x: 490, y: 0 });
}
function morgen() {
	var canvas = document.getElementById('canvas');
	var x = $('canvas').style.left.replace('px', '');
	if(x <= -5880)
		return;
	new Effect.Move(canvas, {x: -490, y: 0 });
}
