//GLOBALS

var ids = new Array();
var currentItem = 0;
var	nrOfItems;

function switchItem()
{
	if(currentItem == nrOfItems)
	{	
		$("#" + ids[nrOfItems]).hide();
		$("#" + ids[0]).show();
		
		currentItem = 0;
		getTimer();
	}
	else
	{
	
		var nextItem = currentItem + 1;
		$("#" + ids[currentItem]).hide();
		$("#" + ids[nextItem]).show();
		
		currentItem ++;
		getTimer();
		
		
	}
}
function getTimer()
{
		timer=setTimeout("switchItem()",4000);
}

$(document).ready(function()
{	
	$.ajax( 
		  { 
			type: "POST", 
			url: "http://www.kuleuven.be/thomas/lib/scroller/scroller_data.php", 
			data: "q=" + "scrollerItems", 
			success: function(info) 
			{ 
				var info = info;
				$("#teaser").append(info);
				getIDs();
			}
		});
	
	function getIDs()
	{
		$.ajax( 
			  { 
				type: "POST", 
				url: "http://www.kuleuven.be/thomas/lib/scroller/scroller_data.php", 
				data: "q=" + "scrollerID", 
				success: function(info) 
				{ 
					var info = info;
					jQuery.trim(info);
					ids = info.split(";");
					
					hideScroller();	
				}
			});
	}

	function hideScroller()
	{		
		
	
		ids.pop();
		nrOfItems = ids.length - 1;
		
	
		for(var i = 0; i < ids.length; i++)
		{
			$("#" + ids[i]).hide();
		}
		
		$("#" + ids[0]).show();
		
		getTimer();
		
		
	}	
	

	
	
	
});
