// Pop-Up Embedder Script by David Battino, www.batmosphere.com
// Version 2006-05-31  
// OK to use if this notice is included

// Original script downloaded 2009-12-14 from http://digitalmedia.oreilly.com/2006/05/31/build-a-better-web-audio-player.html
// See also http://digitalmedia.oreilly.com/2005/02/23/mp3_embed.html and http://www.scriptwell.net/fastweb/howtoplaysound.html

// Modified by Charles W. Uth, www.computerola.com
// Version 2009-12-15
// OK to use if this notice is included
   
function ComputerolaAudioPlayer(filedesc,filepath,WindowNumber) 
{

// 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 = filepath.substr(filepath.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") { 
objTypeTag = mimeType; // audio/mpeg, audio/x-wav, audio/x-ms-wma, etc.
};

    PlayerWin = window.open('',WindowNumber,'width=747,height=500,top=0,left=0,screenX=0,screenY=0,resizable=0,scrollbars=0,titlebar=0,toolbar=0,menubar=0,status=0,directories=0');

    PlayerWin.focus();
    PlayerWin.document.writeln("<html><head><title>" + filedesc + "</title><link rel='stylesheet' type='text/css' href='css/style.css' /></head>");
    PlayerWin.document.writeln("<body><div id='head'><div id='menu'></div></div><div id='body_wrapper'><div id='body'><div id='all'><div class='top'></div><div class='content'>"); 
    PlayerWin.document.writeln("<div align='center'>");
    PlayerWin.document.writeln("<h1>" + filedesc + "</h1><br />");
    PlayerWin.document.writeln("<object width='280' height='69'>");
    PlayerWin.document.writeln("<param name='src' value='" +  filepath + "'>");
    PlayerWin.document.writeln("<param name='type' value='" + objTypeTag + "'>");
    PlayerWin.document.writeln("<param name='autostart' value='1'>");
    PlayerWin.document.writeln("<param name='showcontrols' value='1'>"); 
    PlayerWin.document.writeln("<param name='showstatusbar' value='1'>");
    PlayerWin.document.writeln("<embed src ='" + filepath + "' type='" + objTypeTag + "' autoplay='true' width='280' height='69' controller='1' showstatusbar='1' bgcolor='transparent' kioskmode='true'>");
    PlayerWin.document.writeln("</embed></object></div>");
    PlayerWin.document.writeln("<p style='text-align:center'><a href='" + filepath +"'>Download this file</a> <span style='font-size:10px'>(right-click or Control-click)</span></p>");
    PlayerWin.document.writeln("<form><div align='center'><input type='button' value='Close this window' onclick='javascript:window.close();'></div></form>");
    PlayerWin.document.writeln("</div><div class='bottom'></div></div><div class='clearer'></div></div><div class='clearer'></div></div><div id='end_body'></div><div id='footer'><a rel='license' href='http://creativecommons.org/licenses/by-nc-sa/3.0/'><img alt='Creative Commons License' style='border-width:0' src='http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png' /></a><br />This work is licensed under a <a rel='license' href='http://creativecommons.org/licenses/by-nc-sa/3.0/'>Creative CommonsAttribution-Noncommercial-Share Alike 3.0 Unported License</a></div></body></html>");

    PlayerWin.document.close(); // "Finalizes" new window
}