var icons = [];
icons['sound'] = ['/i/icon_listen.gif', '/i/icon_listen_play.gif', '/i/icon_listen.gif'];
icons['soundLarge'] = ['/i/icon_listen_large.gif', '/i/icon_listen_play_large.gif', '/i/icon_listen_large.gif'];

var playon, playoff, loading;
	
var images = [];

var isIE = navigator.appName == 'Microsoft Internet Explorer';

var MP3File = '';
var action = '';
var activeImage = null;
var activeType = null;

for(var i in icons) for(var j = 0; j < icons[i].length; j++) preloadImage(icons[i][j]);

var minFlashVer	= 6;
var swf = 'Shockwave Flash';
var plugin = 0;

var autoplayFile = '';
var autoplayFileKind = '';
var isInit = false;

if(navigator.mimeTypes && navigator.mimeTypes['application/x-shockwave-flash'] && navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin) {
  var pos = 0;
  var pos2 = 0;

  if(navigator.plugins && navigator.plugins[swf]) {
    pos = navigator.plugins[swf].description.indexOf(swf) + swf.length + 1;
    pos2 = navigator.plugins[swf].description.indexOf(".");
  }

  var swver = navigator.plugins[swf].description.substr(pos,pos2-pos);
  if(swver >= minFlashVer) plugin = true;
} else if(isIE && navigator.userAgent.indexOf('Windows') > -1) with(document) {
  write('<SCRIPT LANGUAGE=VBScript\> \n');
  write('on error resume next \n');
  write('if ( minFlashVer = 3 ) then plugin = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3")))\n');
  write('if (( minFlashVer <= 4) and (plugin <= 0 )) then plugin = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4")))\n');
  write('if (( minFlashVer <= 5) and (plugin <= 0 )) then plugin = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5")))\n');
  write('if (( minFlashVer <= 6) and (plugin <= 0 )) then plugin = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6")))\n');
  write('</SCR'+'IPT\> \n');
}


if(navigator.appName && navigator.appName.indexOf('Microsoft') != -1 && navigator.userAgent.indexOf('Windows') != -1 && navigator.userAgent.indexOf('Windows 3.1') == -1) with(document) {
  write('<SCRIPT LANGUAGE=VBScript\> \n');
  write('on error resume next \n');
  write('Sub MP3Player_FSCommand(ByVal command, ByVal args)\n');
  write('  call MP3Player_DoFSCommand(command, args)\n');
  write('end sub\n');
  write('</SCRIPT\> \n');
}

function preloadImage(src) {
  var idx = images.length;
  images[idx] = new Image();
  images[idx].src = src;
}

function play(f,image,type) {

  if(!isInit) return false;
  var flashObject = getFlashObject('MP3Player');

  if(!flashObject) return false;

  flashObject.SetVariable('_root.MP3File',f);
  action = f == MP3File ? action == 'play' && image == activeImage ? 'stop' : 'play' : 'play';

  if(action == 'play') {
    playoff = icons[type][0];
    playon = icons[type][1];
    loading = icons[type][2];
    document.images[image].src = loading;
  }

  if(activeImage && (action == 'stop' || image != activeImage)) document.images[activeImage].src = icons[activeType][0];

  playoff = icons[type][0];
  flashObject.SetVariable('_root.action',action);
  MP3File = f;
  activeImage = image;
  activeType = type;
  return false;
}
	
function init() {
  isInit = true;
  if(autoplayFile != '') {
    if(isIE) play(autoplayFile, 'autoplay_ringtone',autoplayFileKind);
    else setTimeout("play(autoplayFile,'autoplay_ringtone',autoplayFileKind)",100);
  }
}
	
function MP3Player_DoFSCommand(command, args) {
  if(command == 'loadingDone') {
    document.images[activeImage].src = playon;
  } else if(command == 'playingDone') {
    action = 'stop';
    document.images[activeImage].src = playoff;
  }
}
	
function getFlashObject(movieName) { 
  return isIE ? window[movieName] : document[movieName]
}




