/*
	webQT.js
	----------
	
	File		:	webQT
	SuperClass	:	?
	Project		:	corporateSite
	Description :	Quicktime facilities. code extracted from example by apple.
	http://developer.apple.com/documentation/QuickTime/Conceptual/QTScripting_JavaScript/index.html#//apple_ref/doc/uid/TP40001526
 
 */


//var haveqt=false;
var _qtInterval;
var _qtProgressThumb;
var _qtProgressBar;
var _qtProgressDwl;
var _qtPlugInfo;
var _qtPlugInfoRefresh=true;
var _currentMovie;
var _refreshTime=500; 

/*
if (navigator.plugins) {
	for (i=0; i < navigator.plugins.length; i++ ) {
		if (navigator.plugins[i].name.indexOf("QuickTime") >= 0)
		{ haveqt = true; }
	}
}
*/

function updateMovieController() {
	var thumbSize=2;
	var curTime;
	
	if(_currentMovie && _currentMovie.GetPluginStatus()=="Complete") 
	{
		if(_qtPlugInfoRefresh) {
			_qtPlugInfo.innerHTML="...";
			_qtProgressDwl.style.width="320px";
		}
		if((_currentMovie.GetEndTime() - _currentMovie.GetTime())==0) {
			//alert("Movie is Finished !");
			StopMovie(_currentMovie);
		}
	}
	else
	{
		var dwlstat, curDwl;
		dwlstat=(_currentMovie.GetMaxBytesLoaded()/_currentMovie.GetMovieSize());
		curDwl=dwlstat * 320;
		dwlstat=dwlstat * 100;
		_qtProgressDwl.style.width=curDwl+"px";
		_qtPlugInfo.innerHTML=dwlstat+" %";
	}
	
	curTime=(_currentMovie.GetTime()/_currentMovie.GetEndTime()) * (320-thumbSize);
	_qtProgressThumb.style.left=curTime+"px";
}

function SetupMovieController(movie) {
	_currentMovie=movie;
	_qtProgressDwl=document.getElementById('qtprogressdwl');
	_qtProgressBar=document.getElementById('qtprogressbar');
	_qtProgressThumb=document.getElementById('qtprogressthumb');
	_qtPlugInfo=document.getElementById('qtpluginfo');
	if(!_qtProgressDwl || !_qtProgressBar || !_qtProgressThumb || !_qtPlugInfo) {
		alert("No Valuable Controller to refresh QtView");
	}
	
	_qtProgressDwl.style.width="0px";
	_qtProgressThumb.style.left="0px";
	_qtPlugInfo.innerHTML="Connecting... please wait...";
	_qtPlugInfoRefresh=true;
}
		
function PlayMovie(obj){
	if(!_currentMovie) {
		alert("No Current Movie. Please Load one.");
		return;
	}
	//alert(obj);
	obj.Play();
	//obj.SetRectangle("0, 0, 320, 240");
	_qtInterval=setInterval("updateMovieController()", _refreshTime);
}

function StopMovie(obj){
	//alert("Stopping Movie" + obj);
	clearInterval(_qtInterval);
	_currentMovie.Stop();
}

function SetMovieURL(obj, url){
		obj.SetKioskMode(false);
		obj.SetURL(url);
		obj.SetControllerVisible(false);
		obj.SetRectangle("0, 0, 320, 240");
		obj.SetBgColor("#ffffff");
		SetupMovieController(obj);
		obj.Rewind();
		PlayMovie(obj);
}
