var currentSlide = 0;
var delay = 8000;
// something to hold the setInterval ID
var playingInterval;

//start my functions after the document has loaded
//document.observe('dom:loaded', function () {

	//hide all of the slideshow images	
	$$('#homeImage div').each(function(divimage){		
		if (divimage.id != 'ctl00_Main_homeImage0')
			$(divimage).hide();
	});

	//hide all of the slideshow hotel name	
	$$('#ctl00_Main_pnlHotelNames div').each(function(divhotel){		
		if (divhotel.id != 'ctl00_Main_homeHotelName0')
			$(divhotel).hide();
	});
	
	start_slideshow(0, numOfImages - 1, delay);
//});

//start_slideshow(0, numOfImages - 1, delay);
				
function cancelSlideshow() {
    if (playingInterval) {
        window.clearInterval(playingInterval);
        playingInterval = null;
    }
}

function start_slideshow(start_frame, end_frame, delay) {
	cancelSlideshow();				
                        
	var next = function () {
    switch_slides(start_frame, (start_frame+1) % numOfImages);
  }
  playingInterval = window.setInterval(next, delay);
}
						
function switch_slides(frame, targetframe) {
	  cancelSlideshow();
	  
//	  $('ctl00_Main_homeHotelName' +frame).style.display = "none";
	  
		new Effect.Parallel([		
			new Effect.Fade('ctl00_Main_homeHotelName' + frame, {sync: true, duration:8 } ),
			new Effect.Appear('ctl00_Main_homeImage' + targetframe, {sync: true, duration:8 } ),
			new Effect.Appear('ctl00_Main_homeHotelName' + targetframe, {sync: true, duration:8 } ),
			new Effect.Fade('ctl00_Main_homeImage' + frame, {sync: true, duration:8 } )
		], {
				delay: 0
		});
				
		currentSlide = targetframe;

		var next = function () {
    	switch_slides(targetframe, (targetframe+1) % numOfImages);
  	}
  	playingInterval = window.setInterval(next, delay);
}
			
function next_slide() {
    cancelSlideshow();            
    var next = function () {
       switch_slides(currentSlide, (currentSlide+1) % numOfImages);
    }
    next();
}

function previous_slide() {
		cancelSlideshow();
    var prev = function () {
        switch_slides(currentSlide, (currentSlide+numOfImages-1) % numOfImages);
    }
    prev();
}

