function initPlayer(tmpFormat)
{
	//Show first slide
	slide0.style.visibility = "visible";
	changeTab('Chapters');
	loopStatus		= setTimeout("GetPlayState()",800);
	loopTimer		= setTimeout("GetTime()",200);
	videoFormat		= tmpFormat;	//get the format we are using so we know how to talk to player
	PreviousTime	= 99999;	//set this so it'll never match where it just was (stops looping of slides at 0)
}

function getLayer(layerID) {
	if (document.getElementById)
		return document.getElementById(layerID);
	else if (document.all)
		return document.all[layerID];
	else 
		return null;
}

function filter(imageName,replaceWith)
{
	document.images[imageName].src = replaceWith;
}

function Play()
{
	if(videoFormat == "Real")
		document.VideoView.DoPlay();
	
	else if(videoFormat == "Windows Media")
		document.VideoView.Play();
}

function Pause()
{
	if(videoFormat == "Real")
		document.VideoView.DoPause();

	else if(videoFormat == "Windows Media")
		document.VideoView.Pause();
}

function Stop()
{
	if(videoFormat == "Real")
	{
		document.VideoView.DoStop();
		document.VideoView.SetPosition(0);
	}
	else if(videoFormat == "Windows Media")
	{
		document.VideoView.Stop();
		document.VideoView.CurrentPosition=0;
	}
}

function SetVolume(direction)
{
	if(videoFormat == "Real")
	{
		var oldVolume = document.VideoView.GetVolume();
		var newVolume;
		if(direction == "up")
		{
			newVolume = oldVolume + 5;
		}
		else if(direction == "down")
		{
			newVolume = oldVolume - 5;
			if (newVolume < 0)
				newVolume = 0;
		}
		document.VideoView.SetVolume(newVolume);
	}
	
	else if(videoFormat == "Windows Media")
	{
		var oldVolume = document.VideoView.Volume;
		var newVolume;
		if(direction == "up")
		{
			newVolume = oldVolume + 500;
			if (newVolume > 0)
				newVolume = 0;
			document.VideoView.Volume = newVolume;
		}
		else if(direction == "down")
		{
			document.VideoView.Volume = oldVolume - 500;
		}
	}
}

function GetPlayState()
{
	if(document.VideoView)
	{
		if(videoFormat == "Real")
		{
			//Get PlayState and set friendly name
			switch(document.VideoView.GetPlayState())
			{
				case 0:
					currentStatus	= "Stopped";
					break;
				case 1:
					currentStatus	= "Connecting";
					break;
				case 2:
					currentStatus	= "Buffering";
					break;
				case 3:
					currentStatus	= "Playing";
					break;
				default:
					currentStatus	= "Loading";
			}
		
		}
		else if(videoFormat == "Windows Media")
		{
			//Get PlayState and set friendly name
			switch(document.VideoView.PlayState)
			{
				case 0:
					currentStatus	= "Stopped";
					break;
				case 1:
					currentStatus	= "Paused";
					break;
				case 2:
					currentStatus	= "Playing";
					break;
				case 3:
					currentStatus	= "Buffering";
					break;
				default:
					currentStatus	= "Connecting";
			}
		}
		
		if (document.getElementById || document.all){
			statusLayer = getLayer("status");
			statusLayer.innerHTML = "<strong>"+ currentStatus +"</strong>";
		}
		loopStatus	= setTimeout("GetPlayState()",800);
	}
}

function jumpTo(timeToJump)
{
	if(videoFormat == "Real")
	{
		document.VideoView.SetPosition(timeToJump * 1000);
	}
	else if(videoFormat == "Windows Media")
	{
		//Make sure we're playing so we can jump
		if (document.VideoView.PlayState == 2)
		{
			document.VideoView.CurrentPosition = timeToJump;
			Play();
		}
	}
}

function changeTab(tabToChangeTo)
{
	if (getLayer(tabToChangeTo))
	{
		eval(tabToChangeTo +'.style.visibility = "visible";');
		eval(tabToChangeTo +'Nav.style.visibility = "visible";');
		eval('pnl'+ tabToChangeTo +'.style.visibility = "visible";');
		HideTabs(tabToChangeTo);
	}
}

function HideTabs(exceptThisOne)
{
	if (exceptThisOne == "Chapters")
	{
		Bios.style.visibility = "hidden";
		BiosNav.style.visibility = "hidden";
		pnlBios.style.visibility = "hidden";
		
		Reports.style.visibility = "hidden";
		ReportsNav.style.visibility = "hidden";
		pnlReports.style.visibility = "hidden";
	}
	else if (exceptThisOne == "Bios")
	{
		Chapters.style.visibility = "hidden";
		ChaptersNav.style.visibility = "hidden";
		pnlChapters.style.visibility = "hidden";
		
		Reports.style.visibility = "hidden";
		ReportsNav.style.visibility = "hidden";
		pnlReports.style.visibility = "hidden";
	}
	else if (exceptThisOne == "Reports")
	{
		Chapters.style.visibility = "hidden";
		ChaptersNav.style.visibility = "hidden";
		pnlChapters.style.visibility = "hidden";
		
		Bios.style.visibility = "hidden";
		BiosNav.style.visibility = "hidden";
		pnlBios.style.visibility = "hidden";
	}
}

function HandleSlides()
{
	//Go through slide array and see if we snag any of the items
	for(var i = 0; i < slideTimes.length; i++)
	{
		//alert(slideTimes[i] + " =? "+ CurrentTime);
		if(slideTimes[i] == CurrentTime)
		{
			eval('slide'+i+'.style.visibility = "visible";');
			var test = eval('document.images["chapter'+i+'"];');
			if (test)
				eval('document.images["chapter'+i+'"].src = "images/player/chapters/currentChapter.gif";');
			HideSlides(i);
		}
	}
}

function HideSlides(exceptThisOne)
{
	for(var i = 0; i < slideTimes.length; i++)
	{
		if(i != exceptThisOne)
		{
			eval('slide'+i+'.style.visibility = "hidden";');
			var test = eval('document.images["chapter'+i+'"];');
			if (test)
				eval('document.images["chapter'+i+'"].src = "images/spacer.gif";');
		}
	}
}

function GetTime()
{
	if(document.VideoView)
	{
	
		if(videoFormat == "Real")
		{
			var getTime		= document.VideoView.GetPosition()/1000;
			CurrentTime		= Math.floor(getTime*Math.pow(10,0))/Math.pow(10,0);
			if (CurrentTime != PreviousTime)
			{
				PreviousTime	= Math.floor(getTime*Math.pow(10,0))/Math.pow(10,0);
				HandleSlides();
			}
			var duration	= document.VideoView.GetLength() / 1000;
		}
		else if(videoFormat == "Windows Media")
		{
			var getTime		= document.VideoView.CurrentPosition;
			CurrentTime		= Math.floor(getTime*Math.pow(10,0))/Math.pow(10,0);
			if (CurrentTime != PreviousTime)
			{
				PreviousTime	= Math.floor(getTime*Math.pow(10,0))/Math.pow(10,0);
				HandleSlides();
			}

			var duration	= document.VideoView.Duration;
		}
	
		TotalTime		= Math.floor(duration*Math.pow(10,0))/Math.pow(10,0);
		TotalTime		= FormatTime(TotalTime);

		if (document.getElementById || document.all){
			timerLayer = getLayer("timer");
			timerLayer.innerHTML = "<strong>"+ FormatTime(CurrentTime) +" / "+ TotalTime +"</strong>";
		}
			
		loopTime	= setTimeout("GetTime()",200);
	}
}

function FormatTime(timeInSeconds)
{
	var minutes;
	var seconds;
	var newTime;
	
	minutes	= timeInSeconds/60;
	minutes	= Math.floor(minutes*Math.pow(10,0))/Math.pow(10,0);
	seconds	= timeInSeconds - (60*minutes);
	seconds	= Math.floor(seconds*Math.pow(10,0))/Math.pow(10,0);
	
	if (minutes < 10)
		minutes = "0"+ minutes;
	if (seconds < 10)
		seconds = "0"+ seconds;
	
	newTime = minutes +":"+ seconds;
	
	return newTime;
}