/*******************************************************************************
 * Functions for dealing with the media player.
 *
 * Prerequisites:
 *  ufo.js (at http://www.chorderator.com/ufo.js)
 *  Define chorderatorBase
 *  Element with id flashVideo.
 ******************************************************************************/

function loadPlayerAdvanced(id, file, repeat, div)
{
  var FO = {
	  id:id,
	  name:id,
	  movie:"../mediaplayer.swf",
	  width:"320",
	  height:"0",
	  majorversion:"7",
	  build:"0",
	  bgcolor:"#FFFFFF",
	  flashvars:"enablejs=true&javascriptid="+id+"&file="+file+"&repeat="+repeat
  };
  UFO.create(FO,div);
}
  

function loadPlayer()
{
  var FO = {
	  id:"mpl",
	  name:"mpl",
	  movie:"../mediaplayer.swf",
	  width:"320",
	  height:"0",
	  majorversion:"7",
	  build:"0",
	  bgcolor:"#FFFFFF",
	  flashvars:"enablejs=true&javascriptid=mpl"
  };
  UFO.create(FO,"flashVideo");
}

// This is a javascript handler for the player and is always needed.
function thisMovie(movieName) {
  if(navigator.appName.indexOf("Microsoft") != -1) {
    return window[movieName];
  } else {
    return document[movieName];
  }
}

function playInterval(note1, note2, harmonic)
{
  // ES: HACK!!
  if (typeof(chorderatorBase) != 'undefined') {
    cb = chorderatorBase;
  } else {
    cb = 'http://www.chorderator.com';
  }
  if (!cb || cb.indexOf('localhost') != -1) {
    cb = 'http://test.eddieboston.com';
  }
  // ES: END HACK
  if (note2 == null) {
    note2 = note1 + 27;
    note1 = 27;
  }
  if (typeof(note1) == 'number') {
    note1 = NoteNumToName(note1, '#', true);
    note2 = NoteNumToName(note2, '#', true);
  }
  var mp3File = (note1 + '-' + note2).replace(/#/g, 's');
  if (harmonic) {
    mp3File = cb + '/cgi-bin/getChord.py?shift=0&fileName=' + escape(mp3File) + '.mp3';
  } else {
    mp3File = cb + '/cgi-bin/getChord.py?interval=true&fileName=' + escape(mp3File) + '.mp3';
  }
  obj = {file:mp3File};
  thisMovie("mpl").loadFile(obj);
  thisMovie("mpl").sendEvent('prev', null);
}

function playAgain()
{
  thisMovie("mpl").sendEvent('prev', null);
}

function playMp3(mp3File, shift)
{
  if (shift == null) {
    shift = 0.3;
  }
  // ES: HACK!!
  if (typeof(chorderatorBase) != 'undefined') {
    cb = chorderatorBase;
  } else {
    cb = 'http://www.chorderator.com';
  }
  if (cb.indexOf('localhost') != -1) {
    cb = 'http://test.eddieboston.com';
  }
  // ES: END HACK
  mp3File = mp3File.replace(/#/g, 's')
  mp3File = cb + '/cgi-bin/getChord.py?shift=' + shift + '&fileName=' + escape(mp3File);
  obj = {file:mp3File};
  thisMovie("mpl").loadFile(obj);
  thisMovie("mpl").sendEvent('prev', null);
}

function playUrl(url)
{
  thisMovie("mpl").loadFile({file:url});
  thisMovie("mpl").sendEvent('prev', null);
}
