/* Javascript to create rotating carousel */

// -----------------------
// FUNCTION: fCarouselClick
// DESCRIPTION: A function to move to selected (item) display and swap all classes
// ARGUMENTS: item
// RETURN: None
// -----------------------
function fCarouselClick(item) {
	clearInterval(CarouselRotatingTimer); // clear any existing counters
	// loop though each element in carousel and switch everything to OFF state
	for (i = 1; i <= 4; i++) {
		fChangeClassName('carousel-main-splash-'+i, 'access-text'); // hide main image
		fChangeClassName('carousel-thumb-'+i, 'overflow-hidden cursor-hand off-carousel-thumb'); // set thumb state to off
		// if element is LO carousel (contains teaser) switch to off state
		if (itemTypesArray[i - 1] == "LO")
		{
			fChangeClassName('carousel-teaser-'+i, 'off-carousel-teaser');
		} else {
			fChangeClassName('carousel-overlay-'+i, 'off-carousel-overlay');
		}
	}
	// switch selected element to ON
	fChangeClassName('carousel-main-splash-'+item, 'display-block'); // turn on main image
	// if selected item is LO carousel turn teaser state to on
	if (itemTypesArray[item - 1] == "LO") 
	{
		fChangeClassName('carousel-teaser-'+item, 'on-carousel-teaser');
	} else { // for hi carousel, turn thum to on state
		fChangeClassName('carousel-thumb-'+item, 'overflow-hidden cursor-hand on-carousel-thumb');
		fChangeClassName('carousel-overlay-'+item, 'on-carousel-overlay');
	}
	StartRotateAt = item; // set next click to users selected item
	CarouselRotatingTimer = setInterval("fRotateCarousel()",CarouselRotatingTime); // reset timer
}

// -----------------------
// FUNCTION: fRotateCarousel
// DESCRIPTION: A function to rotate carousel
// ARGUMENTS: item
// RETURN: None
// -----------------------
function fRotateCarousel() {
	StartRotateAt++; // get next item in carousel
	if (StartRotateAt >= 5) StartRotateAt = 1; // go back to 1 if we reach the end
	fCarouselClick(StartRotateAt); // change classNames for selected carousel item
}