/*var urls = ['images/topBar/res_0.jpg',
			'images/topBar/res_1.jpg',
			'images/topBar/res_3.jpg',
			'images/topBar/res_4.jpg',
			'images/topBar/res_5.jpg'];
var urls = [];
for(var i = 0; i<=140; i++)
	urls.push("images/topBar/Koningshof%20printformaat%20("+i+").jpg");
var shuffle = function(o){ //v1.0
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};
urls = shuffle(urls);*/
var shuffle = function(o){ //v1.0
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};

var detail = [2,4,5,7,8,70,71,78,79,90,91,92,93,94,95,97,98,113];
var normal = [0,1,3,6,9,10,14,15,23,26,64,65,66,67,68,69,72,73,74,75,76,77,80,81,82,83,84,85,86,87,88,89,96,99,100,101,102,103,104,105,106,107,108,109,110,111,112,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140];
detail = shuffle(detail);
normal = shuffle(normal);
var urls = [];
for(var l = normal.length, i=0;i<l;i++){
	if(i % 4 == 0)
		urls.push(detail[i/4]);
	else
		urls.push(normal[i]);
}
$(document).ready(function(){
	setInterval(topBar, 4800);
	var lastImg = 0;
	function removeOutOfBounds(){
		$this = $(this);
		if(Math.ceil($this.offset().top) >= $('#imageBar').height()){
			$this.remove();
		}
	}
	$('img.image').bind('removeOutOfBounds', removeOutOfBounds);
	function topBar(){
		var speed = 3000;
		//create the image
		var url = window.BASE_URL+"images/topBar/Koningshof%20printformaat%20("+urls[++lastImg]+").jpg";
		lastImg = lastImg<urls.length?lastImg:0;
		var $img = $(document.createElement('img'))
			.load(function(){
				$this = $(this);
				var width = this.width;
				$this
					.css("width", "0")
					.addClass('image')
					.insertBefore($('img.image:first'))
					.animate({width: width}, {duration: speed})
					.bind('removeOutOfBounds', removeOutOfBounds);
				$('img.image').trigger('removeOutOfBounds');
			})
			.attr('src', url);
	}
});
