//////////////////////////////////////////////////////////////////////////////////////////
// openTunePlayer() function
//
// Function to create a new window to act as a media player.  The new window will
// use the default media player for the file type passed in based upon the user's
// browser settings.  For example, Mac users would likely see an .mp3 file supported
// via QuickTime while Windows users would likely see it supported by Windows Media
// player.
//
// This function takes the basic information about the media file as a parameter
// and creates the new window based upon what it passed in.
//
// USAGE:
// 
// - Call this function while passing it parameters
// - Parameters required are: Artist, Title, URL
// - Format as follows: openTunePlayer('artist','title','url')
//
// EXAMPLE:
//
// <a href="javascript:openTunePlayer('Holograms','Are You Ready For It','./Are-You-Ready-For-It.mp3');">Holograms - Are You Ready For It</a>
//
// TO DO:
//
// Find a way to determine if the popup is still open, and if so, close it before loading new window.
// this must be done to solve odd behaviour in Safari where each track keeps playing over the last.
//


function openTunePlayer(artist,title,tuneURL) {

		// This is a bit funky, but it works...
		// opens a tunePlayer window first if one isn't already open
		// this is done in order to make sure that an existing tunePlayer window 
		// gets closed before loading the next audio sample
		window.open('','tunePlayer','left=20,top=20,width=275,height=150,menubar=0,toolbar=0,status=0,scrollbars=0,resizable=0','replace').close();
		
		// create a reference to a new window which we create
		// new window is given name 'tunePlayer' 
 		tunePlayerRef=window.open('','tunePlayer','left=20,top=20,width=275,height=150,menubar=0,toolbar=0,status=0,scrollbars=0,resizable=0','replace');
 	
 		// write data into the new window
 		tunePlayerRef.document.write(
 			'<html> \n \
  			<head>	\n \
  			<title>Tune Player</title> \n \
  			</head> \n \
  			<body onLoad="self.focus()"> \n \
			<div align="center"> \n \
			<body bgcolor="#F5F5D6" link="maroon" vlink="#b22222"> \n \
			<font size="1" color="#3c3939" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"> \n \
   			<img src="http://www.djculture.com/tuneplayer/images/playerhead.jpg"> \n \
   			<hr> \n \
   			Artist: ' + artist + '<br> \n \
   			Title : ' + title + '<br> \n \
   			<embed src="' + tuneURL + '" autostart="true" loop="false" width="250" height="42" controller="true"></embed> <br>\n \
   			<a href="javascript:window.close();">Close Window</a> \n \
   			</body> \n \
   			</html>');
   			
   		
   		// close access for writing
 		tunePlayerRef.document.close()
 		
 		
 		
}