


// INITIALIZATION FUNCTIONS ////////////////////////////////////////////

function promotionsMediaInitialize(){
	makeMediaDisplayInteractive();
}



// DESTINATIONS CAROUSEL ///////////////////////////////////////////////

// select the next link after the currently selected one, wrapping around at the end of the list
function destinationCarouselNext(){
	var selection = destinationCarouselGetSelection();
	var nextIndex = (selection.selected + 1) % selection.total;
	destinationCarouselSelect( nextIndex );
}


// select the previous link before the currently selected one, wrapping around at the beginning of the list
function destinationCarouselPrevious(){
	var selection = destinationCarouselGetSelection();
	var previousIndex = (selection.selected + (selection.total - 1)) % selection.total;
	destinationCarouselSelect( previousIndex );
}


// select a particular link
function destinationsCarouselSelectLink( link ){
	var link = $( link );
	var previousLinks = Element.previousSiblings( link.parentNode );
	var linkIndex = previousLinks.length;
	destinationCarouselSelect( linkIndex );
}


// get an array of all the destination links
function destinationCarouselGetDestinations(){
	var destinationList = $( "DestinationCarouselDisplayDestinations" );
	if( destinationList == null ){ return null; }

	var destinations = Element.immediateDescendants( destinationList );
	return destinations;
}


// find out which destination link is selected, and how many links there are in total
function destinationCarouselGetSelection(){
	var destinations = destinationCarouselGetDestinations();
	var selectedIndex = 0;

	// run through the links to see which one is currently selected
	for( var i = 0; i < destinations.length; i++ ){
		if( Element.hasClassName( destinations[i], "selected" ) ){
			selectedIndex = i;
		}
	}

	return { selected: selectedIndex, total: destinations.length };
}


// select a carousel link by its index
function destinationCarouselSelect( index ){
	var destinations = destinationCarouselGetDestinations();

	// run through all the destination links and make sure that the "selected"
	// class is only applied to the correct link
	for( var i = 0; i < destinations.length; i++ ){
		if( i == index ){
			Element.addClassName( destinations[i], "selected" );
		} else {
			Element.removeClassName( destinations[i], "selected" );
		}
	}

	// get the information relevant to the particular link
	var destinationData = destinationCarouselData[index];

	// update the display to show the information for the link
	Element.update( "DestinationCarouselDisplayImageTitleResort", destinationData.resort.toUpperCase() );
	Element.update( "DestinationCarouselDisplayImageTitleLocation", destinationData.location.toUpperCase() );
	$( "DestinationCarouselDisplayImage" ).src = destinationData.image;
	$( "DestinationCarouselDisplayImage" ).alt = destinationData.resort + ", " + destinationData.location;
	Element.update( "DestinationCarouselDisplayResortNarrative", destinationData.narrative );
}

////////////////////////////////////////////////////////////////////////
