// The slide's comment
var vComment;

// Change the buttons on a linked slide page, to pass the parameters
function addParams()
{	getParams();
	var paramparent = params[paramparentname];
	if (paramparent != null)
	{	var paramtop = params[paramtopname];
		var vbparent = document.getElementById('bparent');
		var vbfirst = document.getElementById('bfirst');
		var vbprev = document.getElementById('bprev');
		var vbnext = document.getElementById('bnext');
		var vblast = document.getElementById('blast');
		if (vbparent != null)
		{	vbparent.href += '?' + paramparentname + '=' + paramparent
							 + (decodeURIComponent(vbparent.href) == paramtop ? '' : '&' + paramtopname + '=' + paramtop);
		}
		var vparamlist = '?' + paramparentname + '=' + paramparent + '&' + paramtopname + '=' + paramtop;
		if (vbfirst != null)
		{	vbfirst.href += vparamlist;
		}
		if (vbprev != null)
		{	vbprev.href += vparamlist;
		}
		if (vbnext != null)
		{	vbnext.href += vparamlist;
		}
		if (vblast != null)
		{	vblast.href += vparamlist;
		}
	}
}

// Pre-load the images
var vImages = new Array();
function fPreload() {
	if (fPreload.arguments.length > 0)
	{	for (i=0; i<fPreload.arguments.length; i++)
		{	vImages[i] = new Image();
			vImages[i].src = fPreload.arguments[i];
		}
	}
}

// If a variant thumbnail has been clicked, show a different main image.
function selImage(p_image_id, p_image_path, p_show_si, p_comment)
{	var varId = 'MT'+p_image_id;
	var imgMain = document.getElementById('slideimg');
	if (imgMain.name != varId)
	{	var varThumb = document.getElementById(varId);
		var thumbcell = document.getElementById('TD'+varId);
		var thumbcell_prev = document.getElementById('TD'+imgMain.name);
		// Replace the full-size image with the selected image.
		imgMain.name = varId;
		imgMain.src = p_image_path;
		if (varThumb.style.borderTopWidth == '0px')
		{	imgMain.style.borderWidth = '0px';
		}
		else
		{	imgMain.style.borderWidth = '';
		}
		// If this is the main image, show the superimposed image (if it exists), otherwise hide it.
		var superimposed = document.getElementById('superimposedimg');
		if (superimposed != null)
		{	if (p_show_si == 'Y')
			{	superimposed.style.visibility = '';
			}
			else
			{	superimposed.style.visibility = 'hidden';
			}
		}
		// Highlight the selected variant, and un-highlight the previous variant.
		var vClassName = thumbcell.className;
		thumbcell.className = thumbcell_prev.className;
		thumbcell_prev.className = vClassName;
		// Show the variant's comment.
		if (vComment != undefined) {
			document.getElementById('commentText').innerHTML = (p_comment == undefined ? vComment : p_comment);
		}
	}
}

// Build an embedded object.
// This does not handle mov and mp4 files; these are processed in slide.htt.
function fEmbedObject(pFileName, pFileType, pMimeType, pPath, pWidth, pHeight, pFit, pFlvPlayer, pText1, pText2)
{	var vInnerHTML = null;  // The HTML that shows the video
	var vPath = (pPath == '' ? '' : pPath + '/') + pFileName;
	var vBrowser			// Type of browser: I-Internet Explorer F-Firefox S-Safari O-Other
		= (navigator.userAgent.indexOf("MSIE") != -1
		   ? 'I'
		   : (navigator.userAgent.indexOf("Firefox") != -1
		      ? 'F'
		      : (navigator.vendor.indexOf("Apple") != -1
		      	 ? 'S'
		      	 : 'O'
		      	 )
		      )
		   );

	if (pFileType == 'swf')
	{	vInnerHTML = '<object width="' + pWidth + '" height="' + pHeight + '" '
					 + (vBrowser == 'I' ? 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">'
					 					  + '<param name="movie" value="' + vPath + '">'
					 					: 'type="' + pMimeType + '" data="' + vPath + '">')
					 + '<param name="loop" value="false">'
				 	 + pText1 + ' <a href="http://www.adobe.com">Adobe</a>'
					 + '</object>';
	}
	else if (pFileType == 'flv')
	{	vInnerHTML = '<object width="' + pWidth + '" height="' + pHeight + '" '
					 + (vBrowser == 'I' ? 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">'
					 					  + '<param name="movie" value="' + pFlvPlayer + '">'
					 					: 'type="' + pMimeType + '" data="' + pFlvPlayer + '">')
					 + '<param name="allowScriptAccess" value="sameDomain">'
					 + '<param name="quality" value="high">'
					 + '<param name="scale" value="noScale">'
					 + '<param name="wmode" value="transparent">'
					 + '<param name="flashvars" value="config={videoFile: \'' + vPath + '\', loop: false}">'
					 + '</object>';
	}
	else
	{	// Determine the appropriate video player, based on the O/S.
		var videoPlayer = (navigator.appVersion.toLowerCase().indexOf('win') != -1
						   ? 'WMP' : 'QT');

		// Add the height of the control bar to the video's height
		var vidHeight;
		switch (videoPlayer)
		{	case 'WMP': vidHeight = pHeight + 64; break;
			case 'QT':  vidHeight = pHeight + 16; break;
			default:    vidHeight = pHeight;      break;
		}
		// Build the video object
		vInnerHTML = '<object width="' + pWidth + '" height="' + vidHeight + '" ';
		if (videoPlayer == 'QT')
		{	vInnerHTML += 'type="' + pMimeType + '" data="' + vPath + '">'
						+ '<param name="scale" value="aspect">'
						+ '<param name="autoplay" value="true">'
					    + '<param name="controller" value="true">'
						+ '<param name="showlogo" value="false">';
		}
		else
		{	// Windows Media Player
			// Create a normalised absolute path
			var vDocURL = decodeURIComponent(fDocURL());
			var vAbsPath = vDocURL.substring(0,vDocURL.lastIndexOf('/',vDocURL.lastIndexOf('/')));
			var vPathExtension = pPath;
			while (vPathExtension.length > 0 && vPathExtension.substring(0,2) == '..') 
			{	vPathExtension = vPathExtension.substring(2);
				if (vPathExtension.substring(0,1) == '/')
				{	vPathExtension = vPathExtension.substring(1);
				}
				vAbsPath = vAbsPath.substring(0,vAbsPath.lastIndexOf('/'));
			}
			if (vPathExtension.length > 0)
			{	if (vPathExtension.substring(1,2) == ':')
				{	vAbsPath = vPathExtension;
				}
				else
				{	vAbsPath += '/' + vPathExtension;
				}
			}
			vAbsPath += '/' + pFileName;

			if (vBrowser == 'I')
			{	vInnerHTML += 'classId="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">'
		    				+ '<param name="url" value="' + vAbsPath + '">';
			}
			else if (vBrowser == 'F' || vBrowser == 'S')
			{	vInnerHTML += 'type="application/x-ms-wmp">'
				    		+ '<param name="url" value="' + vAbsPath + '">'
			}
			if (vBrowser == 'I' || vBrowser == 'F' || vBrowser == 'S')
			{	vInnerHTML += '<param name="stretchToFit" value="' + pFit + '">';
			}
			if (vBrowser == 'O')
			{	vInnerHTML += 'type="video/x-ms-wmv">'
							+ '<param name="' + pFilename + '" value="' + vAbsPath + '">';
			}
		}
		vInnerHTML += pText2 + '</object>';
	}
	if (vInnerHTML != null)
	{	document.getElementById('imageid').innerHTML = vInnerHTML;
	}
}
