var t;
function slideshow(start, last) {
	if (start > last) start = 1;
	if (start < 1) start = last;
	var interval = 7000;
	var frame = start;
	var nextframe = start+1;
	if (nextframe > last) nextframe = 1;
	if (nextframe < 1) nextframe = last;
	new Effect.Appear('img'+frame,{duration:0.5,from:0.0,to:1.0 });
	t = setInterval(function() {
		new Effect.Parallel([
			new Effect.Fade('img'+frame,{from:1.0,to:0.0,afterSetup:function(){
				//$('img'+frame).hide();
				new Effect.Appear('img'+nextframe,{duration:1.0,from:0.0,to:1.0 });
				frame = nextframe;
				//nextframe = (frame == last) ? 1 : nextframe+1;
			}}),
			new Effect.Fade('bug'+frame,{from:1.0,to:0.0,afterSetup:function(){
				//$('bug'+frame).hide();
				new Effect.Appear('bug'+nextframe,{duration:1.0,from:0.0,to:1.0 });
				frame = nextframe;
				//nextframe = (frame == last) ? 1 : nextframe+1;
			}})
		], { duration: 1.0, delay: 0.0, afterFinish:function() {
			nextframe = (frame == last) ? 1 : nextframe+1;
		} });
	},interval);
	return;
}
function initSlides(n) {
	var slideCount = $$('body.home #header a.header-img').length;
	slideshow(n, slideCount);
	new Effect.Parallel([
     	new Effect.Move($('bug1'), { sync: true, x: 0, y: 0, mode: 'absolute' }),
     	new Effect.Appear($('bug1'), { sync: true, from: 0, to: 1 })
	], { duration: 2.0, delay: 0 });
}
