
function getObject(o,dom)
{
	if (dom == null) dom = document;
	if (typeof (dom.o) == 'object') {return o;}
	else return dom.getElementById(o);
}

function playMovieInterface(playerObject,type)
{
	if (type==2) 
		playerObject.controls.play(); 
	else  	playerObject.DoPlay();
}

function getMovieInterfaceLocation(playerObject,type)
{
	p=-1;
	if (type==2) 
		p = playerObject.Controls.currentPosition; 
	else 	playerObject.DoPlay();
	return(p);
}

function setMovieInterfaceLocation(p,playerObject,type)
{
	if (type==2) 
		playerObject.controls.currentPosition=p; 
	else 	playerObject.DoPlay();
	return(p);
}

function getMovieInterfaceDuration(playerObject,type)
{
	var d = 0;
	if (type==2) 
		d = playerObject.currentMedia ? playerObject.currentMedia.duration : -1;
	else 	playerObject.DoPlay();
	return(d);
}


function getMovieInterfaceVolume(playerObject,type) 
{
	v=100;
	if (type==2) 
		v =  playerObject.Settings.volume; 
	else 	v = playerObject.DoPlay();
	return(v);
}

function setMovieInterfaceVolume(v,playerObject,type) {
	if (type==2) 
		playerObject.Settings.volume = v; 
	else	v = playerObject.DoPlay();
}


function pauseMovieInterface(playerObject,type)
{
	if (type==2) 
		playerObject.controls.pause();
	else	playerObject.DoPause(); 
}


function stopMovieInterface(playerObject,type)
{
	if (type==2)
		playerObject.controls.stop(); 
	else	playerObject.DoStop(); 
}


function getBufferingPercent(playerObject,type) {
	if (type==2)
		return playerObject.Network.bufferingProgress;
  	else
  		return playerObject.BufferingProgress;
}

var StatusText = [ "Stopped", "Paused", "Playing", "Waiting", "Scan Forward", "Scan Reverse", "Skip Forward", "Skip Reverse", "Closed" ];

//function GetOpenState(playerObject,type) { if (type == 2) return playerObject.openState; else  return playerObject.OpenState; }
//function IsBuffering(playerObject,type) {  if (type == 2)    return playerObject.playState == 6; else  return 0; }
function IsValid(playerObject,type) {  if (type == 2)  return typeof(playerObject.playState) != "undefined"; else  return typeof(playerObject.PlayState) != "undefined";}


function getStatusMessage(playerObject,type) 
{
	if (!IsValid(playerObject,type))
		return "Initializing";
	if (type == 2 && playerObject)
		return playerObject.status;
}


function loadMovieInterface(src,wframe,w,h,pType)
{
//	alert("player1.html?pType="+pType+"&src="+src+"&width="+w+"&height="+h+"&autostart=1");
	wframe.location.href = "/videos/player1?pType="+pType+"&src="+src+"&width="+w+"&height="+h+"&autostart=1&d="+(new Date());
//	getObject('debug').innerHTML="/videos/player1?pType="+pType+"&src="+src+"&width="+w+"&height="+h+"&autostart=1";
}

function unLoadMovieInterface(src,wframe)
{
	wframe.location.href = src;
//	getObject('debug').innerHTML=src;
}

function setMovieURL(playerObject,u,type)
{
	if (u>'')
		if (type==2)	return playerObject.URL = u;
		else	{
		return playerObject.setSource(u);
		}
}


function MovieInterface(id,x,y,w,h,thumb)
{
	this.id=id;
	this.x=x;this.y=y;
	this.w=w;this.h=h;
	this.thumbNail = "/videos/image?src="+thumb+"&w="+w+"&h="+h;
	if (document.layers && 0)
	{
		document.write("<ilayer id='"+id+"_FrameWin' src='' style='display:none;position:absolute;left:"+x+";top:"+y+";width:"+w+";height:"+h+";border-width:2px'></ilayer>");
		document.write("<ilayer id='"+id+"_FrameReal' src='' style='display:none;position:absolute;left:"+x+";top:"+y+";width:"+w+";height:"+h+";border-width:2px'></ilayer>");
	}
	else
	{
		document.write("<iframe name='"+id+"_FrameWin' id='"+id+"_FrameWin' src='' style='display:none;z-index:90;position:absolute;left:"+x+";top:"+y+";width:"+w+";height:"+h+";border-width:2px'></iframe>");
		document.write("<iframe name='"+id+"_FrameReal' id='"+id+"_FrameReal' src='' style='display:none;z-index:90;position:absolute;left:"+x+";top:"+y+";width:"+w+";height:"+h+";border-width:2px'></iframe>");
	}
	
	this.playerFrameWin = window.frames[id+"_FrameWin"];
	this.playerFrameReal = window.frames[id+"_FrameReal"];

	this.frameObjectWin = getObject(id+"_FrameWin");
	this.frameObjectReal = getObject(id+"_FrameReal");
	
	this.movieType = 0;
	this.activeFrame = 0;
	this.player = new Array(0,0,0);


	this.getPlayer = function() {
//alert(this.player[this.movieType]);
		if (this.player[this.movieType]==0) {
			var o = 0;
			if (this.movieType == 1) 
				o=getObject('moviePlayer',this.playerFrameReal.document); 
			else
				o=getObject('moviePlayer',this.playerFrameWin.document); 
			if (o) 
			{this.player[this.movieType]=o;
//			alert("newPlayer="+typeof(this.player[this.movieType]));
			}

		} 
		return(this.player[this.movieType]!=0);
	}
	this.Load = function (s) { 
		if (this.movieType > 0 && 0) { this.Unload();  }
		ext=s.substring(s.lastIndexOf('.'),s.length);if (ext.indexOf('&') > 0) ext=ext.substring(0,s.lastIndexOf('&'));
		if ( (ext.indexOf('.ram') > -1) || (ext.indexOf('.rm') > -1) ) newMovieType = 1; else newMovieType = 2; 
		if (this.movieType > 0)
		{
			if (this.player[this.movieType] != 0) { this.Stop();}
				else {this.Unload();}
			if ( (this.movieType != newMovieType) && this.player[this.movieType])  
				this.Hide();
		}
		if (newMovieType == 1) this.activeFrame = this.playerFrameReal; else this.activeFrame = this.playerFrameWin;

		if ( (this.player[newMovieType] != 0) )  
			setMovieURL(this.player[newMovieType],s,newMovieType);
		else
			loadMovieInterface(s,this.activeFrame,this.w,this.h,newMovieType);

		this.movieType = newMovieType;
		this.Show(); 
	};
	this.Play = function () { if (this.getPlayer()) playMovieInterface(this.player[this.movieType],this.movieType); };
	this.Pause = function () { if (this.getPlayer()) pauseMovieInterface(this.player[this.movieType],this.movieType); };
	this.Stop = function () { if (this.getPlayer()) stopMovieInterface(this.player[this.movieType],this.movieType); };
	this.getLocation = function () { if (this.getPlayer()) return getMovieInterfaceLocation(this.player[this.movieType],this.movieType); else return 0; };
	this.setLocation = function (p) { if (this.getPlayer()) setMovieInterfaceLocation(p,this.player[this.movieType],this.movieType); };
	this.getVolume = function () { if (this.getPlayer()) return getMovieInterfaceVolume(this.player[this.movieType],this.movieType); else return 0; };
	this.setVolume = function (v) { if (this.getPlayer()) setMovieInterfaceVolume(v,this.player[this.movieType],this.movieType); };
	this.getDuration = function () { if (this.getPlayer()) return getMovieInterfaceDuration(this.player[this.movieType],this.movieType); else {return 0;} };
	this.getStatusMessage = function () { if (this.getPlayer()) return getStatusMessage(this.player[this.movieType],this.movieType); else {return 0;} };
	this.Hide = function () { this.frameObjectReal.style.display='none'; this.frameObjectWin.style.display='none';};
	this.Show = function () { if (this.movieType==1) this.frameObjectReal.style.display='block'; else this.frameObjectWin.style.display='block'; };
	this.Unload = function () { unLoadMovieInterface(this.thumbNail,this.activeFrame);this.player[this.movieType]=0; };
}

