function HTMLAudioPlayer(varName)
{
	this.mediaPlayerId = 'MediaPlayer1';
	this.use_mediaControl = false;
	this.containerId = 'card_preview_audio';
	this.autoPlay = false;
	this.playerControlId = 'preview_player';
	this.audioFile = null;
	this.instanceVarName = varName;
}
HTMLAudioPlayer.prototype.stop = function()
{
	if (this.use_mediaControl) {
		$(this.mediaPlayerId).controls.stop();
	} else {
		$(this.containerId).innerHTML = this.getNonControlledMedia('');
	}
}
HTMLAudioPlayer.prototype.play = function()
{
	if (this.audioFile && this.audioFile.length > 0) {
		if (this.use_mediaControl) {
			$(this.mediaPlayerId).URL = this.audioFile;
		} else {
			$(this.containerId).innerHTML = this.getNonControlledMedia(this.audioFile);
		}
	}
}
HTMLAudioPlayer.prototype.load = function(audioUrl, audioLength, autoPlay)
{
	if (this.audioFile) {
		this.stop();
	}
	if (! $(this.playerControlId)) {
		return;
	}
	if (audioUrl && audioUrl.length > 0) {
		this.audioFile = audioUrl;
		$(this.playerControlId).src = '/cache/sv/1202925915931/postcard/images/preview_player.gif';
		$(this.playerControlId).useMap = '#audioControlMap';
		
		if (this.autoPlay || autoPlay) {
			this.play();
		}
	} else {
		this.audioFile = null;
		$(this.playerControlId).src = '/cache/sv/1202925915931/postcard/images/preview_player_disabled.gif';
		$(this.playerControlId).useMap = '';
	}
}
HTMLAudioPlayer.prototype.setup = function(elName)
{
	var html = '<div id="' + this.containerId + '">' + "\n"
    	+ this.getControlledMedia() + "\n"
  		+ '</div>'
    	+ '<map name="audioControlMap">' + "\n"
		+ '<area shape="circle" coords="21,18,15" href="javascript:' + this.instanceVarName + '.play();" name="audioControlPlay"/>' + "\n"
		+ '<area shape="circle" coords="51,18,15" href="javascript:' + this.instanceVarName + '.stop();" name="audioControlStop"/>' + "\n"
		+ '</map>'
		+ '<img id="' + this.playerControlId + '" src="/cache/sv/1202925915931/postcard/images/preview_player_disabled.gif" width="192" height="37" usemap="#audioControlMap" border="0"/>';
	$(elName).innerHTML = html;
	
}
HTMLAudioPlayer.prototype.testAudio = function()
{
	if ($(this.mediaPlayerId)) {
		if ('controls' in $(this.mediaPlayerId)) {
			this.use_mediaControl = true;
		}
	}
}
HTMLAudioPlayer.prototype.getControlledMedia = function()
{
  	var content = '<object id="' + this.mediaPlayerId + '" width="0" height="0"'
		+ ' classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" '
		+ ' type="application/x-oleobject">' + "\n"
		+ '<param name="URL" value=""/>' + "\n"
		+ '<param name="SendPlayStateChangeEvents" value="True"/>' + "\n"
		+ '<param name="AutoStart" value="True"/>' + "\n"
		+ '<param name="uiMode" value="none"/>' + "\n"
		+ '<param name="PlayCount" value="1"/>' + "\n"
	    + '<embed type="application/x-mplayer2" pluginspage="https://www.microsoft.com/Windows/MediaPlayer/"'
      	+ ' name="MediaPlayer1" width="0" height="0" ShowControls="false" AutoStart="True" '
      	+ ' url="" sendplaystatechangevents="True" uiMode="none" playcount="1">'
        + '</embed>' + "\n"
		+ '</object>';
	return content;
}
HTMLAudioPlayer.prototype.getNonControlledMedia = function(audioLink)
{	
	var content = '<object id="' + this.mediaPlayerId + '" width="100" height="45' + "\n" +
	    'classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6"' + "\n" +
		'type="application/x-oleobject" style="background-color:#E7E9EA">' + "\n" +
		'<param name="URL" value="' + audioLink + '" />' + "\n" +
		'<param name="showControls" value="1" />' + "\n" +
		'<param name="showPositionControls" value="0" />' + "\n" +
		'<param name="AutoStart" value="true" />' + "\n" +
		'<embed id="ShoutPlayer2" type="application/x-mplayer2\"' + "\n" +
		'pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"' + "\n" +
		'src="' + audioLink + '"' + "\n" +
		'name="' + this.mediaPlayerId + '"' + "\n" +
		'width="0"' + "\n" +
		'height="0"' + "\n" +
		'ShowControls="false"' + "\n" +
		'AutoStart="true" style="background-color:#E7E9EA">' + "\n" +
		'</embed>' + "\n" +
		'</object>';
		return content;
}
HTMLAudioPlayer.prototype.reset = function() {
	if (this.containerId && $(this.containerId)) {
		$(this.containerId).parentNode.innerHTML = '<img src="/cache/sv/1202925915931/postcard/images/preview_player_loading.gif" width="192" height="37"/>';
	}
}