/**
  * mp3playa - Streaming Flash Mp3 player
  *
  * Copyright (C) 2004  troels knak-nielsen <troels@kyberfabrikken.dk>
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License.
  * 
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  * 
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  */

/**
  * @private
  * @see pollPlaya()
  */
var _playaTmp;

/**
  * internal function to retrieve player-object
  * @private
  */
function getPlaya()
{
	if (navigator.appName.indexOf ("Microsoft") !=-1) {
		var p = window["playa"];
	} else {
		var p = document["playa"];
	}
	if (typeof(p) != "undefined") {
		if (p.PercentLoaded() == 100) {
			return p;
		}
	}
	return null;
}

/**
  * This is the main loop
  * @private
  */
function pollPlaya()
{
	var p = getPlaya();
	if (p != null) {
		var params = new Object();
		params.title = p.GetVariable("jsTitle");
		params.playListPosition = parseInt(p.GetVariable("jsPlayListPosition"));
		if (_playaTmp != (params.title + params.playListPosition)) {
			_playaTmp = params.title + params.playListPosition;

			params.path = p.GetVariable("jsPath");
			params.btnState = p.GetVariable("jsBtnState");
			params.playlistSize = parseInt(p.GetVariable("jsPlaylistSize"));

			//PlayaUpdateInterface(params);
		}
	}
	setTimeout("pollPlaya()", 200);
}
pollPlaya();

/**
  * Fire this event when user press the play/stop button
  * @public
  */
function PlayaDoPlayStop() {
	var p = getPlaya();
	if (p != null) {
		p.SetVariable("remoteRequest", "PlayStop");
	}
}

/**
  * Fire this event when user press the next button
  * @public
  */
function PlayaDoNext() {
	var p = getPlaya();
	if (p != null) {
		p.SetVariable("remoteRequest", "Next");
	}
}

/**
  * Update interface here
  * Most likely this is the only function you will need to tamper with
  * @public
  */
function PlayaUpdateInterface(params)
{
	sTitle = (params.playListPosition+1) + "/" + params.playlistSize + " ";
	if (params.path == "") {
		sTitle += params.title;
	} else {
		sTitle += "<a href=\"" + params.path + "\" target=\"_blank\" title=\"Click to download\">" + params.title + "</a>";
	}

	//document.getElementById("songTitle").innerHTML = sTitle;
	//document.getElementById("btnPlayStop").value = params.btnState;
}