// Values for the player vars if different to the default ones specified in createPlayer()
var playerVars = new Array();

playerVars['radiovague-player'] = new Array();
playerVars['radiovague-player']['playlistUrl'] = "/droid/playlist.xml";
playerVars['radiovague-player']['backcolor'] = "0x000000";
playerVars['radiovague-player']['frontcolor'] = "0xCCCCCC";
playerVars['radiovague-player']['lightcolor'] = "0xCC0000";
playerVars['radiovague-player']['screencolor'] = "0x000000";
playerVars['radiovague-player']['displaywidth'] = "0";
playerVars['radiovague-player']['playerheight'] = "20";
playerVars['radiovague-player']['popupWidth'] = "290";
playerVars['radiovague-player']['popupHeight'] = "145";

playerVars['giss-player'] = new Array();
playerVars['giss-player']['playlistUrl'] = "/mp3player/live1.xml";
// End player vars ///////////////////////////////////////////////////////////////////////

var currentItem, currentState;
var showFlag = new Array(), playerWindows = new Array(), playingFlag = true;

function sendEvent(typ,prm,theId) { 
	theId = theId?theId:'thePlayerId';
	thisMovie(theId).sendEvent(typ,prm,theId); 
};

// 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 createPlayer(thePlace, theId) {
	if (!theId) var theId = thePlace;

	// Set defualt values for the player vars if they're not defined already
	var playlistUrl = (playerVars[theId] && playerVars[theId]['playlistUrl']) ? playerVars[theId]['playlistUrl'] : "/mp3player/mp3player.swf";
	var backcolor = (playerVars[theId] && playerVars[theId]['backcolor']) ? playerVars[theId]['backcolor'] : "0x000000";
	var frontcolor = (playerVars[theId] && playerVars[theId]['frontcolor']) ? playerVars[theId]['frontcolor'] : "0xCCCCCC";
	var lightcolor = (playerVars[theId] && playerVars[theId]['lightcolor']) ? playerVars[theId]['lightcolor'] : "0xCC0000";
	var screencolor = (playerVars[theId] && playerVars[theId]['screencolor']) ? playerVars[theId]['screencolor'] : "0x000000";
	var displaywidth = (playerVars[theId] && playerVars[theId]['displaywidth']) ? playerVars[theId]['displaywidth'] : "150";
	var playerHeight = (playerVars[theId] && playerVars[theId]['playerheight']) ? playerVars[theId]['playerheight'] : "150";

	showFlag[thePlace]=true;

	var s = new SWFObject("/mp3player/mp3player.swf", theId, "100%", playerHeight, "7");
	s.addVariable("file", playlistUrl);
	s.addVariable("backcolor", backcolor);
	s.addVariable("frontcolor", frontcolor);
	s.addVariable("lightcolor", lightcolor);
	s.addVariable("displaywidth", displaywidth);
	s.addVariable("screencolor", screencolor);

	s.addVariable("showdigits", "false");
	s.addVariable("shuffle", "false");
	s.addVariable("autostart", "false");

	s.addVariable("enablejs", "true");
	s.addVariable("javascriptid", theId); 

	s.write(thePlace);
}

function createWindow(adr,thePlace) {
	var theId = thePlace;

	var popupWidth = (playerVars[theId] && playerVars[theId]['popupWidth']) ? playerVars[theId]['popupWidth'] : "500";
	var popupHeight = (playerVars[theId] && playerVars[theId]['popupHeight']) ? playerVars[theId]['popupHeight'] : "150";

	showFlag[thePlace]=true;
  	sendEvent("stop", '', theId);
  
  	document.getElementById(thePlace).style.visibility="hidden";
  	playerWindows[thePlace]=window.open(adr, thePlace, "width=" + popupWidth + ",height=" + popupHeight + ",left=400,top=400,resizable=yes");
  	playerWindows[thePlace].focus();
}

function showhide(thePlace) { 
	var theId = thePlace;
	
	if (showFlag[thePlace]) { 
		document.getElementById(thePlace).style.visibility="visible";
		if (playerWindows[thePlace]) playerWindows[thePlace].close();
		showFlag[thePlace]=true;
		sendEvent('playitem', currentItem, theId); 					
	} else { 
		document.getElementById(thePlace).style.visibility="hidden";
		showFlag[thePlace]=false;
	}
}

function getQueryStringParameter(name) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(window.location.href);

	if (results == null)
		return false;
	else
		return results[1];
}