// JavaScript Document
// One Green Bottle, www.onegreenbottle.com.au, modified version of Pop-Up Audio/Photo Embedder Script by David Battino, www.batmosphere.com
// v 2006-21-06
// OK to use if this notice is included

function EnhAudioPop(popuptitle,imgpath,imgwidth,imgheight,caption,soundpath,UniqueID) { // Add error handling?

// Get Operating System 
var isWin = navigator.userAgent.toLowerCase().indexOf("windows") != -1
if (isWin) {
    // Use MIME type = "application/x-mplayer2";
	visitorOS="Windows";
} else {
    // Use MIME type = "audio/mpeg"; // or audio/x-wav or audio/x-ms-wma, etc.
	visitorOS="Other";
}

// Get the MIME type of the audio file from its extension (for non-Windows browsers)
var mimeType = "audio/mpeg"; // assume MP3/M3U
var objTypeTag = "application/x-mplayer2"; // The Windows MIME type to load the WMP plug-in in Firefox, etc.

var theExtension = soundpath.substr(soundpath.lastIndexOf('.')+1, 3); // truncates .aiff to aif
if (theExtension.toLowerCase() == "wav") { mimeType = "audio/x-wav"};
if (theExtension.toLowerCase() == "aif") { mimeType = "audio/x-aiff"}; 
if (theExtension.toLowerCase() == "wma") { mimeType = "audio/x-ms-wma"};
if (theExtension.toLowerCase() == "mid") { mimeType = "audio/mid"};
// Add additional MIME types as desired


if (visitorOS != "Windows") { 
	// Use MIME type = "application/x-mplayer2";
	objTypeTag = mimeType; // audio/mpeg, audio/x-wav, audio/x-ms-wma, etc.
};
     var winWidth = Number(imgwidth) + 170;
     var rawHeight = Number(imgheight) + 168 + caption.length/7; // calculate window height based on caption length
     var winHeight = Math.round(rawHeight * Math.pow(10,0))/Math.pow(10,0); // round to integer
     MediaWin = window.open('',UniqueID,'width=' + winWidth + ',height=' + winHeight + ',top=0,left=0,resizable=1,scrollbars=0,titlebar=0,toolbar=0,menubar=0,status=0,directories=0,personalbar=0');
     MediaWin.focus();
     var winContent = "<html><head><title>" + popuptitle + "</title></head>";
     winContent += "<body bgcolor='#FFFFFF'>"; // check image path
    
     winContent += "<div align='center'>";
     winContent += "<br /><br />"; // could use padding
     winContent += "<img src='" + imgpath + "' id='image1' border='0' alt='" + popuptitle + "' width='" + imgwidth + "' height='" + imgheight + " 'title='" + popuptitle + "' />";
     winContent += "<br />";
     winContent += "<object width='" + imgwidth + "' height='45' >"; // add 4 to width to align controller with img border?
     winContent += "<param name='src' value='" + soundpath + "'>";
     winContent += "<param name='autoplay' value='true'>";
     winContent += "<param name='controller' value='true'>";
     winContent += "<param name='bgcolor' value='#D8E7DA'>";
     winContent += "<embed src ='" + soundpath + "' type='" + objTypeTag + "' autostart='true' loop='false' width='140' height='69' controller='true' showstatusbar='1' bgcolor='#D8E7DA'>";
     winContent += "</embed></object>";

     winContent += "<div style='width: " + imgwidth + "px; margin: 0px; padding: 0px; text-align:left;'>"; // restrict caption width to image width
     winContent += "<p style='font-size:12px;font-family:Verdana,sans-serif'>" + caption + "</p>";
     winContent += "</div>";
     winContent += " &#8226; <a href='#' style='font-size:10px;font-family:Verdana,sans-serif;color:#558A5B' onClick='javascript:window.close();'>Close this window</a></p>";

     winContent += "</div>";
     winContent += "</body></html>";
     MediaWin.document.write(winContent); 
     MediaWin.document.close(); // "Finalizes" new window
}