// image rotate script
// (c) 2006 QSC Audio
// set var img_obj (name of image to swap)
// var img_seq (Array) front to back series
// var timing (speed factor, smaller= faster
imgtimeout = null;

function rotate(){
	if(img_seq && img_seq.length > 0){
		clearTimeout(imgtimeout); 
		if(direction == 1){
			step ++;
			if(step<img_seq.length){
				swap(img_seq[step],direction);
			} else {
				// reached the end, reverse direction for next click
				step = img_seq.length-1;
				direction = 0;
				swaplabel('img_button',1);
			}
			
		} else {
			step --;
			if(step>=0){
				swap(img_seq[step],direction);
			} else {
			// reached the end, reverse direction for next click
				step = 0;
				direction = 1;
				swaplabel('img_button',0);
			}
		}
	}

}
function swap(newsrc,direction){
	img = document.images[img_obj];
	if(img){
		testimg = new Image();
		testimg.src = newsrc;
		if(testimg.complete){ // checking that the next image has loaded
			img.src = newsrc;
			if(direction){
				imgtimeout = setTimeout('rotate(1)',100*(timing/100));
			} else {
				imgtimeout = setTimeout('rotate(0)',100*(timing/100));
			}
		} else {
			// jump directly to final image
			if(direction){ 
				img.src =img_seq[img_seq.length-1];
				step = 0
				direction = 1;
				swaplabel('img_button',0);
			} else {
				img.src =img_seq[0];
				step = img_seq.length-1;
				direction = 0;
				swaplabel('img_button',1);
			}
			
		}
	}
}

