// JavaScript Document

var winHandle = null;
var window_open_options = 'width=245,height=295,resizable=false,scrollbars=no,status=no';

//Note, set timeout is used only when the window is being opened for the first time.
function play_a_song(songname) { winHandle.enqueSong(songname); }
function enqueue(songname) {
	if (winHandle && winHandle.closed) {
		//alert('The playa is closed. Open it.');
		winHandle = window.open('moozique.php','playa_window',window_open_options);
		setTimeout('play_a_song("'+songname+'")',5000);
	} else {
		winHandle = window.open('','playa_window',window_open_options);
		//alert('The win handle location is'+winHandle.location);
		if (!(winHandle.location.toString().match('moozique.php'))) { //if the location is NOT playa_sketch
			//alert('The window has been opened. However, the location is not the loaction of the playa. Reload it with the right location.');
			winHandle.location = 'moozique.php';
			setTimeout('play_a_song("'+songname+'")',5000);
		} else {
			//alert('The player window is opened. The handle has been selected.');
			play_a_song(songname);
		}
	}
	//alert('The window is at: '+winHandle.location);
	winHandle.focus();	
}
function enque(songname) { enqueue(songname); }