
// WINDOW GLOBAL VARIABLES /////////////////////////////////////////////////

// slideshow variables for the "At a glance" page
window.atAGlancePhotoIndex = 0;



// PAGE INITIALISATION /////////////////////////////////////////////////

function accommodationInitialise(){
	makeMediaDisplayInteractive();
	// cache the tab panels so that they're quicker to display
	tabPanelsCacheAll( "accommodationSection" );
	//tabPanelsDisplayFirst( "accommodationSection" );

	// if the user has arrived directly, then show the modal window to select when they are travelling
	if( $( "AccommodationSeasonSelectOverlay" ) != null ){
		displaySeasonSelectModalWindow();
	} else {
		// otherwise start the "At a glance" tab slideshow running
		// atAGlanceSlideshowStart();
	}
}



// SEASON SELECT MODAL OVERLAY FUNCTIONS ///////////////////////////////

function displaySeasonSelectModalWindow(){
	var modalWindow = $( "AccommodationSeasonSelectOverlay" );
	var modalWindowWidth = Element.getWidth( modalWindow );
	var modalWindowHeight = Element.getHeight( modalWindow );

	// show the transparent overlay over the whole page
	modalWindowOverlayShow();

	// put the modal window in the middle of the browser and show it
	positionElementInViewportCentre( modalWindow );
	modalWindow.style.display = "block";
}



// "AT A GLANCE" PHOTO SLIDESHOW FUNCTIONS //////////////////////////////////////////////

// the slideshow on the "At a glance" page is a lot simpler than the main one -
// it doesn't need to start or stop, just keeps cycling through the list of photos
function atAGlanceSlideshowStart(){
	
	var thumbnailList = $( "MediaThumbnailsList" );
	var thumbnailItems = $A( thumbnailList.getElementsByTagName( "LI" ) );
	
	if( thumbnailItems.length > 1 ){
		window.slideshowCounter = -1;

		atAGlanceSlideshowNext();
		window.slideshowTimerID = setInterval( atAGlanceSlideshowNext, window.slideshowTimeBetweenChange );
	}
}



function atAGlanceSlideshowNext(){
	
	var thumbnailList = $( "MediaThumbnailsList" );
	var thumbnailItems = $A( thumbnailList.getElementsByTagName( "LI" ) );

	// make sure that there's more than one image to display
	if( thumbnailItems.length > 1 ){
		// increment the slidehow counter
		window.slideshowCounter = (window.slideshowCounter + 1) % thumbnailItems.length;
		
		var mediaItem = thumbnailItems[window.slideshowCounter];
		//get the image details from the list
		var nextPhoto = mediaItem.childNodes.item(0);
		//set src and caption from the image in list
		$( "AccommodationAtAGlancePhoto" ).src = nextPhoto.src;
		$( "AccommodationAtAGlancePhoto" ).alt = nextPhoto.alt;
		Element.update( "AccommodationAtAGlancePhotoCaption", nextPhoto.alt );
	}

}
