player_id = 0;

var popupWin = null;
var previousFileId = -1;

function pausecomp(millis) {
	var date = new Date();
	var curDate = null;
	
	do { curDate = new Date(); }
	while(curDate-date < millis);
} 

function openPopup(par) {
	var url = "/player.php?file=" + par;
	
	if( !popupWin || popupWin.closed ) {
		popupWin = window.open( url, "popupWin", "width=260,height=50,directories=no,resizable=no,status=no,scrollbars=no,toolbar=no" );
	} else popupWin.focus();
}

function fileObject(file,id,title) {
	this.file = file;
	this.id = id;
	this.title = title;
}

function loadFile(par, artist) {
	var f = new fileObject("/download.php%3Ffile=" + par + "%26type=playback", par, artist);
	var p = par + "&artist=" + artist;
	var temp = null;

	if( popupWin && !popupWin.closed ) {
		// The popup is open so call it
		popupWin.loadFile(f);
		popupWin.focus();
	} else {
		// The popup is closed so open it
		temp = openPopup(p);

		// The popup is open so call it
		pausecomp(200); // TODO: Do we need that?
		popupWin.loadFile(f);
		popupWin.focus();
	}

	return false;
}
