// JavaScript Document
// Pop-Up Embedder Script by David Battino, www.batmosphere.com; Object tag implementation by Mark Levitt, http://digitalmedia.oreilly.com

var UniqueID = 314 // Make each link open in a new window.

var newWinOffset = 0 // Position of first pop-up

$(document).ready( function(){

	$("#tbl_audio td a, #audio_player, .audio_file").click( function(){
				
		embedPlayer( $(this).attr("title"), $(this).attr("href"));
		return false;
	});		
	
	// Pop-Up Embedder Script by David Battino, www.batmosphere.com
// Version 2006-05-31 
// OK to use if this notice is included
   
   
   function embedPlayer(MP3title,MP3URL) { 
   
		var WindowNumber = 1;
   
		// correct the url
		MP3URL = MP3URL.indexOf("http") >= 0 ? MP3URL: "http://" + window.location.hostname + MP3URL;
		
		
	   // 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, audio/x-wav, etc.
		  visitorOS="Other";
	   }
	   
		var objTypeTag = "application/x-mplayer2"; // The MIME type to load the WMP plugin in non-IE browsers on Windows
		if (visitorOS != "Windows") { objTypeTag = "audio/mpeg"}; // The MIME type for Macs and Linux 

		// determine screen size
				
		var left_offset = screen.width - 300 - 100;


		PlayerWin = window.open('',WindowNumber,'width=300,height=160,top=20,left=' + left_offset + ',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><META HTTP-EQUIV='Pragma' CONTENT='no-cache'><TITLE>Media Player</TITLE></HEAD><BODY bgcolor='#000000'>");
		PlayerWin.document.writeln("<B style='font-size:18px;font-family:Verdana,sans-serif;color:#FFFFFF;line-height:1.5'>" + MP3title + "</B>");  // Adjust font style to taste
		PlayerWin.document.writeln("<object width='280' height='69'>"); // Width is the WMP minimum. Height = 45 (WMP controls) + 24 (WMP status bar) 
		PlayerWin.document.writeln("<param name='type' value='" + objTypeTag + "'>");
		PlayerWin.document.writeln("<param name='src' value='" + MP3URL + "'>");
		PlayerWin.document.writeln("<param name='autostart' value='0'>");
		PlayerWin.document.writeln("<param name='showcontrols' value='1'>");
		PlayerWin.document.writeln("<param name='showstatusbar' value='1'>");
		PlayerWin.document.writeln("<embed src ='" + MP3URL + "' type='" + objTypeTag + "' autoplay='true' autostart='1' width='280' height='69' controller='1' showstatusbar='1' bgcolor='#ffffff'></embed>"); 

		// Firefox and Opera Win require both autostart and autoplay
		PlayerWin.document.writeln("</object>");
		PlayerWin.document.writeln("<FORM><DIV align='center'><INPUT type='button' value='Close this window' onClick='javascript:window.close();'></DIV></FORM>");
		PlayerWin.document.writeln("</BODY></HTML>");
		PlayerWin.document.close(); // Finalizes the document
	}
   
	

	function PlayerOpen(soundfiledesc,soundfilepath) {

		soundfilepath = soundfilepath.indexOf("http") >= 0 ? soundfilepath: "http://" + window.location.hostname + soundfilepath;

		PlayWin = window.open('',UniqueID,'width=400,height=190,top=' + newWinOffset +',left=0,resizable=0,scrollbars=0,titlebar=0,toolbar=0,menubar=0,status=0,directories=0,personalbar=0');

		PlayWin.focus(); 


		var winContent = "<HTML><HEAD><META HTTP-EQUIV='Pragma' CONTENT='no-cache'><TITLE>one</TITLE></HEAD><BODY bgcolor='#000000'>";
		winContent += "<B style='font-size:18px;font-family:Verdana,sans-serif;color:#FFFFFF;line-height:1.5'>" + soundfiledesc + "</B>";



		var safari_is_not_browser_test = 1

		if ((navigator.userAgent.indexOf("Safari") != -1) || ((navigator.userAgent.indexOf("Firefox") != -1) && (navigator.userAgent.indexOf("Macintosh") != -1)))
		{
			safari_is_not_browser_test = 0;
		}

		if (safari_is_not_browser_test != 0)
		{
			winContent += "<OBJECT ID='MediaPlayer' WIDTH=300 HEIGHT=42 classid='CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95' standby='Loading Microsoft Windows Media Player components...'  type='application/x-oleobject' CODEBASE='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112'>";
			winContent += "<PARAM NAME='ControlType' VALUE='1'>";
			winContent += "<PARAM NAME='AutoStart' VALUE='true'>";
			winContent += "<PARAM NAME='ShowDisplay' VALUE='0'>";
			winContent += "<PARAM NAME='ShowStatusBar' VALUE='0'>";
			winContent += "<PARAM NAME='cache' VALUE='false'>";
			winContent += "<PARAM NAME='FileName' VALUE='" + soundfilepath + "'>";

			winContent += "<Embed type='application/x-mplayer2' Height=42 width=300 pluginspage='http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/' Name=MediaPlayer ShowControls=1 ShowDisplay=0 ShowStatusBar=0 autostart=true Src='" + soundfilepath + "' >";
			winContent += "</embed>";
		}
		else
		{
			winContent += "<Embed type='application/x-mplayer2' Height=16 width=300 pluginspage='http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/' Name=MediaPlayer ShowControls=1 ShowDisplay=0 ShowStatusBar=0 autostart=true Src='" + soundfilepath + "' >";
			winContent += "</embed>";
		}


		if (safari_is_not_browser_test != 0)
		{
			winContent += "</OBJECT>";
		}

		//winContent += "<p style='font-size:12px;font-family:Verdana,sans-serif;text-align:center'><a href='"+soundfilepath+"'>Download this file</a> <SPAN style='font-size:10px'>(right-click or Option-click)</SPAN></p>";

		winContent += "<FORM><DIV align='center'><INPUT type='button' value='Close this window' onClick='javascript:window.close();'></DIV></FORM>";
		winContent += "</BODY>";
		winContent += "</HTML>";
		 
		 
		PlayWin.document.write(winContent);

		PlayWin.document.close(); // "Finalizes" new window
		//UniqueID = UniqueID + 1
		// newWinOffset = newWinOffset + 20 // subsequent pop-ups will be this many pixels lower.
	}

});

