//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

// Constants for Page View States:

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

var CURRENT_VIEW_STATE = -1;

var VIEW_STATE_SLIDESHOW_VIEW = 0;

var VIEW_STATE_PANORAMA_VIEW = 1;

var VIEW_STATE_VIDEO_VIEW = 2;

var currentPanoramaImageIndex = -1;



//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

// Constants for Page Timer:

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

var TIMER_ID = null;

TIMER_INTERVAL = 1500;



//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

// Constants for Various DOM Element IDs:

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

var JID_FOR_DEBUG_ELEMENT = "div#debug";

var JID_FOR_SLIDE_SHOW_INTERVAL_RATE_CONTROL = "div#viewRateSlideshow";

var JID_FOR_SLIDE_SHOW_INTERVAL_DISPLAY = "span#slideShowInterval";

var DOM_ID_FOR_THICKBOX_DISPLAY_ELEMENT = "TB_window";



var JID_FOR_SLIDESHOW_TAB = "#tabSlides";

var JID_FOR_SLIDESHOW_CONTAINER = "div#slideViewer";

var JID_FOR_SLIDE_THUBNAIL_IMAGE_CONTAINER = "ul.sstnimages";

var JID_FOR_SLIDE_CAPTION_CONTAINER = "div#ssCaption";

var JID_FOR_SLIDE_SHOW_CYCLE_CONTAINER = "div#ssCycle";

var JID_FOR_SLIDE_RATE_CONTROL_CONTAINER = "div#slideshowControls";

var JID_FOR_SLIDESHOW_RATE_CONTROLS = "table#slideshowViewerControls";



var JID_FOR_PANO_TAB = "#tabPano";

var JID_FOR_PANO_CONTAINER = "div#panoViewer";

var JID_FOR_PANO_CONTAINER2 = "div#panoViewerContainer";

var JID_FOR_PANO_THUBNAIL_IMAGE_CONTAINER = "ul.sstnimages";

var JID_FOR_PANO_CYCLE_CONTAINER = "#panoViewer";

var JID_FOR_PANO_RATE_CONTROL_CONTAINER = "div#panoramaControls";

var JID_FOR_PANO_RATE_CONTROLS = "table#panoViewerControls";



var JID_FOR_VIDEO_TAB = "#tabVideo";

var JID_FOR_VIDEO_CONTAINER = "div#videoFileContainer";

var JID_FOR_VIDEO_PLAYER_CONTAINER = "div.video-media";



//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

// Constants for Audio Control:

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

var INITIAL_HEIGHT_OF_AUDIO_CONTROL = 20;

var INITIAL_WIDTH_OF_AUDIO_CONTROL = 300;

var CAN_AUTO_PLAY = true;



//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

// Constants for Video Control:

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
var INITIAL_HEIGHT_OF_VIDEO_CONTROL = 400;
var INITIAL_WIDTH_OF_VIDEO_CONTROL = 500;
// The margin-left offset should be (540 - INITIAL_WIDTH_OF_VIDEO_CONTROL) / 2. 
var INITIAL_MARGIN_LEFT_OFFSET_FOR_VIDEO_CONTROL = ((540 - INITIAL_WIDTH_OF_VIDEO_CONTROL) / 2) + "px";
var CAN_AUTO_PLAY = true;



//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

// Constants for Panorama Image Viewer:

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

var PANORAMA_FRAME_RATE_FACTOR = 0.010;

var MIN_PANORAMA_PAN_RATE = 1;

var MAX_PANORAMA_PAN_RATE = 20;

var PANORAMA_PAN_RATE_STEPPING = 1;        

var INITIAL_PANORAMA_PAN_RATE = 10; 

var CURRENT_PANORAMA_PAN_RATE = 10;



//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

// Constants for Slideshow Image Viewer:

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

var SLIDESHOW_TRANSITION_RATE_FACTOR = 4;

var MIN_SLIDESHOW_TRANSITION_RATE = 2000;

var MAX_SLIDESHOW_TRANSITION_RATE = 10000;

var SLIDESHOW_TRANSITION_RATE_STEPPING = 500;

var INITIAL_SLIDESHOW_TRANSITION_RATE = 5000;

var CURRENT_SLIDESHOW_TRANSITION_RATE = 5000;



//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

// BEGIN:  Define the slide show image transition effects:

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\	

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

// END:  Define the slide show image transition effects:

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\	



//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

// Function Name:  $(document).ready

// Purpose:  Binds a function to be executed whenever the DOM is ready

//           to be traversed and manipulated.

// Parameters:  function -- The function to be executed when the DOM is ready.

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

$(document).ready(function() 

{

	$('a.media').media({

		width: INITIAL_WIDTH_OF_AUDIO_CONTROL,

		height: INITIAL_HEIGHT_OF_AUDIO_CONTROL,

		autoplay: CAN_AUTO_PLAY,

		type: 'swf'

	});

	

	$('a.video-media').media({

		width: INITIAL_WIDTH_OF_VIDEO_CONTROL,

		height: INITIAL_HEIGHT_OF_VIDEO_CONTROL,		

		autoplay: CAN_AUTO_PLAY

	});



	$(JID_FOR_VIDEO_PLAYER_CONTAINER).css("margin-left", INITIAL_MARGIN_LEFT_OFFSET_FOR_VIDEO_CONTROL);



	// Initialize the navigation tabs.

	$("#tabContainer > ul").tabs(

	{

		fx: {

			opacity: 'toggle'

		},

		show: function(ui) {

			onTabShow(ui);

		}

	});

	

	// Initialize the panorama viewer rate slider control.

	$("#viewRatePanorama").slider({

		stepping:PANORAMA_PAN_RATE_STEPPING,

		min:MIN_PANORAMA_PAN_RATE,

		max:MAX_PANORAMA_PAN_RATE,

		startValue:INITIAL_PANORAMA_PAN_RATE,

		change:function(e, ui){alterViewerDisplayRate(ui.value);}

	});						

					

	// Initialize the slide show viewer rate slider control.

	$("#viewRateSlideshow").slider({

		stepping:SLIDESHOW_TRANSITION_RATE_STEPPING,

		min:MIN_SLIDESHOW_TRANSITION_RATE,

		max:MAX_SLIDESHOW_TRANSITION_RATE,

		startValue:CURRENT_SLIDESHOW_TRANSITION_RATE,

		change:function(e, ui){alterViewerDisplayRate(ui.value);}

	});		

	

    // Initialize the radio button control groups.

    $("input[@name='panoDirection']").click(function(){alterViewerDisplayRate(CURRENT_PANORAMA_PAN_RATE)});

    $("input[@name='isSlideShowEnabled']").click(function(){alterViewerDisplayRate(CURRENT_SLIDESHOW_TRANSITION_RATE);});	

	

	// Append the ramaining slide show image elements to the image element container.

	if ((SLIDE_SHOW_ELEMENT_DEFS != null) && (SLIDE_SHOW_ELEMENT_DEFS.length > 0))

	{

		$(JID_FOR_SLIDE_SHOW_CYCLE_CONTAINER).append(SLIDE_SHOW_ELEMENT_DEFS);

	}

	

	// Append the ramaining thumbnail slide show image elements to the image element container.

	if ((SLIDE_SHOW_THUMBNAIL_ELEMENT_DEFS != null) && (SLIDE_SHOW_THUMBNAIL_ELEMENT_DEFS.length > 0))

	{

		$(JID_FOR_SLIDE_THUBNAIL_IMAGE_CONTAINER).append(SLIDE_SHOW_THUMBNAIL_ELEMENT_DEFS);	

	}

	

	$("a[href='#tabPano'], a[href='#tabSlides'], a[href='#tabVideo']").click(function() {onTabShow($(this).attr("href"));});



	// Initialize the slide show transition rate.

	CURRENT_SLIDESHOW_TRANSITION_RATE = INITIAL_SLIDESHOW_TRANSITION_RATE;

	

	// Start in slideshow view mode.

	toggleView(VIEW_STATE_SLIDESHOW_VIEW, null);

	

	// Reinitialize any thickbox-enabled elements.

	tb_init("a.thickbox, area.thickbox, input.thickbox");

	

	// Poll at regular timer intervals.

	TIMER_ID = window.setInterval(onTimerPoll, TIMER_INTERVAL);

});



//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

// Function Name:  onExceptionThrown

// Purpose:  Provides a common exception handling function.  The exception

//			 data are displayed in a debuggine element if the element exists.

// Parameters:  e -- The exception that was thrown

//			    otherData -- Other custom data to display

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

function onExceptionThrown(e, otherData)

{

	try

	{

		// If the debug element exists, update the debug element contents.

		if ($(JID_FOR_DEBUG_ELEMENT) != null)

		{

			$(JID_FOR_DEBUG_ELEMENT).html("Exception:\n" + e + "\nOther Data:\n" + otherData);	

		}

	}

	catch (e)

	{}

}



//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

// Function Name:  onTimerPoll

// Purpose:  Provides a function to act as a callback for a specified

// 			 timer interval.

// Parameters: None

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

function onTimerPoll()

{

	try

	{

		switch (CURRENT_VIEW_STATE)

		{

			case (VIEW_STATE_PANORAMA_VIEW):

				{

					// Pause the cycle.

					$(JID_FOR_SLIDE_SHOW_CYCLE_CONTAINER).cycle("pause");

					

					break;	

				}

			case(VIEW_STATE_SLIDESHOW_VIEW):

				{		

					// Is the Thickbox display element present?

					if (document.getElementById(DOM_ID_FOR_THICKBOX_DISPLAY_ELEMENT) != null)

					{

						// Pause the cycle.

						$(JID_FOR_SLIDE_SHOW_CYCLE_CONTAINER).cycle("pause");

					}

					else

					{	

						// Resume the cycle.

						$(JID_FOR_SLIDE_SHOW_CYCLE_CONTAINER).cycle("resume");

					}

					

					break;

				}

			case (VIEW_STATE_VIDEO_VIEW):

			default:

			{

					// Pause the cycle.

					$(JID_FOR_SLIDE_SHOW_CYCLE_CONTAINER).cycle("pause");

					

					break;	

			}

		}

	}

	catch (e)

	{

		onExceptionThrown(e, "Exception in onTimerPoll()");

	}

}



//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

// Function Name:  onBeforeTabShown

// Purpose:  Provides a function to act as a callback before a slide is cycled.

// Parameters: None

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

function onBeforeTabShown()

{

	try

	{

		if ((this.title != null) && ($(JID_FOR_SLIDE_CAPTION_CONTAINER) != null))

		{

			// Update the slide caption using the anchor builder's title attribute.

			$(JID_FOR_SLIDE_CAPTION_CONTAINER).html(this.title);

		}

	}

	catch (e)

	{

		onExceptionThrown(e, "Exception in onBeforeTabShown()");

	}

}



//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

// Function Name:  createSlideShowCycle

// Purpose:  Creates a cycle for the slide show image container element.

// Parameters:  timeout -- The specified timeout value between slides

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

function createSlideShowCycle(timeout)

{

	try

	{

		$(JID_FOR_SLIDE_SHOW_CYCLE_CONTAINER).cycle({

			fx: "fade",

			speed: "fast",

			timeout: timeout,

			before: onBeforeTabShown,

			pager: JID_FOR_SLIDE_THUBNAIL_IMAGE_CONTAINER,

			pagerAnchorBuilder: function(index, slide)

			{

				// Use the first anchor for the <li> element specified by the current index.

				return JID_FOR_SLIDE_THUBNAIL_IMAGE_CONTAINER + " li:eq(" + index + ") a";

			}

		});

	}

	catch (e)

	{

		onExceptionThrown(e, "Exception in createSlideShow(timeout) with timeout = '" + timeout + "'");

	}

}



//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

// Function Name:  onTabShow

// Purpose:  Acts as the event handler for the tab navigation control

//		   when the show event is raised.

// Parameters:  tabLink -- The tab that is activated.

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

function onTabShow(tabLink) 

{

	try

	{	

		// Create a text version of the tabLink.

		var tabLinkText = tabLink + "";

		

		// Change the current view depending on the tab that was clicked.

		if (tabLinkText.indexOf(JID_FOR_SLIDESHOW_TAB) != -1)

		{

			toggleView(VIEW_STATE_SLIDESHOW_VIEW, 0);

		}

		else if (tabLinkText.indexOf(JID_FOR_PANO_TAB) != -1)

		{

			toggleView(VIEW_STATE_PANORAMA_VIEW, 0);

		}

		else if (tabLinkText.indexOf(JID_FOR_VIDEO_TAB) != -1)

		{			

			toggleView(VIEW_STATE_VIDEO_VIEW, 0);

		}

		

	}

	catch (e)

	{

		onExceptionThrown(e, "Exception in onTabShow(tabLink) with tabLink = '" + tabLink + "'");

	}	

}



//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

// Function Name:  alterViewerDisplayRate

// Purpose:  Alters the display rate for the viewer controls.  This may

//           be one of the following rates based on the current view:

//           VIEW_STATE_PANORAMA_VIEW -- Panorama Viewer Pan Rate

//           VIEW_STATE_SLIDESHOW_VIEW -- Slide Viewer Transition Rate

// Parameters:  newRate -- The new rate of display

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

function alterViewerDisplayRate(newRate)

{

	try

	{

		switch (CURRENT_VIEW_STATE)

		{

			case (VIEW_STATE_PANORAMA_VIEW):

				{

					CURRENT_PANORAMA_PAN_RATE = newRate;



					var frameRate = (newRate * PANORAMA_FRAME_RATE_FACTOR);



                    var panDirection = $("input[@name='panoDirection']:checked").val();



                    $("span#panRate").html(CURRENT_PANORAMA_PAN_RATE);

							

					// startAutoPan( pan_inc,  tilt_inc, zoom ) initiate autopanning. Each successive view's panangle is incremented 

					// by pan_inc, its tiltangle is incremented by tilt_inc, and its field of view is multiplied by zoom.

                    document.panoViewer.startAutoPan((frameRate * panDirection), 0.0, 1.0);

								 

					break;

				}

			case (VIEW_STATE_VIDEO_VIEW):

			{

				break;

			}

			case(VIEW_STATE_SLIDESHOW_VIEW):

			default:

				{

					// Convert the new rate to an integer.

					CURRENT_SLIDESHOW_TRANSITION_RATE = parseInt(newRate);

		

					// Convert from millisecond to seconds by dividing by 1000.

					$(JID_FOR_SLIDE_SHOW_INTERVAL_DISPLAY).html(CURRENT_SLIDESHOW_TRANSITION_RATE / 1000);

		

					// If the slideshow feature is enabled, set the new interval.

					if (($("input[@name='isSlideShowEnabled']:checked").val() == "1"))

					{

						// Start the slide show cycle.

						createSlideShowCycle(CURRENT_SLIDESHOW_TRANSITION_RATE);

					}

					else

					{

						// Stop the slide show cycle by specifying a zero timeout value.

						createSlideShowCycle(0);		

					}

					

		

					break;

				}

		}

	}

	catch (e)

	{

		onExceptionThrown(e, "Exception in alterViewerDisplayRate(newRate) with newRate = '" + newRate + "'");

	}		

}



//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

// Function Name:  toggleView

// Purpose:  Handles the transition between display states.

// Parameters:  

//             viewState -- The new view to prepare

//             initialData -- Initialization data for the view

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\            

function toggleView(viewState, initialData)

{

	try

	{	

		CURRENT_VIEW_STATE = viewState;

	

		switch (viewState)

		{

			case (VIEW_STATE_PANORAMA_VIEW):

				{

					// Hide the video viewer.

					$(JID_FOR_VIDEO_CONTAINER).hide();						

					

					// Hide the slideshow viewer.

					$(JID_FOR_SLIDESHOW_CONTAINER).hide();

					

					// Show the pano viewer.

					$(JID_FOR_PANO_CONTAINER).show();

					$(JID_FOR_PANO_CONTAINER2).show();	

					

					// Hide the slideshow rate control container.

					$(JID_FOR_SLIDE_RATE_CONTROL_CONTAINER).hide();

					

					// Show the panorama rate control container.

					$(JID_FOR_PANO_RATE_CONTROL_CONTAINER).show();

					

					// Show the panorama rate control container.

					$(JID_FOR_PANO_RATE_CONTROLS).show();

					

					// Store the revised image index.

                    currentPanoramaImageIndex = initialData;

										

					// Load the requested file in the panorama viewer.

					document.panoViewer.newPanoFromList(currentPanoramaImageIndex);

					

					alterViewerDisplayRate(CURRENT_PANORAMA_PAN_RATE);

					

					break;

				}

			case (VIEW_STATE_VIDEO_VIEW):

				{

					// Hide the slideshow viewer.

					$(JID_FOR_SLIDESHOW_CONTAINER).hide();

					

					// Hide the slideshow rate control container.

					$(JID_FOR_SLIDESHOW_RATE_CONTROLS).hide();

					

					// Hide the panorama rate control container.

					$(JID_FOR_PANO_RATE_CONTROLS).hide();

					

					// Hide the pano viewer.

					$(JID_FOR_PANO_CONTAINER).hide();	

					$(JID_FOR_PANO_CONTAINER2).hide();		

					

					// Show the video viewer.

					$(JID_FOR_VIDEO_CONTAINER).show();

					

					break;

				}

			case(VIEW_STATE_SLIDESHOW_VIEW):

			default:

				{

					// Hide the video viewer.

					$(JID_FOR_VIDEO_CONTAINER).hide();					

					

					// Hide the pano viewer.

					$(JID_FOR_PANO_CONTAINER).hide();	

					$(JID_FOR_PANO_CONTAINER2).hide();				

					

					// Initialize the radio button control groups.

					$("input[@name='isSlideShowEnabled']").click(function() {

						alterViewerDisplayRate(CURRENT_SLIDESHOW_TRANSITION_RATE);

					});							

					

					// Show the slideshow viewer.

					$(JID_FOR_SLIDESHOW_CONTAINER).show();

		

					// Show the slideshow rate control container.

					$(JID_FOR_SLIDE_RATE_CONTROL_CONTAINER).show();

					

					// Show the panorama rate control container.

					$(JID_FOR_SLIDESHOW_RATE_CONTROLS).show();

		

					// Hide the panorama rate control container.

					$(JID_FOR_PANO_RATE_CONTROL_CONTAINER).hide();

							

					// Synchronize the viewer display rate.

					alterViewerDisplayRate(CURRENT_SLIDESHOW_TRANSITION_RATE);

		

					break;

				}

		}

	}

	catch (e)

	{

		onExceptionThrown(e, "Exception in toggleView(viewState, initialData) with viewState = '" + viewState + "', initialData = '" + initialData + "'");

	}		

}
