﻿// JavaScript Document
// Version 2006-06-27 
// This function reads an audio file URL from the referring page and generates embedding code to play back the audio file.
// Windows browsers (except for Internet Explorer) will play back the file with the Windows Media Player *plug-in.* Internet Explorer will use Windows Media Player.
// Non-Windows browsers will play back the file with their standard audio handler for the specified MIME type (mpeg, wav, or wma). On Macs, that handler will usually be QuickTime.

var audioFolder = "http://www.bundlecom.com/audio/";

function embedPlayer() { 

// 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
	visitorOS="Other";
}

// Build audio file path by extracting filename and directory from e-mail link
var fullUrl = location.href; // the e-mail link that called this page
var filePath = fullUrl.substring(fullUrl.indexOf('?')+3, fullUrl.length); 

var audioURL = audioFolder + filePath;
// Get the MIME type of the audio file from its extension (for non-Windows browsers)
var audioType = "audio/mpeg"; // assume MP3
var theExtension = filePath.substring(filePath.indexOf('.')+1, filePath.length); 
if (theExtension.toLowerCase() == "wav") { audioType = "audio/x-wav"};
if (theExtension.toLowerCase() == "wma") { audioType = "audio/x-ms-wma"};
// Add additional MIME types as desired

var objTypeTag = "application/x-mplayer2"; // The Windows MIME type to load the WMP plug-in in Firefox, etc.
var clickType = "right-click the following link"; // Windows users will right-click
if (visitorOS != "Windows") { 
objTypeTag = audioType // audio/mpeg or audio/x-wav or audio/x-ms-wma
clickType = "hold down your Control key, click the following link," // Mac users will Control-click
}; 

document.write("<p>(Your recording may take a moment to load.)</p>");
document.write("<object width='360' height='69'>");
document.write("<param name='type' value='" + objTypeTag + "'>");
document.write("<param name='src' value='" + audioURL + "'>");
document.write("<param name='autostart' value='1'>");
document.write("<param name='showcontrols' value='1'>"); // was 'controller'
document.write("<param name='showstatusbar' value='1'>");
document.write("<embed src ='" + audioURL + "' type='" + objTypeTag + "' autoplay='true' width='360' height='69' controller='1' showstatusbar='1' bgcolor='#ffffff' kioskmode='true'></embed>");
document.write("</object>");

document.write("<p>To save the recording to your computer, " + clickType + " and choose <b>Save Target As</b> or <b>Save Link As.</b></p>");
document.write("<a href='" + audioURL + "' target='_blank'>" + audioURL + "</a>");
document.close(); // Finalizes the document
}