

function NetscapePluginIsInstalled() {
	for (i=0; i< navigator.plugins.length; i++) {
		if (navigator.plugins[i].name.indexOf("Photodex Presenter") + 1) {
			return 1;
		}
	}
	return 0;
}

function NetscapePluginNeedsUpgrade (requiredVersion) {
	/* Build a version number from the required version string */
	rv = requiredVersion.split(",");
	rvNum = parseInt(rv[0])*1000000 + parseInt(rv[1])*10000 + parseInt(rv[2])*100 + parseInt(rv[3]);
	
	/* Find the plugin */
	for (i=0; i< navigator.plugins.length; i++) {
		if (navigator.plugins[i].name.indexOf("Photodex Presenter") + 1) {
			break;
		}
	}
	/* Sanity Check */
	if (i == navigator.plugins.length) {
		return 1;
	}
	
	/* Split the description to find the version string */
	desc = navigator.plugins[i].description.split(" ");
	
	/* Build a version number from the required version string */
	iv = desc[desc.length-1].split(",");
	ivNum = parseInt(iv[0])*1000000 + parseInt(iv[1])*10000 + parseInt(iv[2])*100 + parseInt(iv[3]);	
	return ivNum < rvNum;
}

function PhotodexObject (objectType,objectName,pxURL,width,height,bgcolor) {
	pxVer = "3,00,0,1967";
	pxFile = "http://files.photodex.com/presenter/";
	if (!bgcolor) {	bgcolor = document.bgColor; }
	if (navigator.userAgent.toLowerCase().indexOf('msie') + 1) {
	  document.write('<object id="'+objectName+'" align=center width="'+width+'" height="'+height+'"classid="clsid:CB50428B-657F-47DF-9B32-671F82AA73F7" codebase="http://www.photodex.com/pxplay.cab#version='+pxVer+'"><param name="showURL" value="'+pxURL+'"><param name="bgcolor" value="'+bgcolor+'"><param name="pageURL" value="'+document.URL+'"></object>');
	} else {
	  if (!NetscapePluginIsInstalled()) {
		  document.write('<embed id="'+objectName+'" name="'+objectName+'" align=center width="'+width+'" height="'+height+'" type="application/x-photodex-presenter" pluginspage="'+pxFile+'pxplay.xpi" showURL="'+pxURL+'" bgcolor="'+bgcolor+'" pageURL="'+document.URL+'"></embed>');
	  } else if (NetscapePluginNeedsUpgrade(pxVer)) {
		  newHeight = height - 20;
		  document.write('<table bgcolor=#FFFFFF cellspacing=0 cellpadding=0><tr><td><center>The plugin needs to be upgraded.</center></td></tr><tr><td><embed id="'+objectName+'" name="'+objectName+'" align=center width="'+width+'" height="'+newHeight+'" type="application/x-photodex-presenter-upgrade" pluginspage="'+pxFile+'pxplay.xpi" showURL="'+pxURL+'" bgcolor="'+bgcolor+'" pageURL="'+document.URL+'"></embed></td></tr></table>');
	  } else {
		  document.write('<embed id="'+objectName+'" name="'+objectName+'" align=center width="'+width+'" height="'+height+'" type="application/x-photodex-presenter" pluginspage="'+pxFile+'pxplay.xpi" showURL="'+pxURL+'" bgcolor="'+bgcolor+'" pageURL="'+document.URL+'"></embed>');
	  }
	}
}

function PhotodexPostInstall(url, status) {
	if (status == 0) {
		navigator.plugins.refresh();
		self.location.reload();
	}
}


// Control bar code ----
initializedImages = 0;


function InitImage (imgName,fileNameOn,fileNameOff) {
	eval("imgPresenter" + imgName + "On = new Image();");
	eval("imgPresenter" + imgName + "On.src = \"http://images.photodex.com/presenter_controls/rounded/" + fileNameOn + "\"");

	eval("imgPresenter" + imgName + "Off = new Image();"); 
	eval("imgPresenter" + imgName + "Off.src = \"http://images.photodex.com/presenter_controls/rounded/" + fileNameOff + "\"");
	
}

function PresenterInitialize (controlName) {
	if (!initializedImages) {
		InitImage("Play","play_on.gif","play.gif");
		InitImage("Pause","pause_on.gif","pause.gif");
		InitImage("Stop","stop_on.gif","stop.gif");
		InitImage("Prev","prev_on.gif","prev.gif");
		InitImage("Next","next_on.gif","next.gif");
		InitImage("Mute","mute_on.gif","mute.gif");
		InitImage("Unmute","unmute_on.gif","unmute.gif");
		InitImage("About","about_on.gif","about.gif");
		for (x=0;x<11;x++) {
			eval("InitImage(\"Volume"+x+"\",\"volume_"+x+".gif\",\"volume_"+x+"_off.gif\")");
		}
		initializedImages=1;
	}
	
	if (typeof controlName == "undefined") {
		controlName = document.embeds[controlName];
	}
	document [controlName].volumeLeft = 0;
	document [controlName].volumeRight = 0;
	document [controlName].currentPosition = 0;
	document [controlName].totalLength = 0;
	document [controlName].showState = "";
	document [controlName].muted = 0;
	document [controlName].lastVolume = 0;
	document [controlName].lastState = "";
	window.setInterval("PresenterGetStates('" + controlName + "')",100);
}

function PresenterGetStates (controlName) {
	document [controlName].Send('get '+controlName+' volume');
	document [controlName].Send('get '+controlName+' position');
	document [controlName].Send('get '+controlName+' state');

}

function ShowNotify(response) {
	argument = response.split(" ");										// split the response
	controlName = argument[0];
	if (argument[1] == 'volume') {										// Check for 'volume'. Arguments: 'left right'
		document [controlName].volumeLeft = parseInt(argument[2]);     
		document [controlName].volumeRight = parseInt(argument[3]);
		if (document [controlName].volumeLeft != document [controlName].lastVolume) {
			for (x=0;x<=10;x++) {
				imgName = "imgPresenterVolume" + x;
				step = x*10;
				if (step <= document [controlName].volumeLeft) {
					eval("document."+imgName+controlName+".src = "+imgName+"On.src");
				} else {
					eval("document."+imgName+controlName+".src = "+imgName+"Off.src");
				}
			}
		}
		document [controlName].lastVolume = document [controlName].volumeLeft;
	}
	if (argument[1] == 'position') {									// Check for 'position'. Arguments: 'currentPosition totalShowLength'
		document [controlName].currentPosition = parseInt(argument[2]);
		document [controlName].totalLength = parseInt(argument[3]);
	}
	if (argument[1] == 'state') {										// Check for 'state'. Arguments: one of 'paused', 'buffering', 'playing', 'stopped'
		document [controlName].showState = argument[2];
		if (document [controlName].lastState != document [controlName].showState) {
			document [controlName].lastState = document [ controlName].showState;
			if (document [controlName].showState == 'paused') {
				eval("document.imgPresenterPlay"+controlName+".src = imgPresenterPlayOff.src");
			} else if (document [controlName].showState == 'stopped') {
				eval("document.imgPresenterPlay"+controlName+".src = imgPresenterPlayOff.src");
			} else if (document [controlName].showState == 'finished') {
				eval("document.imgPresenterPlay"+controlName+".src = imgPresenterPlayOff.src");
			} else {
				eval("document.imgPresenterPlay"+controlName+".src = imgPresenterPauseOff.src");
			}
		}
	}
}
function PresenterPause (controlName) {
	if (document [controlName].showState == 'paused') {
		document [controlName].Send('Resume');
		eval("document.imgPresenterPlay"+controlName+".src = imgPresenterPauseOff.src");
	} else if (document [controlName].showState == 'stopped') {
		document [controlName].Send('Play');
		eval("document.imgPresenterPlay"+controlName+".src = imgPresenterPauseOff.src");
	} else if (document [controlName].showState == 'finished') {
		document [controlName].Send('Play');
		eval("document.imgPresenterPlay"+controlName+".src = imgPresenterPauseOff.src");
	} else {
		document [controlName].Send('Pause');
		eval("document.imgPresenterPlay"+controlName+".src = imgPresenterPlayOff.src");
	}
}

function PresenterMute (controlName) {
	if (document [controlName].muted) {
		document [controlName].Send('Unmute');
		document [controlName].muted = 0;
		eval("document.imgPresenterMute"+controlName+".src = imgPresenterMuteOff.src");
	} else {
		document [controlName].Send('Mute');
		document [controlName].muted=1;
		eval("document.imgPresenterMute"+controlName+".src = imgPresenterUnmuteOff.src");
	}
}

function PresenterStop (controlName) {
	document [controlName].Send('Stop');
	eval("document.imgPresenterPlay"+controlName+".src = imgPresenterPlayOff.src");
}

function PresenterVolume (controlName,volume) {
	volumeStr = "Volume " + volume;
	document [controlName].Send(volumeStr);
}

function PresenterNext (controlName) {
	document [controlName].Send('Next');
}

function PresenterPrev (controlName) {
	document [controlName].Send('Previous');
}

function PresenterAbout (controlName) {
	document [controlName].Send('About');
}

function imgPresenterPause (controlName,mouseState) {
	if (mouseState == "over") {
		if (document [controlName].showState == 'paused') {
			eval("document.imgPresenterPlay"+controlName+".src = imgPresenterPlayOn.src");
		} else if (document [controlName].showState == 'stopped') {
			eval("document.imgPresenterPlay"+controlName+".src = imgPresenterPlayOn.src");
		} else if (document [controlName].showState == 'finished') {
			eval("document.imgPresenterPlay"+controlName+".src = imgPresenterPlayOn.src");
		} else {
			eval("document.imgPresenterPlay"+controlName+".src = imgPresenterPauseOn.src");
		}
	} else {
		if (document [controlName].showState == 'paused') {
			eval("document.imgPresenterPlay"+controlName+".src = imgPresenterPlayOff.src");
		} else if (document [controlName].showState == 'stopped') {
			eval("document.imgPresenterPlay"+controlName+".src = imgPresenterPlayOff.src");
		} else if (document [controlName].showState == 'finished') {
			eval("document.imgPresenterPlay"+controlName+".src = imgPresenterPlayOff.src");
		} else {
			eval("document.imgPresenterPlay"+controlName+".src = imgPresenterPauseOff.src");
		}
	}
}

function imgPresenterMute (controlName,mouseState) {
	if (mouseState == 'over') {
		if (document [controlName].muted) {
			eval("document.imgPresenterMute"+controlName+".src = imgPresenterUnmuteOn.src");
		} else {
			eval("document.imgPresenterMute"+controlName+".src = imgPresenterMuteOn.src");
		}
	} else {
		if (document [controlName].muted) {
			eval("document.imgPresenterMute"+controlName+".src = imgPresenterUnmuteOff.src");
		} else {
			eval("document.imgPresenterMute"+controlName+".src = imgPresenterMuteOff.src");
		}
	}
}

function imgPresenterControlOn (imgName,controlName) {
	eval("document."+imgName+controlName+".src = "+imgName+"On.src");
}

function imgPresenterControlOff (imgName,controlName) {
	eval("document."+imgName+controlName+".src = "+imgName+"Off.src");
}

function PresenterControls(controlName,width) {
	PresenterInitialize(controlName);
	document.write("<table border=0 cellspacing=0 cellpadding=0 width="+width+"><tr>");
	document.write("<td width=15><img src=\"http://images.photodex.com/presenter_controls/rounded/left.gif\" width=\"15\" height=\"30\" alt=\"\" border=\"0\"></td>");
	document.write("<td width=28><a href=\"javascript:PresenterPause('"+controlName+"')\" onMouseOver=\"imgPresenterPause('"+controlName+"','over')\" onMouseOut=\"imgPresenterPause('"+controlName+"','out')\"><img name=\"imgPresenterPlay"+controlName+"\" src=\"http://images.photodex.com/presenter_controls/rounded/pause.gif\" width=\"28\" height=\"30\" alt=\"Pause / Play\" border=\"0\"></a></td>");
	document.write("<td width=24><a href=\"javascript:PresenterStop('"+controlName+"')\" onMouseOver=\"imgPresenterControlOn('imgPresenterStop','"+controlName+"')\" onMouseOut=\"imgPresenterControlOff('imgPresenterStop','"+controlName+"')\"><img name=\"imgPresenterStop"+controlName+"\" src=\"http://images.photodex.com/presenter_controls/rounded/stop.gif\" width=\"24\" height=\"30\" alt=\"Stop\" border=\"0\"></a></td>");
	document.write("<td width=10><img src=\"http://images.photodex.com/presenter_controls/rounded/back.gif\" width=\"10\" height=\"30\" alt=\"\" border=\"0\"></td>");
	document.write("<td width=24><a href=\"javascript:PresenterPrev('"+controlName+"')\" onMouseOver=\"imgPresenterControlOn('imgPresenterPrev','"+controlName+"')\" onMouseOut=\"imgPresenterControlOff('imgPresenterPrev','"+controlName+"')\"><img name=\"imgPresenterPrev"+controlName+"\" src=\"http://images.photodex.com/presenter_controls/rounded/prev.gif\" width=\"24\" height=\"30\" alt=\"Previous Slide\" border=\"0\"></a></td>");
	document.write("<td width=24><a href=\"javascript:PresenterNext('"+controlName+"')\" onMouseOver=\"imgPresenterControlOn('imgPresenterNext','"+controlName+"')\" onMouseOut=\"imgPresenterControlOff('imgPresenterNext','"+controlName+"')\"><img name=\"imgPresenterNext"+controlName+"\" src=\"http://images.photodex.com/presenter_controls/rounded/next.gif\" width=\"24\" height=\"30\" alt=\"Next Slide\" border=\"0\"></a></td>");
	document.write("<td background=\"http://images.photodex.com/presenter_controls/rounded/back.gif\"><img src=\"http://images.photodex.com/presenter_controls/rounded/back.gif\" width=\"10\" height=\"30\" alt=\"\" border=\"0\"></td>");
	document.write("<td width=24><a href=\"javascript:PresenterMute('"+controlName+"')\" onMouseOver=\"imgPresenterMute('"+controlName+"','over')\" onMouseOut=\"imgPresenterMute('"+controlName+"','out')\"><img name=\"imgPresenterMute"+controlName+"\" src=\"http://images.photodex.com/presenter_controls/rounded/mute.gif\" width=\"24\" height=\"30\" alt=\"Mute\" border=\"0\"></a></td>");
	document.write("<td width=46><table border=0 cellspacing=0 cellpadding=0><tr>");
	document.write("<td><a href=\"javascript:PresenterVolume('"+controlName+"',0)\"><img name=\"imgPresenterVolume0"+controlName+"\" src=\"http://images.photodex.com/presenter_controls/rounded/volume_0_off.gif\" width=\"9\" height=\"30\" alt=\"0%\" border=\"0\"></a></td>");
	for (x=1;x<11;x++) {
		document.write("<td><a href=\"javascript:PresenterVolume('"+controlName+"',"+x+"0)\"><img name=\"imgPresenterVolume"+x+controlName+"\" src=\"http://images.photodex.com/presenter_controls/rounded/volume_"+x+"_off.gif\" width=\"4\" height=\"30\" alt=\""+x+"0%\" border=\"0\"></a></td>");
	}
	document.write("</tr></table></td>");
	document.write("<td width=40><img src=\"http://images.photodex.com/presenter_controls/rounded/right.gif\" width=\"40\" height=\"30\" border=\"0\"></td>");
	document.write("</tr></table>");
}	

