// AANPASSEN:

// scroll weer op 0 zetten nadat ie gescrollte heeft,
// paar seconden wachten met naar beneden scrollen

$(document).ready(function(){

	
	var blockwidth = $('.headline').width();

	
	var aantaldivs 	= $(".headline").length-2;
	if (aantaldivs > 0) {
	
		$("#scrollup").css('left','-176px');
		$("#scrollup").css('top','0px');
		setTimeout(function() {
			switchAdvertentie();
		}, 3000);
	}

});

var intervalsec	= 10000;
var id = 1;
var scrollsec	= intervalsec/6;


function switchAdvertentie() {
		
		var aantaldivs 	= $(".headline").length-2;
		
		// Checken of de advertnties weer vooraan moeten beginnen
		if (aantaldivs < id) {
			id = 0;	
			$("#scrollup").animate({"left": "0px"}, 1)
		}

		if (id > 1) {
			divid= id-1;	
		}else {divid = id;}
		
		
		
		var xposition = 0;
		var currentdiv = '.div'+divid;
		var blockheight = $(currentdiv).height();
		var bannerheight = $("#bannerholder").height();

		//$("#colourButton").html(currentdiv+' id: '+id+' divid: '+divid+'- <br/>blockheight: '+blockheight+' groter is dan '+bannerheight);
		
		
		// Als de tekst-div groter is dan de hoogte van het hokje, laat hem dan scrollen
		if (blockheight > bannerheight) {
			
			var moveheight = blockheight - bannerheight + 10;
			
			
			setTimeout('$("#scrollup").animate({"top": "-='+moveheight+'px"}, scrollsec);', 1*scrollsec);
			setTimeout('$("#scrollup").animate({"top": "+='+moveheight+'px"}, scrollsec);', 3*scrollsec);
		

		}

		setTimeout(function() {headline_rotate();}, 5*scrollsec);
		
		id++;
		
}



function headline_rotate() {
   var blockwidth = $('.headline').width();
   $("#scrollup").animate({"left": "-="+blockwidth+"px"}, scrollsec);
   setTimeout(function() {switchAdvertentie()}, 3000);
}
