var currentindex = 0;
var realstarttime = 0;
var realStatusPlaying = 3;
var watchdog = 0;
var TryToSeek = false;
var ms_delay = 4.387;
var rl_delay = 100;

// wait till playing before trying to seek
// Real will lock up otherwise, poll every 100 mSec
function RealPlay()
{
	if (top.rp.GetPlayState() == realStatusPlaying)
	{
		top.rp.SetPosition(realstarttime);
		TryToSeek = false;
	}
	else if (watchdog != 0)
	{
		--watchdog;
		setTimeout("RealPlay()", 100);
	}
	else TryToSeek = false;
}

// given the calling anchor object, the slidename and starttime
// try to set the current slide with the slidename
// try to set the current time in the media player
// set the index of the given anchor into the current index variable
function ProcessIndex(slidename, starttime)
{
	var errorcode;

	// do not try to seek if not done seeking (real player only)
	if (TryToSeek) return;

	if(typeof(top.Slider) != "undefined") top.Slider.SetSelectedSlideBStr(slidename);

	if(typeof(top.mp) != "undefined")
	{
		// 2002.09.28 BEGIN MOD by MCC [Cobia-JP-103]
		if (starttime > ms_delay) {
			//top.mp.CurrentPosition = starttime-ms_delay;
			top.mp.controls.CurrentPosition = starttime-ms_delay;
		}
		else {
			//top.mp.CurrentPosition = starttime;
			top.mp.controls.CurrentPosition = starttime;
		}
		//top.mp.Play();
		top.mp.controls.Play();
		// 2002.09.28 END MOD by MCC [Cobia-JP-103]
	}

	if(typeof(top.rp) != "undefined")
	{
		if (starttime > rl_delay)
			starttime = starttime - rl_delay;

		// if paused or stopped
		if (top.rp.CanPlay())
		{
			// start playing, but seek only after back playing again (poll every 100 mSec)
			top.rp.DoPlay();

			// try to seek for 15 tries (1.5 sec), then just give up
			TryToSeek = true;
			watchdog = 15;
			realstarttime = starttime - rl_delay;
			// 2002/10/09 BRGIN ADD by MCC COBIA-DB-079
			if( 0 > realstarttime ) {
				realstarttime = 0;
			}
			// 2002/10/09 BRGIN ADD by MCC COBIA-DB-079
			setTimeout("RealPlay()", 100);  
		}
		else if (top.rp.GetPlayState() == realStatusPlaying) top.rp.SetPosition(starttime);
	}

	// determine and set the current index
	for(i=0;i < indexlink.length;i++)
	{
		if(indexlink[i].name == slidename)
		{
			currentindex = i;
			break;
		}
	}
}

function ProcessNextIndex()
{
// 2002/09/26 BEGIN MOD by MCC
	if(typeof(indexlink.length) == "undefined") {
		if( "undefined" == typeof(indexlink.name) ) {
			return;
		}
		indexlink.click();
		indexlink.setActive();
		return;
	}
// 2002/09/26 END MOD by MCC

// 2002/09/26 BEGIN ADD by MCC cobia-us-087
	if( "undefined" != typeof(top.Slider) ) {
		currentindex = top.Slider.GetBookmarkSelectIndex(-1);
	}
// 2002/09/26 END ADD by MCC cobia-us-087

	// make the index wrap
	if(currentindex == (indexlink.length - 1)) currentindex = 0;
	else currentindex++;

	indexlink[currentindex].click();
	indexlink[currentindex].setActive();
}

function ProcessPrevIndex()
{
// 2002/09/26 BEGIN MOD by MCC
	if(typeof(indexlink.length) == "undefined") {
		if( "undefined" == typeof(indexlink.name) ) {
			return;
		}
		indexlink.click();
		indexlink.setActive();
		return;
	}
// 2002/09/26 END MOD by MCC

// 2002/09/26 BEGIN ADD by MCC cobia-us-087
	if( "undefined" != typeof(top.Slider) ) {
		currentindex = top.Slider.GetBookmarkSelectIndex(1);
	}
// 2002/09/26 BEGIN ADD by MCC cobia-us-087

	// make the index wrap
	if(currentindex == 0) currentindex = (indexlink.length - 1);
	else currentindex--;

	indexlink[currentindex].click();
	indexlink[currentindex].setActive();
}


