/*
 * A note about what's going on:
 *
 * Opening a window as the result of a Flash => Javascript call back triggers
 * popup blocking software. In order to circumvent this, we check a variable on
 * the object to see if the window needs to be opened, and open it if we do.
 * However, it takes a few hundred milliseconds for this to be set, so we need
 * to poll it. However x 2, we can't poll it from a while loop or it never gets
 * set, because Javascript is using 100% CPU. So, we poll it every 100
 * milliseconds and set a global variable - we then look at this global
 * variable to make the decision of whether or not to open a window. This value
 * won't get set until passData has been called, so we send an invalid XML
 * fragment to make sure it gets called, and the Flash throws the invalid XML
 * away. - AWDB 12/06/06
 */
/* We no longer have to send a passData with invalid XML - the Flash starts the
 * polling process automatically, and does so every 6 frames. 
 */

function radio_openPlayer(trackNo, hn, up) {
  window.open(up + "/" + hn + "/player.php?xml=" + trackNo,'player',"toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=305, height=394");
}

function aff_radio_openPlayer(trackNo, aff, hn) {
  window.open('http://' + aff + "-" + hn + ".buyassociation.co.uk/" + hn + "/player.php?xml=" + trackNo,'player',"toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=305, height=394");
}

function radio_play_button_click() {
	radio_openPlayer(trackNo, hn, up);
}

function aff_radio_play_button_click(aff) {
	if(arguments.length == 1) {
		aff_radio_openPlayer(trackNo, aff, 'property');
	} else if(arguments.length == 3) {
		aff_radio_openPlayer(arguments[1], aff, arguments[2]);
	} else { /* 2 ? */
		aff_radio_openPlayer(arguments[1], aff, 'property');
	}
}

function printRadioButton(a) {
  var addition = '';
  if(arguments.length != 1) {
    addition = arguments[1];
  }
  if (!(navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Mac") != -1) && hasRightVersion) {
    document.write('<a href="javascript:radio_play_button_click()"><img src="' + up + '/images/en/template/'+addition+'listen-now" border="0"/></a>');
  } else { 
    document.write('<a href="' + up + '/listen/' + a + '.mp3?noflash.mp3"><img src="' + up + '/images/en/template/'+addition+'listen-now" border="0"/></a>');
  }
}

function printOrangeRadioButton(a) {
  if(arguments.length != 1) {
    addition = arguments[1];
  }
  if (!(navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Mac") != -1) && hasRightVersion) {
    document.write('<a href="javascript:radio_play_button_click()"><img src="' + up + '/images/en/orange/listen_now" border="0"/></a>');
  } else { 
    document.write('<a href="' + up + '/listen/' + a + '.mp3?noflash.mp3"><img src="' + up + '/images/en/orange/listen_now" border="0"/></a>');
  }
}

function aff_printRadioButton(id, link, aff) {
  if(arguments.length == 4) {
	hn = arguments[3];
  } else {
	hn = 'property';
  }
  if (!(navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Mac") != -1) && hasRightVersion) {
	document.write('<a href="javascript:aff_radio_play_button_click(\'' + aff + '\', ' + id + ', \'' + hn + '\')">' + link + '</a>');
  } else { 
    document.write('<a href="http://' + aff + '-' + hn + '.buyassociation.co.uk/' + hn + '/listen/' + a + '.mp3?noflash.mp3">' + link + '</a>');
  }
}
