var curSld=-1;
var WMPTimer;var CheckDataTimer = -1;
var CheckPlayStateTimer = -1;
var TimerID;
var d=document;

function ScriptReady(){
	var ScrPath;
	ScrPath=(scriptdata.src).toLowerCase();
	clearTimeout(CheckDataTimer);
	if(scriptdata.readyState!="complete" && scriptdata.readyState!="loaded" ){
		CheckDataTimer=setTimeout("ScriptReady()",1000);
 		}
	else{
		if (bPreview && ScrPath.lastIndexOf("datatable.js")>0||!bPreview&&!(bNT && ScrPath.lastIndexOf("datatable.js")< 0)){
			if(d.all["LogoImg"]&&g_Logo)
				d.all["LogoImg"].src = g_Logo;
			if(d.all["TitleDiv"]&&g_Title)
				d.all["TitleDiv"].innerHTML=TitleFont+"<b>"+ g_Title +"</b></font>";
			if(d.all["PresenterDiv"]&&g_Presenter)
				d.all["PresenterDiv"].innerHTML=PresenterFont+ g_Presenter +"</font>";
			if(d.all["IntroDiv"]&&g_Intro)
				d.all["IntroDiv"].innerHTML=IntroFont + g_Intro +"</font>";
			if(d.all["TimeDiv"]&&g_Duration){
				ts="0:00:00"+"/"+GetTimeStr(g_Duration);
				d.all["TimeDiv"].innerHTML=TimeFont+ ts +"</font>";
				};
			if(g_AutoStart) {
				window.setTimeout("MediaPlayer_Play()",2000);
				};
			if(StrArray && d.all["DocDiv"])
				window.setTimeout("InitializeMarkers()",1);
			}
		else CheckDataTimer=setTimeout("ScriptReady()",1000);
		}
	}
	
function RestartTimer(){
	if (WMPTimer){
		if(WMPTimer != null){
			clearTimeout(WMPTimer);
			WMPTimer = null;
			}
		}
	if(d.all["TimeDiv"]){
		WMPTimer = setTimeout("SetTimeStr()",1000);
		}
	}
	
function SetTimeStr(){
	if((PreviewStarted || !bPreview)&& !bEnd){
		ts=GetTimeStr(GetCurrentPosition());
		ts+="/";
		ts+=GetTimeStr(GetDuration());
		d.all["TimeDiv"].innerHTML=TimeFont+ ts +"</font>";
	}
	RestartTimer();
}

function DivResize(){
	var t2;
	var i;
	if((d.body.clientWidth) >= (tt.style.posWidth)){
		t1=(d.body.clientWidth-tt.style.posWidth)/2-parseInt(tt.style.left);
		for(i = 0;i< d.all.length; i++){ 
			if(d.all(i).tagName =="DIV"){
				if(d.all(i).style.width != ""){
					t2=d.all(i).style.posLeft;
					d.all(i).style.left=t1+t2;
					}
				}
			if(d.all(i).tagName =="IFRAME"){
				if(d.all(i).style.width != ""){
					t2=d.all(i).style.posLeft;d.all(i).style.left=t1+t2;
					}
				}
			}
		}
	}
	
function MediaPlayer_Create(MWidth,MHeight,MPUI7,MPUI6){
	var _B="";
	var MediaPath = window.location.href;
	if(MediaPath.substring(0, 8).toLowerCase() == "file:///"){
		MediaPath = "file://" + MediaPath.substring(8,MediaPath.toLowerCase().lastIndexOf("/web/"));
		MediaPath += "/index.asx";
		}
	else{
		MediaPath =MediaPath.substring(0,MediaPath.toLowerCase().lastIndexOf("/web/"));
		MediaPath += "/index.asx";
		}
	var pWMP=null;
	try{
		if(bMP7)
			pWMP=new ActiveXObject("WMPlayer.OCX.7");
		if(!pWMP)
			throw e;
		pWMP=null;
		_B="<OBJECT classid=CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6 width="+MWidth+" height="+(MHeight-0)+" id=MediaPlayer name=MediaPlayer type=application/x-oleobject standby=\"\"><PARAM NAME=\"URL\" VALUE=\"\"><PARAM NAME=\"autoStart\" VALUE=\"0\"><PARAM NAME=\"invokeURLs\" VALUE=\"0\"><PARAM NAME=\"baseURL\" VALUE=\"\"><PARAM NAME=\"volume\" VALUE=\"60\"><PARAM NAME=\"mute\" VALUE=\"0\"><PARAM NAME=\"uiMode\" VALUE=\""+MPUI7+"\"><PARAM NAME=\"enabled\" VALUE=\"-1\"><PARAM NAME=\"enableContextMenu\" VALUE=\"-1\"></OBJECT>";
		PlayerDiv.innerHTML=_B;
		if(bPreview)
			MediaPlayer.URL="";
		else
			MediaPlayer.URL=unescape(MediaPath);
		}
		catch(e){
			pWMP=new ActiveXObject("MediaPlayer.MediaPlayer.1");
			try{
				if(!pWMP)
					throw e;
				pWMP=null;
				bMP7=0;	
				_B="<OBJECT ID=\"MediaPlayer\" name=\"MediaPlayer\" width="+MWidth+" height="+(MHeight-20)+" CLASSID=\"CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95\" STANDBY=\"Loading Windows Media Player components...\" TYPE=\"application/x-oleobject\"><PARAM NAME=\"ShowControls\" VALUE=\""+MPUI6+"\"> <PARAM NAME=\"AutoRewind\" VALUE=\"False\"><PARAM NAME=\"AutoStart\" VALUE=\"false\"><PARAM NAME=\"FileName\" VALUE=\"\"></OBJECT>";
				PlayerDiv.innerHTML=_B;
				if(bPreview){
					MediaPlayer.FileName="";
					CheckPlayStateTimer=setTimeout("CheckPlayState()",1000);
					}
				else
					MediaPlayer.FileName=unescape(MediaPath); 
				}
				catch(e){
					alert("No MediaPlayer");
					}
				}
			}
			
function MediaPlayer_PlayStateChange(lOldState,lNewState){
	if(d.btnPlay)
		d.btnPlay.src="play-up.gif";
	if(d.btnPause)
		d.btnPause.src="pause-up.gif";
	if(d.btnStop)
		d.btnStop.src="stop-up.gif";
	if((bMP7&&lOldState==3)||(!bMP7&&lNewState==2)){
		TimeID=window.setInterval("SldShow()",300);
		PreviewStarted=true;
		RestartTimer();
		if(d.btnPlay)
			d.btnPlay.src="play-gray.gif";
		}
		else if((bMP7&&lOldState==2)|| (!bMP7&&lNewState==1)){
			if(TimerID) window.clearInterval(TimerID);
			if(d.btnPause)d.btnPause.src="pause-gray.gif";
		}
		else if((bMP7&&(lOldState==1||lOldState==10))|| (!bMP7&&lNewState==0)){
			if(TimerID) window.clearInterval(TimerID);
			if(WMPTimer!=null&&d.all["TimeDiv"]) {
				clearTimeout(WMPTimer);
				WMPTimer=null
				}
			if(d.btnPause)
				d.btnPause.src="pause-gray.gif";
			if(d.btnStop)
				d.btnStop.src="stop-gray.gif";
			}
		}

function CheckPlayState(){
	clearTimeout(CheckPlayStateTimer);
	try{
		if((!bMP7 && MediaPlayer.PlayState==2)){
			window.setInterval("SldShow()",300);PreviewStarted=true;
			}
		}
	catch(e) {
		CheckPlayStateTimer=setTimeout("CheckPlayState()",1000);
		}
	}
	
function FindMarker(){
	var nPos;
	var mNum=StrArray.length;
	if(MediaPlayer_IsPlaying()){
		nPos=GetCurrentPosition()*1000;
		if(curSld>=0){
			if(StrArray[curSld].mMark >nPos){
				for(j=0;j<mNum;j++){
					if(j< mNum-1){
						if(StrArray[j].mMark<nPos && nPos<StrArray[j+1].mMark)
							return j; 
							}
						else{
							if(StrArray[j].mMark<nPos)
								return j;
							}
						}
					}
					for(j=curSld;j<mNum;j++){
						if(j< mNum-1){if(StrArray[j].mMark<nPos && nPos<StrArray[j+1].mMark)
							return j;
						}
						else{
							if(StrArray[j].mMark<nPos)
								return j;
							}
						}
					}
				else {
					nPos=GetCurrentPosition()*1000;
					for(j=0;j<mNum;j++){
						if(j< mNum-1){
							if(StrArray[j].mMark<nPos && nPos<StrArray[j+1].mMark)
								return j;
							}
							else{
								if(StrArray[j].mMark<nPos)
									return j;
								}
							}
						}
					}
					else { 
						nPos=GetCurrentPosition()*1000;
						var tmp;
						for(j=0;j<mNum;j++){
							if(j< mNum-1){
								if(StrArray[j].mMark<=nPos && nPos<StrArray[j+1].mMark){
									return j;
									}
								}
								else{
									if(StrArray[j].mMark<=nPos)
										return j;
									}
								}
							}
							return -1;
						}

function SldShow(){
	var findSld=FindMarker();
	if(findSld>-1){
		if(findSld!=curSld){
			curSld=findSld;
 			var mType=(StrArray[findSld].mType);
			switch(mType){
				case 1:
					if(d.all["sldImg"]){
						d.all["sldImg"].src=StrArray[findSld].mSldHref;
						if(!bHtmlStandAlone) {
							d.all["PPTTop"].style.visibility="hidden";
							}
						d.all["SldDiv"].style.visibility="visible";
					}
					break;
				default:
					if(d.all["PPTTop"]){
						d.frames("PPTTop").document.frames("PPTSld").location.href=StrArray[findSld].mSldHref;
						if(!bHtmlStandAlone){
							d.all["SldDiv"].style.visibility="hidden";
							}
						d.all["PPTTop"].style.visibility="visible";
						}
					break;
					}
				}
			}
		}

function OnPreviousClicked(){
	var iMax; 
	iMax=StrArray.length;   
	if(curSld>0){
		OnMarkerClicked(curSld-1);
		}
	}

function OnNextClicked(){
	var iMax; 
	iMax=StrArray.length;
	if(curSld<(iMax-1)){
		OnMarkerClicked(curSld+1);
		}
	}

function EnlargeSld(){
	var	WebPath = window.location.href;
    if(bPreview){
		alert("This function is unavailable in preview mode!");
		return;
		};
    if (WebPath.substring(0, 8).toLowerCase() == "file:///")
		WebPath = "file://" + WebPath.substring(8,WebPath.lastIndexOf("/"));
	else
        WebPath = WebPath.substring(0,WebPath.lastIndexOf("/"));
		WebPath +="/pptview.htm";
		if(curSld>-1){
			try{
				if(newwin.closed){
					newwin=window.open(unescape(WebPath),'newwin1','screenX=0,screenY=0,directories=0,fullscreen=0,width=720,height=540,location=0,menubar=0,scrollbars=0,status=0,toolbar=0,resizable= 1');
  				}
			}
			catch(e){  
				newwin=window.open(unescape(WebPath),'newwin1','screenX=0,screenY=0,directories=0,fullscreen=0,width=720,height=540,location=0,menubar=0,scrollbars=0,status=0,toolbar=0,resizable= 1');
 				}
			try{
				newwin.document.frames("PPTSld").location.href=StrArray[curSld].mSldHref;
				}
			catch(e){
				window.setTimeout("ReloadAgain()",800);
				}
			}
		}

function ReloadAgain(){
	try{ 
		newwin.document.frames("PPTSld").location.href=StrArray[curSld].mSldHref; 
		} 
	catch(e){
		window.setTimeout("ReloadAgain()",800);
		}	
	}

function PrintSld(){
	d.frames("PPTTop").document.frames("PPTSld").focus();
	d.frames("PPTTop").document.frames("PPTSld").print();
	}
	
function OnMarkerClicked (marker){
	if(CurrentMedia_CanSeek()){
		var npos=StrArray[marker].mMark;
		SetCurrentPosition(npos/1000);
		if(!PreviewStarted){
			MediaPlayer_Play();
			}
		}
		else {
			window.status="Current Media does not seekable!"; 
			}
		} /*end OnMarkerClicked() */

function InitializeMarkers(){
	var iMax, x; 
	iMax=StrArray.length;
	if (iMax > 0) {
		for (x = 0; x < iMax; x++){
			if(bMP7 || (!bMP7 && MediaPlayer.CanSeek))
				d.all["DocDiv"].innerHTML+=("<IMG border=0 height=9 src='../../images/menuitem.gif' width=9><span onclick='javascript:OnMarkerClicked(" + x + ")' onmouseover=\"this.style.cursor='hand'\">"+TocFont + StrArray[x].mName + "</FONT></span><BR>");
			else
				d.all["DocDiv"].innerHTML+=("<IMG border=0 height=9 src='../../images/menuitem.gif' width=9>"+TocFont + StrArray[x].mName + "</FONT><BR>");
			}
		}
		else
			d.all["DocDiv"].innerHTML+=("No Markers");
		}

function GetTimeStr(tm){
	hour=Math.floor(tm/3600);
	min=Math.floor((tm%3600)/60);
	sec=Math.floor(tm%60);
	szTime=hour+":";
	if(min<10)
		szTime+="0";
	szTime+=min+":";
	if(sec<10)
		szTime+="0";
	szTime+=sec;
	return szTime;
	}
	
function GetCurrentPosition(){
	try{
		if(bMP7)
			return d.MediaPlayer.controls.currentPosition;
		else
			return d.MediaPlayer.CurrentPosition;
		}
	catch(e){
		}
	}
	
function SetCurrentPosition(npos){
	if(bMP7)
		d.MediaPlayer.controls.currentPosition=npos;
	else
	return d.MediaPlayer.CurrentPosition=npos;
	}

function GetDuration(){
	try{
		if(bMP7)
			return d.MediaPlayer.currentMedia.Duration;
		else
			return d.MediaPlayer.Duration;
		}
	catch(e){
		}
	}

function MediaPlayer_Play(){
	var _PS=MediaPlayer.PlayState;
	if(bMP7){
		if(_PS==1||_PS==2||_PS==10){ 
			MediaPlayer.Controls.Play();
			return 1;
			}
		return 0;
		}
	else{ 
		if(_PS==0||_PS==1){
			MediaPlayer.Play();
			return 1;
			}
		return 0;
		}
	}
	
function MediaPlayer_Pause(){
	var _PS=MediaPlayer.PlayState; 
	if(bMP7){
		if(_PS==1||_PS==10){
			MediaPlayer.Controls.Pause();
			return 1;
			}
		else if(_PS==3){
			MediaPlayer.Controls.Pause();
			return 1;
		}
	return 0;
	}
	else{
		if(_PS==0){
			MediaPlayer.Play();
			MediaPlayer.Pause();
			return 1;
			}
		else if(_PS==2){
			MediaPlayer.Pause();
			return 1;
			}
		return 0;
		}
	}

function MediaPlayer_IsPlaying(){
	try{
		var _PS=MediaPlayer.PlayState;
		}
	catch(e){
		return 0;
		}
	if(bMP7){
		if(_PS==3)
			return 1;
		}
	else if(!bMP7){
		if(_PS==2)
			return 1;
		}
	return 0;
	}
	
function CurrentMedia_CanSeek(){
	if(bMP7){
		if(MediaPlayer.controls.isAvailable("CurrentPosition"))
		return 1; 
		else{
			if(MediaPlayer.PlayState==10||MediaPlayer.PlayState==0)
				return 1;
			}
		}
	else if(!bMP7){
		if(MediaPlayer.CanSeek)
			return 1;
		}
	return 0;
	}

function MediaPlayer_Stop(){
	if(bMP7)
		MediaPlayer.Controls.Stop();
	else
		MediaPlayer.Stop();
}
