﻿
/* Functions for handling the animated slideshow marquee */

// PROPERTIES

// What marquee is currently selected?
var g_iSelectedMarquee = Number(1);

// How many marquees are there?
var g_iMarqueeCount = Number(6);

// The id of the timer for the slideshow
var g_iMarqueeTimerID = null;

// Were we playing?
var g_bPlaying = Boolean(false);

// FUNCTIONS

// Handle a click on a specific marquee
function MarqueeClick(iNewMarquee) {
	// Pause the slideshow, if any
	MarqueePauseSlideShow();
	
	// Hide the old marquee, if visible
	$("#EDC-default-marquee-"+g_iSelectedMarquee).fadeOut('normal');
	// Show the new marquee
	$("#EDC-default-marquee-"+iNewMarquee).fadeIn('normal');	
	// Store the visible marquee
	g_iSelectedMarquee = iNewMarquee;
}

// Show the next marquee in the slideshow
function MarqueeNext() {
	// Calculate the next marquee
	iNewMarquee = Number(g_iSelectedMarquee) + 1;
	iNewMarquee = ( iNewMarquee > g_iMarqueeCount ) ? 1 : iNewMarquee;

	// Hide the old marquee, if visible
	$("#EDC-default-marquee-"+g_iSelectedMarquee).fadeOut('normal');
	// Show the new marquee
	$("#EDC-default-marquee-"+iNewMarquee).fadeIn('normal');
	// Store the visible marquee
	g_iSelectedMarquee = iNewMarquee;

	// Continue the slideshow
	MarqueePlaySlideShow();
}

// Start the slideshow animation
function MarqueePlaySlideShow() {
	$(".EDC-default-marquee-nav").stop();

	// Clear the existing timer, if any
	if ( g_iMarqueeTimerID != null ) {
		clearTimeout(g_iMarqueeTimerID);
		g_iMarqueeTimerID = null;
	}
	
	// Update the UI
	g_bPlaying = true;
	MarqueeUpdatePlayPauseUI();
	
	// Set a timer to show the next marquee
	g_iMarqueeTimerID = setTimeout('MarqueeNext();',6000);
}

// Stop the slideshow animation
function MarqueePauseSlideShow() {
	$(".EDC-default-marquee-nav").stop();

	if ( g_iMarqueeTimerID != null ) {
		clearTimeout(g_iMarqueeTimerID);
		g_iMarqueeTimerID = null;
	}
	
	// Update the UI
	g_bPlaying = false;
	MarqueeUpdatePlayPauseUI();
}

// Temporarily pause the slideshow
function MarqueeHoverOverSlideShow() {
	if ( g_iMarqueeTimerID != null ) {
		clearTimeout(g_iMarqueeTimerID);
		g_iMarqueeTimerID = null;
		g_bPlaying = true;
	} else {
		g_bPlaying = false;
	}
}


// Resume the temporarily paused slideshow
function MarqueeHoverOutSlideShow() {
	if ( g_bPlaying ) {
		// Set a timer to show the next marquee
		g_iMarqueeTimerID = setTimeout('MarqueeNext();',4000);
	}
}

// Begin the slideshow animation
function MarqueeBegin() {
	g_bPlaying = true;
	// Show the first marquee
	$("#EDC-default-marquee-"+g_iSelectedMarquee).fadeIn('normal');
	// Start the slideshow
	MarqueePlaySlideShow();
}

// Updates the pause/play button visibility
function MarqueeUpdatePlayPauseUI() {
	// Update the UI
	document.getElementById('EDC-default-marquee-nav-play').style.display = ((g_bPlaying==true)?"none":"block");
	document.getElementById('EDC-default-marquee-nav-pause').style.display = ((g_bPlaying==true)?"block":"none");
}