﻿	var MINS_AGO = 0;
	var GUID = 1;
	var SUBJECT = 2;
	var PROBLEM = 3;
	var MAX_SESSIONS = 25;
	var WB_URL = "/Tools/PreviousSessionViewer/ThumbnailViewer.aspx?index=1&Scale=.27&SessionGUID="
	
	var m_Result = null;
	var m_Position = 0;
	var m_FlashVideoPlayer;

	function getRecentSessions()
	{
		RecentSessions.GetRecentSessions(onGetRecentSessions, onGetRecentSessionsFailed);
	}

	function onGetRecentSessions(result)
	{
		//initialize
		if (m_Result == null)
		{
			//if there are no sessions (dev only), result will be empty string
			if (result == "")
				return;

			//seeing a weird case where result is "-7"...
			if (!result || result.toString().substring(0, 1) == "-")
			{
				getRecentSessions();
				return;
			}

			m_Result = result;
		}
				
		/* Check whether the browser is IE. If so, m_FlashVideoPlayer is
		window.videoPlayer. Otherwise, it's document.videoPlayer. The
		videoPlayer is the ID assigned to the <object> and <embed> tags. */

		m_FlashVideoPlayer = (window.ActiveXObject) ? document.getElementById('RecentSessionsMovie') : document['RecentSessionsMovie'];

		if (!m_FlashVideoPlayer || !m_FlashVideoPlayer.InitializeSessions)
		{
			setTimeout(onGetRecentSessions, 500);
			return;
		}

		if (m_Result.length < 3)
			return;

		MAX_SESSIONS = m_Result.length;

		m_FlashVideoPlayer.InitializeSessions(
			WB_URL + m_Result[1][0],
			WB_URL + m_Result[2][0],
			WB_URL + m_Result[0][0],
			m_Result[1][1],
			m_Result[1][2],
			m_Result[1][3]);

		m_Position = 1;

		//start timer to spin wheel (wait 10 seconds for initial, since we loaded 3 wbs)
		setTimeout(loadRecentSession, 10000);			
	}

	var m_Continue = true;
	function SetContinue(val)
	{
		m_Continue = val;
	}

	function loadRecentSession()
	{
		if (m_Continue)
		{
			if (m_Position == MAX_SESSIONS - 2)
				m_Position = 0;
			else
				m_Position++;

			//load
			m_FlashVideoPlayer.LoadSession(
				WB_URL + m_Result[m_Position + 1][0],
				m_Result[m_Position][1],
				m_Result[m_Position][2],
				m_Result[m_Position][3]);
		}
		
		//start timer to spin wheel
		setTimeout(loadRecentSession, 7000);			
	}

	function onGetRecentSessionsFailed(result)
	{		
		//ignore	
	}

	function loadRecentSessionsMovie(divId)
	{		
		var html =
		'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="RecentSessionsMovie" width="400" height="230" align="middle">' +
			'<param name="allowScriptAccess" value="always" /><param name="wmode" value="transparent" /><param name="movie" value="/recentsessions/RecentSessions.swf" /><param name="quality" value="high" />' +
			'<embed src="/recentsessions/RecentSessions.swf" quality="high" wmode="transparent" name="RecentSessionsMovie" width="400" height="230" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" menu="false"/>' +
		'</object>'
		;
		
		var d = document.getElementById(divId);
		
		d.innerHTML = html;

		getRecentSessions();
	}
