var visible = true;
	loop = false;
	image='Error loading image.';
	productimageVisible = true;
	productimageFading = false;

    Event.observe(window, 'load', function() {
		startSlideshow.delay(3.0);
    });

	function switchImage() {
		new Ajax.Request('index.php', {
		  method: 'post',
		  postBody: 'productImageList=1',
		  onSuccess: function(transport) {
		    var notice = $('notice');
			image=transport.responseText;
			document.getElementById("doSlideshow").innerHTML = image;
		  }
		});
 	}

	function stopSlideshow() {
		loop = false;
	}

	function startSlideshow() {
		if (loop == false && productimageFading == false) {
			loop = true;
			loopSlideshow.delay(0.0);
		}
	}

	function loopSlideshow() {
		if (loop == true && productimageFading == false) {
			productimageFading = true;
			if (productimageVisible == true) {
				fadeout.delay(0.0);
				fadein.delay(2.4);
			} else {
				fadein.delay(2.4);
			}	
			switchImage.delay(1.3);
			loopSlideshow.delay(6.0);
		}
	}


    function fadein(){
        new Effect.Opacity("doSlideshow", {duration:1.3, from:0.0, to:1.0,
				afterFinish: function(){
					productimageVisible = true;
					productimageFading = false;
				}
			});
    }    
    function fadeout(){
        new Effect.Opacity("doSlideshow", {duration:1.3, from:1.0, to:0.0,
				afterFinish: function(){
					productimageVisible = false;
				}
			});
    }