// VidButton.js
// ... a class to call the 'Play' method on a SWF object, given it's ID/Name
// Author: Martin Cowie

function VidButton( vidName )
{
	this.vidName = vidName;
	this.renderHTML();
}

// Change this according to your tastes
VidButton.prototype.buttonImage = "PlayVideo.PNG";

VidButton.prototype.renderHTML = function()
{
	// Insert the Anchor element, and get it's reference
	var id = Math.random();
	document.write( "<img id='"+ id + "'></a>" );
	// ... set it's attributes
	this.display = document.getElementById( id );
	this.display.src = this.buttonImage;
	this.display.border = 0;
	this.display.style.cursor = "pointer";

	// In preparation for the following closure, as 'this' means something else when it's run
	var self = this;

	// Setup a callback for it to do something useful
	this.display.onclick = function( event ) {
		self.playVid();
	}
}


VidButton.prototype.getVidPanel = function()
{
	// This code is just horrid ... and I take no credit for it

	if( window.document[this.vidName] )
		return window.document[this.vidName];

	if( navigator.appName.indexOf( "Microsoft Internet" ) == -1 )
	{
		if( document.embeds && document.embeds[this.vidName] )
			return document.embeds[this.vidName];
	} //else ..

	// frankly if it gets this far - your done for
	return document.getElementById(this.vidName);
}

VidButton.prototype.playVid = function()
{
	// magic ...
	this.getVidPanel().Play();
}
