/* Eptamedia s.r.l. - Copyright (c) 2001 - 2004
* Common.js 06.09.12
* FOR WEB USE ONLY
*/
/* main file locations */
eptaUrl = "http://www.eptamedia.com";
xpiUrl = eptaUrl+"/software/EptaPlayer.xpi";
cabUrl = eptaUrl+"/software/EptaPlayer.cab";
downloadUrl = eptaUrl+"/en-doc/en-download.htm";
nopluginUrl = eptaUrl+"/software/noplugin.gif";
notsupportedUrl = eptaUrl+"/software/notsupported.gif";
notInstalledMessage = "EptaPlayer is not installed:\n to install it, follow the on-screen instructions.\n---\nEptaPlayer non è installato,\n per installarlo segui le istruzioni nelle prossime schermate.";
needsUpdateMessage = "A new release of EptaPlayer is available.\nUna nuova versione di EptaPlayer è disponibile.";
/* encodes the minimum version required to correctly view the website */
function RequiredVersion ()
{
	/* Encode here the required version number for the Plugin as year - month - day */
	this.v1=6;
	this.v2=9;
	this.v3=12;
	this.v4=0; 
	this.version = '';  
	if (this.v1<10) this.version = '0';
	this.version = this.version+this.v1+'.';
	if (this.v2<10) this.version = this.version+'0';
	this.version = this.version+this.v2+'.';
	if (this.v3<10) this.version = this.version+'0';
	this.version = this.version+ this.v3; 
}
var requiredVersion = new RequiredVersion();
var is = new Is();
/* check wether the plugin pointer points to the plugin and not to a dummy object */
function isValid(eplObj)
{
	if (eplObj)
	{
		if (is.ie)
	  		if (eplObj.version) 
	  			return true;
	}
	return false;
}
/* EPTAPLAYER SCRIPTING INTERFACE WRAPPERS */
function PlayStream(wav)
{
	if (isValid(this.eplObj))
		this.eplObj.PlayStream(wav);
}
function LoadStream(fap,wav,autoplay)
{
	if (isValid(this.eplObj))
		this.eplObj.LoadStream(fap,wav,autoplay);
}
function LoadModel(model)
{
	if (isValid(this.eplObj))
		this.eplObj.LoadModel(model);
}
function LoadBackground(bkg)
{
	if (isValid(this.eplObj))
		this.eplObj.LoadBackground(bkg);
}
function ConfigSession(model, bkg,  fap, wav, drawmode, autoplay)
{
	if (isValid(this.eplObj))
		this.eplObj.ConfigSession(model, bkg,  fap, wav, drawmode, autoplay);
}
function ChangeDrawmode(drawmode)
{
	if (isValid(this.eplObj))
		this.eplObj.ChangeDrawmode(drawmode);
}
/* PLAYER CONTROLS*/
function Play()
{
	if (isValid(this.eplObj))
		this.eplObj.Play();
}
function Stop()
{
	if (isValid(this.eplObj))
		this.eplObj.Stop();
}
function Pause()
{
	if (isValid(this.eplObj))
		this.eplObj.Pause();
}
function Loop()
{
	if (isValid(this.eplObj))
		this.eplObj.Loop();
}
function Next()
{
	if (isValid(this.eplObj))
		this.eplObj.Next();
}
function Rewind()
{
	if (isValid(this.eplObj))
		this.eplObj.Rewind();
}
/* NOT SUPPORTED
Prev();
*/
function ShowLogo(flag)
{
	if (isValid(this.eplObj))
		this.eplObj.ShowLogo(flag);
}
/* return a string containing the version of the player, if installed, 
or "NOT INSTALLED" or "BROWSER NOT SUPPORTED" */
function GetVersion()
{
	if (isValid(this.eplObj)) 
	{
	 	if (is.ie)
	  		return this.eplObj.version;
	}
	if (is.supported) 
		return "NOT INSTALLED"; 
	else 
		return "BROWSER NOT SUPPORTED";
}
/* associate a real plugin instance to the wrapper */ 
function setPlayerInstance(playerPointer)
{
	if (playerPointer)
	{
		this.eplObj = playerPointer;
	}	
	else 
		this.eplObj = null;	
}
/* wrapper used to prevent javascript errors whenever the plugin is not present */
function EptaPlayerWrapper ()
{
	this.eplObj = null;
	this.setPlayerInstance = setPlayerInstance;	
	this.update = false; 
	this.PlayStream = PlayStream;
	this.LoadModel = LoadModel;
	this.LoadStream = LoadStream;
	this.LoadBackground = LoadBackground;
	this.ConfigSession = ConfigSession;
	this.ChangeDrawmode = ChangeDrawmode;
	this.Play = Play;
	this.Stop = Stop;
	this.Pause = Pause;
	this.Loop = Loop;
	this.Rewind = Rewind;
	this.Next = Next;
	this.ShowLogo = ShowLogo;
	this.GetVersion= GetVersion;	
	this.instanceName='eplInstance'; 
}
/* Utility functions */ 
/* Write a parameter of the OBJECT/EMBED TAG */
function writeParam(name,value)
{
	if (!is.netscape6) 
	{
		temp = ' <PARAM name="'+name+'" value = "'+value+'">\n';
		document.write(temp);
	}
}
/* what to display if the plugin is supported but not yet installed */ 
function noPlugin(w,h)
{
	temp = '<a href="'+downloadUrl+'" target="_top"> ';
	temp +='<img src="'+nopluginUrl+'" width="'+w+'" height= "'+h+'" border="0"></a>';
	document.write(temp);
}
/* what to display if the browser/platform is not supported */ 
function notSupported(w,h)
{
	temp = '<a href="'+eptaUrl+'" target="_top">'; 
	temp +='<img src="'+notsupportedUrl+'" width="'+w+'" height= "'+h+'" border="0"></a>';
	document.write(temp);
}
/* EptaPlayer API */ 
/* New API */
function EptaPlayer( w,h,model,background,fapstream,audiostream,drawmode,autoplay,n )
{
	instanceName = 'eplInstance';
	if (!n)
		n = 1;
	document.epl = new EptaPlayerWrapper ();
	document.epl.instanceName = instanceName;
	if (!is.supported)
	{
		notSupported(w,h);
		return false;
	}
	if (is.win32)
	{
	/* open the tag */
	if (is.ie) 
		{
			temp = '<OBJECT ID="'+instanceName+'" WIDTH='+w+' HEIGHT='+h;
			temp += ' CODEBASE="'+cabUrl+'#Version=';
			temp += requiredVersion.v1+','+requiredVersion.v2+','+requiredVersion.v3+','+requiredVersion.v4+'"';
			temp += ' CLASSID="clsid:6206E9A0-E55B-11D4-8EE8-0050DA455324"> ';
			document.write(temp);
	/* write parameters */ 
			writeParam("AUTOPLAY",autoplay);
			writeParam("MODEL",model);
			writeParam("BACKGROUND",background);
			writeParam("FAPSTREAM",fapstream);
			writeParam("AUDIOSTREAM",audiostream);
			writeParam("DRAWMODE",drawmode);
		}
	if (is.ie)
		{
			writeParam("BASE", document.URL);
		}
	/* close the TAG */
	if (is.ie ) 
		{
			noPlugin(w,h);
			document.writeln(" </OBJECT>");
		}
	document.writeln();
	} 
	if (is.supported)
		{
			if (n == 1)
				{
				document.epl.setPlayerInstance(document.eplInstance);
				}
			else
				{
					alert('Multiple instances are not allowed in the current version\n');
				}
			pluginVersion = document.epl.GetVersion();
			if( pluginVersion < requiredVersion.version )
			{
				if (document.epl.update == false) 
					alert(needsUpdateMessage+"\nPlease download it from www.eptamedia.com.");
			} 
		}
	if (is.supported)
		{
			return true;
		}
}
/* detect browser and platform */
function Is ()
{
	var agt=navigator.userAgent.toLowerCase();
	this.ver = parseFloat( navigator.appVersion );
	this.major = parseInt( navigator.appVersion );
	this.netscape  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
	             && (agt.indexOf('compatible') == -1) 
	             && (agt.indexOf('opera')==-1) ); 
	this.netscape4 = (this.netscape && (this.major == 4));
	this.netscape6 = (this.netscape && (agt.indexOf("netscape6") != -1)); 
	this.mozilla = (this.netscape && (this.major > 4));
	this.netscape6up = (this.mozilla && (agt.indexOf("netscape/") != -1)); 
	this.firefox = (this.mozilla && (agt.indexOf("firefox/") != -1));
	if (this.mozilla) 
		{
			if (agt.indexOf("rv:")!=-1) 
			{
				revisionStr = agt.slice(agt.indexOf("rv:")+3);
				this.mozillaVersion = revisionStr.slice(0,revisionStr.indexOf(")"));
			}
		}
	this.XPInstallDisabled = (this.firefox || 
							  (this.mozilla && this.mozillaVersion>="1.7")); 
	this.ie   = ((agt.indexOf("msie") != -1) && (agt.indexOf('opera')==-1) ); 
	this.opera  = (agt.indexOf('opera')!=-1);
	var plat=navigator.platform.toLowerCase();
	this.win32 = (plat.indexOf("win32")>-1);
	this.linux = (plat.indexOf("linux")>-1); 
	this.mac = (plat.indexOf("mac")>-1); 
	this.pocketpc = (plat.indexOf("wince")>-1);
	this.supported = (this.win32 && this.ie); 
}
