		var thumbs = [];
		var preload = [];
		var current = 0;
		var rotation_timeout = 6500; // 5 seconds

		// init_thumbs();

		function init_thumbs(){
			new Ajax.Request('/frontpage_img_rotation/index.pl',
			{
				method: 'get',
				onSuccess: function(transport){
					var response = transport.responseText || '';
					eval('thumbs = ' + response);
					preload_images();
					/*setTimeout("rotate_image()",rotation_timeout);
					rotate_image();*/
					initial_image();
				},
				onFailure: function(transport){ alert("Something went wrong:\n" + transport.responseText) }
			});	
		}

		function preload_images(){

			/*alert('Preloading images');*/

			for(var i = 0; i < thumbs.length; i++){
				var photo = new Image();
				photo.src = '/frontpage_img_rotation/' + thumbs[i];
				preload.push(photo);
			}
		}

		function initial_image(){
			//$('rotation_img').src = preload[0].src;
			//setTimeout("rotate_image()",rotation_timeout);
			rotate_image();
		}

		function rotate_image(){		
			var rnd = Math.round(Math.random() * (preload.length - 1));

			var photo = preload[rnd];
			if(photo.complete && rnd != current){
				// place current one as background
				$('rotation_back').src = $('rotation_img').src;
				
					// place new as image - but opacity 0 (display none?)
					$('rotation_img').style.display = "none";
					$('rotation_img').src = photo.src;
					
					// fade in effect
					Effect.Appear(
						'rotation_img', 
						{
							duration: 2.5
						}
					);
				
				current = rnd;
	
				setTimeout("rotate_image()",rotation_timeout);

			}
			else {
				setTimeout("rotate_image()",50);
			}
		}