window.onload = function() {
	// if (oldOnload) oldOnload();
	if ($$('body.home')) {
		if (typeof(CarouselImages) != 'undefined' && CarouselImages.length > 0) {
			var executer,swap,current = 0;
			var link = $('carousel');
			var controls = $('carousel-controls');
			var carouselControls = [];
			CarouselImages.each(function(image,index){
				if (!image) {
					CarouselImages = CarouselImages.slice(0,index);
					return;
				}
				CarouselImages[index] = new Element('img',{src:image});
				image = image.split('/').pop().split('.');
				image.pop();
				image = image.join('/');
				var control = new Element('a',{'className':'carousel-control',href:image.replace(/^[0-9]+-/,'')});
				control.observe('click',function(event){
					event.stop();
					current = index;
					swap(true);
				});
				carouselControls.push(control);
				controls.insert({top:control});
			});
			swap = function(newIndex) {
				if (newIndex) {
					executer.stop();
					executer = new PeriodicalExecuter(swap,5);
				}
				$$('#carousel-controls .active').each(function(activeControl){activeControl.removeClassName('active');});
				var control = carouselControls[current].addClassName('active');
				var image = CarouselImages[current++];
				link.insert(image.hide());
				image.appear({
					afterFinish:function(){
						link.href = control.href;
						link.setStyle({backgroundImage:"url('" + image.src + "')"});
						image.remove();
					}
				});
				if (current > CarouselImages.length - 1) current = 0;
			}
			swap();
			executer = new PeriodicalExecuter(swap,5);
		}
	}
}

var $delta = function(respondWith) { return respondWith; };