// by Doug Wyatt, doug@sonosphere.com, April 2006
// http://sonosphere.com/
// (c) 2006 Doug Wyatt, released under the MIT License:
// http://www.opensource.org/licenses/mit-license.php

var jukeboxFlashPlayer = '/flash/xspf_player/xspf_player.swf';
var jukeboxBackgroundColor = "#DFDFF4";
var jukeboxFlashButton = '/flash/button/musicplayer.swf';
var jukeboxPopupTitle = 'dougwyatt.net player';

function embedJukebox2(fo) {
	// http://flash-mp3-player.net/players/multi/
	if (fo) {
		// Flash movie successfully loaded
		fo.write("jukeboxFlash"); // inserts the Flash HTML code into the jukeboxFlash div
		changeDisplay('jukeboxMP3s', 'none');
		changeDisplay('jukeboxFlash', 'block');
		// hide the MP3 div, and make the Flash div visible
		document.write('<span id="jukeboxFlashLinks">');
		q = "'";
		s = '<a href="javascript:doIt();" onclick="javascript:popupJukebox('+w+','+h+','+q+url+q+','+q+ptitle+q+');">Open popup player</a> ';
		document.write(s);
		document.write('| <a href="javascript:doIt();" onclick="javascript:showMP3s();">audio files</a></span>');
		document.write('<span id="jukeboxMP3Links" style="display: none"><a href="javascript:doIt();" onclick="javascript:showFlash()">Flash player</a></span>');
	}
}

function embedJukebox(w, h, url, ptitle) {
	// http://musicplayer.sourceforge.net/
	var fo = new FlashObject(jukeboxFlashPlayer, "myFlashJukebox", w, h, "7", jukeboxBackgroundColor);
	fo.addVariable('playlist_url', url);
	fo.addVariable('player_title', ptitle);
	if (fo) {
		// Flash movie successfully loaded
		fo.write("jukeboxFlash"); // inserts the Flash HTML code into the jukeboxFlash div
		changeDisplay('jukeboxMP3s', 'none');
		changeDisplay('jukeboxFlash', 'block');
		// hide the MP3 div, and make the Flash div visible
		document.write('<span id="jukeboxFlashLinks">');
		q = "'";
		s = '<a href="javascript:doIt();" onclick="javascript:popupJukebox('+w+','+h+','+q+url+q+','+q+ptitle+q+');">Open popup player</a> ';
		document.write(s);
		document.write('| <a href="javascript:doIt();" onclick="javascript:showMP3s();">MP3s</a></span>');
		document.write('<span id="jukeboxMP3Links" style="display: none"><a href="javascript:doIt();" onclick="javascript:showFlash()">Flash player</a></span>');
	}
}

function popupJukebox(w, h, url, ptitle) {
	args = 'toolbar=no,location=no,directories=no,status=no,';
	args += 'menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+w+',height='+h+', screenX=400,screenY=200,top=200,left=300';
	win = window.open('','jukebox', args);
	win.document.write('<html><head><title>'+jukeboxPopupTitle+'</title></head><body style="margin: 0; padding: 0">');
	var fo = new FlashObject(jukeboxFlashPlayer, "myFlashJukebox", w, h, "7", jukeboxBackgroundColor);
	fo.addVariable('playlist_url', url);
	//fo.addVariable('detectflash', 'false');
	fo.addVariable('autoplay', 'true');
	fo.addVariable('player_title', ptitle);
	html = fo.getFlashHTML();
	win.document.write(html);
	win.document.write('</body></html>');
	win.document.close();
	win.focus();
}

function embedPlayButton(elemid, buttonid, songurl) {
	var fo = new FlashObject(jukeboxFlashButton, buttonid, 17, 17, "7", jukeboxBackgroundColor);
	fo.addVariable('song_url', songurl);
	if (fo)
		fo.write(elemid);
}

function doIt() { }

function showMP3s() {
	changeDisplay('jukeboxFlash', 'none');
	changeDisplay('jukeboxFlashLinks', 'none');
	changeDisplay('jukeboxMP3s', 'block');
	changeDisplay('jukeboxMP3Links', 'inline');
}

function showFlash() {
	changeDisplay('jukeboxFlash', 'block');
	changeDisplay('jukeboxFlashLinks', 'inline');
	changeDisplay('jukeboxMP3s', 'none');
	changeDisplay('jukeboxMP3Links', 'none');
}

// http://www.howtocreate.co.uk/tutorials/javascript/dhtml
function changeDisplay( elementId, setTo ) {
   var theElement;
  if( document.getElementById ) {
    //DOM
    theElement = document.getElementById( elementId );
  } else if( document.all ) {
    //Proprietary DOM
    theElement = document.all[ elementId ];
  }
  if( !theElement ) {
    /* The page has not loaded, or the browser claims to
    support document.getElementById or document.all but
    cannot actually use either */
    return;
  }
  //Reference the style ...
  if( theElement.style ) { theElement = theElement.style; }
  if( typeof( theElement.display ) == 'undefined' ) {
    //The browser does not allow us to change the display style
    //Alert something sensible (not what I have here ...)
   	//window.alert( 'Your browser does not support this' );
    return;
  }
  //Change the display style
  theElement.display = setTo;
}

// for blog: show "more" for entry bodies
function showMore(eid) {
changeDisplay('more'+eid, 'none');
changeDisplay('body'+eid, 'block');
}
