/*
 * thAudioObject
 * Revised by Tony Freixas (tony@tigerheron.com, http://www.tigerheron.com/) from:
 *
 * qtObject.js embed
 * http://blog.deconcept.com/2005/01/26/web-standards-compliant-javascript-quicktime-detect-and-embed/
 * by Geoff Stearns (geoff@deconcept.com, http://www.deconcept.com/)
 * v1.0.2 - 2005-02-16
 *
 * Revised version:
 * v1.0.2.th - 2007-09-06:
 *    - Works for audio instead of video
 *    - Still requires QuickTime but less QT specific (could be adapted for other sound formats)
 *    - Added Autodesk convenience functions
 */

var thObjectIdCount = 1;
document.write("<style>.noscript { display: none } </style>");

function OCOTListen(src)
{
    var id = 'thObj' + thObjectIdCount++;
    document.write(
	'<div>' +
	'<span style="color: #7fad2c; font-weight: bold; font-size: 80%;">' +
	'<span title="Click to listen" style="cursor: pointer" onclick="AutodeskAudio_OnClick(' +
	'\'' + src + '\', \'' + id + '\', 100, 16)"> ' +
	'LISTEN ' +
	'<img src="/ontarget/files/audio.gif" width="16" height="16" style="vertical-align: top" alt=""> ' +
	'</span>' +
	'<span id="' + id + '"> ' +
	'</span>' +
	'&nbsp;&nbsp;&nbsp;<a href="' + src + '" title="To download, right-click and select &quot;Save Target As&quot;">DOWNLOAD AUDIO ' +
	'<img src="/ontarget/files/download.gif" width="8" height="16" style="vertical-align: top" alt=""> ' +
	'</a>' +
	'</span>' +
	'</div>');
}

function OCOTPodcast(src)
{
    var id = 'thObj' + thObjectIdCount++;
    document.write(
	'<img width="70" height="22" border="0" ' +
	'src="/ontarget/images/podcast-mini2.gif" alt="Podcast" ' +
	'title="Click to listen" ' +
	'style="cursor: pointer" ' +
	'onclick="AutodeskAudio_OnClick(' +
	'\'' + src + '\', \'' + id + '\', 100, 16)">' +
	'<span id="' + id + '"></span>');
}

function OCOTPodcast_OnClick(src, id, width, height)
{
    AutodeskAudio_OnClick(src, id, width, height);
//    e = document.getElementById(id);
//     temp = e.innerHTML;
//     e.innerHTML =
// 	'<div style="margin: .5em 0 0 0">' + temp + '</div>';
}

function AutodeskMP3(src, clickImg, imgWidth, imgHeight)
{ AutodeskAudio(src, 100, 16, clickImg, imgWidth, imgHeight, ''); }

function AutodeskAudio(src, width, height, clickImg, imgWidth, imgHeight, imgExtra)
{
    var id = 'thObj' + thObjectIdCount++;
    document.write(
	'<img src="' + clickImg + '" width="' + imgWidth + '" height="' + imgHeight +'" ' +
	imgExtra + ' ' +
	'onclick="AutodeskAudio_OnClick(' +
	'\'' + src + '\', \'' + id + '\', ' + width + ', ' + height + ')"> ' +
	'<span id="' + id + '"> ' +
	'</span>');
}

function AutodeskAudio_OnClick(src, id, width, height)
{
    var obj = new thAudioObject(src, id, width, height);
    obj.addParam("controller", "true");
    obj.addParam("autoplay", "true");
    obj.addParam("autostart", 1);
    obj.write(id);
}

thAudioObject = function(media, id, width, height) {
    this.media = media;
    this.id = id;
    this.width = width;
    this.height = height;
    this.params = new Object();
}

thAudioObject.prototype.addParam = function(name, value) {
    this.params[name] = value;
}

thAudioObject.prototype.getParams = function() {
    return this.params;
}

thAudioObject.prototype.getParam = function(name) {
    return this.params[name];
}

thAudioObject.prototype.getParamTags = function() {
    var paramTags = "";
    for (var param in this.getParams()) {
	paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '">';
    }
    if (paramTags == "") paramTags = null;

    return paramTags;
}

thAudioObject.prototype.getHTML = function() {
    var html = "";
    if (navigator.plugins && navigator.plugins.length) { // not ie
	html +=
	    '<object style="vertical-align: middle" data="' +
	    this.media + '" width="' + this.width + '" height="' + this.height + '">';
	if (this.getParamTags() != null) html += this.getParamTags();
	html +=
	    '<embed style="vertical-align: middle" ' +
	    '" src="' + this.media + '" width="' + this.width + '" height="' + this.height + '"';
	for (var param in this.getParams()) {
	    html += ' ' + param + '="' + this.getParam(param) + '"';
	}
	html +=
	    '></embed>' +
	    '</object>';
    }
    else { // IE
	html += '<object ' +
	'" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"' +
	' codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="' +
	this.width + '" height="' + this.height + '">';
	this.addParam("src", this.media);
	if (this.getParamTags() != null) {
	    html += this.getParamTags();
	}
	html += '</object>';
    }
    return html;
}

thAudioObject.prototype.write = function(elementId) {
    if (elementId) {
	document.getElementById(elementId).innerHTML = this.getHTML();
    }
    else {
	document.write(this.getHTML());
    }
}
