
var playerWindow;
var playerTimer;

function getObject(id) {
    var obj;

    if (document.all) obj = document.all[id];
    else if (document.getElementById) obj = document.getElementById(id);
    else if( document.getElementsByName) obj = document.getElementsByName(id);

    return obj;
}


// play sound in popup player
function playSound(path, author, name) {
    getObject("AudioPlayer").playSound(path, author, name);

}

function playSound2(path, author, name) {
    getObject("AudioPlayer2").playSound(path, author, name);
}


// stop sound in player (in site top), don't touch this!
function stopSound() {
    getObject("AudioPlayer").stopSound();
}


// open player in popup and play sound
function openAudioPlayer(index) {

	  if (!playerWindow || playerWindow.closed) {
		 playerWindow = window.open("/radioonline?index="+index, "player", "width=340,height=50");

		 clearInterval(playerTimer);
		 playerTimer = setInterval(validateAudioPlayer, 500);
	  }

}

// validate player state by interval
function validateAudioPlayer() {

	if (playerTimer) {
		if (!playerWindow || playerWindow.closed) {
			clearInterval(playerTimer);
			playerTimer = null;
			stopSound();
		}
	}
}


// html/js control handlers
function btnClick(path2) {
   var obj = {path:""+path2+"", author:"AU-0", name:"song0"};
   playSound(obj.path, obj.author, obj.name);
}

