function slidePic(image,imgSource) {
	
	var nextSource = parseInt(imgSource) + 1;
	var nextImage;
	var src = '/wp-content/themes/lorenz/images/animation/foto' + nextSource + '.gif';
	
	if (image == 'photoA') { nextImage = 'photoB'; } else { nextImage = 'photoA'; }
	if (nextSource >= 8) { nextSource = 0; }

	$('#mask').animate({"left": "+=566px"}, 3000,'',function() { 
																	   $('#mask, #' + image).animate({"left": "-=566px"}, 3000, '', function() {
																		   $('#' + image).attr({"style":"left:0; z-index:1;","src":src});
																		   $('#' + nextImage).attr({"style":"z-index:10;"});
																	   });
																   });
	setTimeout("slidePic('" + nextImage + "','" + nextSource + "')",14000);
}

$(document).ready(function() {
	
	if ($('#photoMovie').length) {
		
		var adjustedHigh = (parseFloat(8) - parseFloat(1)) + 1;
        var numRand = Math.floor(Math.random()*adjustedHigh) + 1;
		var nextSource;
	
		if (numRand >= 8 ) { nextSource = 1; } else { nextSource = numRand + 1; }
		
		$('#photoMovie').append('<img id="mask" src="/wp-content/themes/lorenz/images/animation/foto0.png" alt="Lorenz sfeerbeeld" /><img id="photoA" src="/wp-content/themes/lorenz/images/animation/foto' + numRand + '.gif" alt="Lorenz sfeerbeeld" /><img id="photoB" src="/wp-content/themes/lorenz/images/animation/foto' + nextSource + '.gif" alt="Lorenz sfeerbeeld" />');
	
		setTimeout("slidePic('photoA'," + nextSource + ")",6000);
	}	
	
});
