

////////////////////////////////////////////////
// Called by the EP_onEvent(evt) function
// (located in 'ep_player.js') when the status of 
// the player changes.
function EP_eventHandler(evt) 
{
	// write the event to the text-area in the HTML page
	EP_logEvent(evt);
	
	switch(evt) {
		
		case 'MP3_LOADING':
			
			break;
		case 'MP3_BUFFERING':

			break;
		case 'MP3_PLAYING':
			
			// get track info
			var t = EP_getTrackInfo('ep_player');

			// write the event to the text-area in the HTML page
			EP_logEvent('playlistIndex: '+t.playlistIndex);
			EP_logEvent('location: '+t.location);
			EP_logEvent('title: '+t.title);
			EP_logEvent('annotation: '+t.annotation);
			EP_logEvent('creator: '+t.creator);
			EP_logEvent('info: '+t.info);
			EP_logEvent('image: '+t.image);
			EP_logEvent('album: '+t.album);
			EP_logEvent('trackNum: '+t.trackNum);
			EP_logEvent('link: '+t.link);
			EP_logEvent('----------------------------');

			break;			
		case 'MP3_PREV':

			break;				
		case 'MP3_NEXT':

			break;			
		case 'MP3_SELECT':
		
			// write the event to the text-area in the HTML page
			EP_logEvent("Select MP3 (#"+EP_getTrackInfo('ep_player').playlistIndex+") from playlist ...");
			
			break;
		case 'MP3_PAUSED':

			break;
		case 'MP3_COMPLETE':

			break;			
		case 'MP3_STOPPED':

			break;						
		default:
			break;
	}
}

////////////////////////////////////////////////
// write the event to the text-area in the HTML page
function EP_logEvent(evt) 
{
	ep_form.events.value += '>'+evt+'\n';
}


////////////////////////////////////////////////
var EP_playerCount = 0;


////////////////////////////////////////////////
function EP_addSingleTrack(url, artist, title) {
    var so;
    
    EP_playerCount++;
    document.write('	<div id="ep_player_' + EP_playerCount + '">\n');
    document.write('		To view the <a href="http://www.e-phonic.com/mp3player/" target="_blank">E-Phonic MP3 Player</a> you will need to have Javascript turned on and have <a href="http://www.adobe.com/go/getflashplayer/" target="_blank">Flash Player 9</a> or better installed.\n');
    document.write('	</div>\n');
    
    so = new SWFObject(pathToHome + "Resources/ep_player/ep_player.swf", "ep_player", "301", "16", "9", "#FFFFFF");
    so.addVariable("skin", pathToHome + "Resources/ep_player/skins/micro_player/skin.xml");
    //so.addVariable("playlist", "playlist.xml");
    so.addVariable("file", 
        "<location>" + toHtml(url) + "</location>" +
        "<creator>" + toHtml(artist) + "</creator>" +
        "<title>" + toHtml(title) + "</title>"
    );
    so.addVariable("autoplay", "false");
    so.addVariable("shuffle", "false");
    so.addVariable("repeat", "false");
    so.addVariable("buffertime", "1");
    so.addVariable("volume", "100");

    // this parameter activates the use of event callbacks
    // like MP3_PLAYING / MP3_PAUSED / MP3_STOPPED
    so.addVariable("notifyonevent", "true");

    so.addParam("allowscriptaccess", "always");
    so.write("ep_player_" + EP_playerCount);
    
}


////////////////////////////////////////////////
function EP_addTrackList(trackList) {
    var so, i, track;
    var playList = "";
    
    for (i = 0; i < trackList.length; i++) {
        track = trackList[i];
        if (track.length >= 2) {
            playList += "<track>";
            playList += "<location>" + toHtml(track[0]) + "</location>";
            playList += "<creator>" + toHtml(track[1]) + "</creator>";
            playList += "<title>" + toHtml(track[2]) + "</title>";
            playList += "</track>";
        }
    }
    
    EP_playerCount++;
    document.write('	<div id="ep_player_' + EP_playerCount + '">\n');
    document.write('		To view the <a href="http://www.e-phonic.com/mp3player/" target="_blank">E-Phonic MP3 Player</a> you will need to have Javascript turned on and have <a href="http://www.adobe.com/go/getflashplayer/" target="_blank">Flash Player 9</a> or better installed.\n');
    document.write('	</div>\n');
    
    so = new SWFObject(pathToHome + "Resources/ep_player/ep_player.swf", "ep_player", "269", "226", "9", "#FFFFFF");
    so.addVariable("skin", pathToHome + "Resources/ep_player/skins/nobius_platinum/skin.xml");
    //so.addVariable("playlist", "playlist.xml");
    so.addVariable("playlistxml", playList);
    so.addVariable("autoplay", "false");
    so.addVariable("shuffle", "false");
    so.addVariable("repeat", "false");
    so.addVariable("buffertime", "1");
    so.addVariable("volume", "100");

    // this parameter activates the use of event callbacks
    // like MP3_PLAYING / MP3_PAUSED / MP3_STOPPED
    so.addVariable("notifyonevent", "true");

    so.addParam("allowscriptaccess", "always");
    so.write("ep_player_" + EP_playerCount);
    
}


////////////////////////////////////////////////
function EP_detachTrackList() {
    window.open(pathToHome + "Tracks/Player.aspx", "Player", "width=269, height=226");
}


////////////////////////////////////////////////
function toHtml(text) {
    text = text.replace(/&/g, "&amp;");
    text = text.replace(/</g, "&lt;");
    text = text.replace(/>/g, "&gt;");
    text = text.replace(/"/g, "&quot;");
    text = text.replace(/'/g, "&#39;");
    return text;
}

