var currentCount=1;
var imgCount=4;
var speed=.3;
var changeTime=8000;
var playing;
Event.observe(window, 'load', runGallery);

function runGallery(){
	playing=setTimeout("playImg()",changeTime);
}

function playImg(){
	new Effect.Fade("photoGallery"+currentCount,{
					duration:speed,
					afterFinish:function(){
							if(currentCount==imgCount) currentCount=1
							else currentCount++;
							clearHighlights();
							$("btn"+currentCount).addClassName("active");
							new Effect.Appear("photoGallery"+currentCount, {duration:speed})
						}
					});
	runGallery();
}

function changeImg(imgNum){
		clearTimeout(playing);
		clearHighlights();
		$("btn"+imgNum).addClassName("active");
		new Effect.Fade("photoGallery"+currentCount,{
					duration:speed,
					afterFinish:function(){
							currentCount=imgNum;
							new Effect.Appear("photoGallery"+imgNum, {duration:speed})
						}
					});
		runGallery();
		return false;
}

function clearHighlights(){
	for(i=1;i<=imgCount;i++) $("btn"+i).removeClassName("active")
}
