if (!ismac) {
	
	if (playerType == "live") {
		document.write('<embed src="' + streamURL + '" type="audio/x-pn-realaudio-plugin" pluginspage="http://www.real.com/" width="0" height="0" name="RP" autostart="true" console="one" nojava="true" />');
	}
	else if (playerType == "music_aod" || playerType == "speech_aod") {
		document.write('<embed src="' + showName + '" type="audio/x-pn-realaudio-plugin" pluginspage="http://www.real.com/" width="0" height="0" name="RP" autostart="false" console="one" nojava="true" />');
	}
	else if (playerType == "music_promo" || playerType == "speech_promo") {
		document.write('<embed src="' + showName + '" type="audio/x-pn-realaudio-plugin" pluginspage="http://www.real.com/" width="0" height="0" name="RP" autostart="true" console="one" nojava="true" />');
	}
}

//images preloader
if(!ismac && !isopera && !isfirefox)
{	if(document.images)
	{
		butPlay=new Image;
		butPause=new Image;
		butPlay_on=new Image;
		butPause_on=new Image;

		if (playerType == "live" || playerType == "music_aod" || playerType == "music_promo")
		{
			butPlay.src='../images/' + butCol + 'play.gif'; 
			butPause.src='../images/' + butCol + 'pause.gif'; 
			butPlay_on.src='../images/' + butCol + 'play_on.gif'; 
			butPause_on.src='../images/' + butCol + 'pause_on.gif';
		}
		else
		{
			butPlay.src='../images/' + butCol + '_play_sml.gif'; 
			butPause.src='../images/' + butCol + '_pause_sml.gif'; 
			butPlay_on.src='../images/' + butCol + '_play_sml_on.gif'; 
			butPause_on.src='../images/' + butCol + '_pause_sml_on.gif';
		}
		if (playerType == "music_aod" || playerType == "music_promo")
		{
			butFF5 = new Image;
			butFF5_on = new Image;
			butFF15 = new Image;
			butFF15_on = new Image;
			butFF5.src='../images/' + butCol + '_forward5.gif';
			butFF5_on.src='../images/' + butCol + '_forward5_on.gif';
			butFF15.src='../images/' + butCol + '_forward15.gif';
			butFF15_on.src='../images/' + butCol + '_forward15_on.gif';
		}
		else
		{
			butREW1 = new Image;
			butREW1_on = new Image;
			butREW15 = new Image;
			butREW15_on = new Image;
			butREW1.src='../images/' + butCol + '_back1_sml.gif';
			butREW1_on.src='../images/' + butCol + '_back1_sml_on.gif';
			butREW15.src='../images/' + butCol + '_back15_sml.gif';
			butREW15_on.src='../images/' + butCol + '_back15_sml_on.gif';

			butFF1 = new Image;
			butFF1_on = new Image;
			butFF15 = new Image;
			butFF15_on = new Image;
			butFF1.src='../images/' + butCol + '_forward1_sml.gif';
			butFF1_on.src='../images/' + butCol + '_forward1_sml_on.gif';
			butFF15.src='../images/' + butCol + '_forward15_sml.gif';
			butFF15_on.src='../images/' + butCol + '_forward15_sml_on.gif';
		}
	}
}

//use red volume buttons for Radio Cymru
if (butCol == "cymru") {
	butCol = "red";
}

//change Playpause button to show pause
function Play()
{	
	if(!ismac && document.images)
	{	
		playing = true;
		if(document.images['playpause'].src!=butPause.src){
			document.images['playpause'].src=butPause.src;
		}
	}
}

//change playpause button to show play
function Pause()
{	
	if (!ismac && document.images)
	{	
		playing = false;
		if(document.images['playpause'].src!=butPlay.src){
			document.images['playpause'].src=butPlay.src;
		}
	}
}
		
function timeTwoChars(num)
{	if(num<10)
	{	return "0"+num;	}
	else
	{	return num;		}
}

function timeConvert(ms)
{	var msConvert=new Date(ms);
	var msHours=msConvert.getHours();
	var msMinutes=msConvert.getMinutes();
	var msSeconds=msConvert.getSeconds();
	var msConverted=timeTwoChars(msHours)+":"+timeTwoChars(msMinutes)+":"+timeTwoChars(msSeconds);
	return msConverted;
}

function PlayOrPause() {
	if(eval(document.RP.GetPlayState())==3) {
		RealPlayerPause();
	}
	else {
		RealPlayerPlay();
	}

}

//change images and instruct Real Player to do something
function RealPlayerPlay()
{	if(!ismac)
	{	Play();
		if (document.RP.CanPlay()) 
		{	document.RP.DoPlay();
		}
	}
}

function RealPlayerPause()
{	if(!ismac)
	{	Pause();
		if (document.RP.CanPause()) 
		{ 	document.RP.DoPause();
		}
	}
}

function highlight(imgname) {
	document.images[imgname].src=eval("but" + imgname + "_on").src;
}		

function unhighlight(imgname){
	document.images[imgname].src=eval("but" + imgname).src;
}

var playing;

function highlightPlayPause() {
	if (playing) {
		document.images['playpause'].src = butPause_on.src;
	}
	else {
		document.images['playpause'].src = butPlay_on.src;
	}
}

function changeSet ()
{
	if(eval(document.RP.GetPlayState())==0)
	{
		if (document.RP.GetLength() != 0 && (document.RP.GetPosition() == document.RP.GetLength()))
		{
			playing = true;
			Play();
		}
		return "Changing...";
	}	
}



//Position increase or decrease is in milliseconds

function RealPlayerStartStream(sURL)
{	if(!ismac)
	{	//alert('Playing: ' + sURL);
  		if (document.RP.CanPause()) 
		{	document.RP.DoPause();	}
  		document.RP.SetSource(sURL);
  		document.RP.DoPlay();			}	}

//detect Player State and set text to display in status box
function RealPlayerGetState()
{	if(!ismac)
	{	if(document.RP.GetPlayState()>=0)
		{	if(eval(document.RP.GetPlayState())==0)
			{
				if (document.RP.GetLength() != 0 && (document.RP.GetPosition() == document.RP.GetLength()))
				{
					playing = false;
					Pause();
				}
				return "Stopped";
			}
	 		else if(eval(document.RP.GetPlayState())==1)
			{	if(document.images['playpause'].src!=butPlay.src)
				{	Play();		}
				return "Contacting...&nbsp;";
	 		}
	 		else if(eval(document.RP.GetPlayState())==2)
			{	if(document.images['playpause'].src!=butPlay.src)
				{	Play();	}
				return ("Loading " + Math.round((document.RP.GetBufferingTimeElapsed()/1000)*100)/100 + " sec");
			}
	 		else if(eval(document.RP.GetPlayState())==3)
			{	if(document.images['playpause'].src!=butPlay.src)
				{
					Play();
				}
	 	 		var secs=document.RP.GetBandwidthAverage()/1000;
				// secs=secs.substring(0,6);
				toDisplay = "Playing " + Math.round(secs) + "kbps";
				if (toDisplay.length == 14) {
					toDisplay += "&nbsp;&nbsp;";
				}
				else if (toDisplay.length == 13) {
					toDisplay += "&nbsp;&nbsp;&nbsp;";
				}
				toDisplay += " &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; "+timeConvert(document.RP.GetPosition())+"/"+timeConvert(document.RP.GetLength());
				return toDisplay;
			}
	 		else if(eval(document.RP.GetPlayState())==4)
	 		{  	if(document.images['playpause'].src!=butPlay.src)
				{	Pause();	}
				return "Paused&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; "+timeConvert(document.RP.GetPosition())+"/"+timeConvert(document.RP.GetLength());
			}
	 		else if(eval(document.RP.GetPlayState())==5)
			{	return "Seeking";
	 		}	
		}
	}
}

//cross-browser write into status box.  This function is called every 2 seconds by the network/genre page.
function changeContent(text) 
{	if(!ismac)
	{	//IE6
    	if (document.getElementById)
		{	document.getElementById('status').innerHTML = "&nbsp;" + text;	}
		//IE 4/5
		else if (document.all)
		{	document.all('status').innerHTML = "&nbsp;" + text;	}
		//NN4+
		else if (document.layers)
		{	document.layers['statusl'].left=135;
			document.layers['statusl'].top=107;
			document.layers['statusl'].document.open();
			document.layers['statusl'].document.write('<font size="1" style="font-family:verdana,arial,helvetica,sans-serif;color:#ffffff;">&nbsp;');
			document.layers['statusl'].document.write(text);
			document.layers['statusl'].document.write('</font>');
			document.layers['statusl'].document.close();
		}
	}
}


function RealPlayerFF(minutes)
{	
	if(!ismac && document.RP.GetCanSeek())
	{	
		newTime = document.RP.GetPosition()+(minutes*60000);
		if ( newTime < document.RP.GetLength() )
		{
			document.RP.SetPosition(newTime);
		}
	}
}

function RealPlayerRew(minutes)
{	
	if(!ismac && document.RP.GetCanSeek())
	{	
		newTime = document.RP.GetPosition()-(minutes*60000);
		if (newTime >= 0) {
			document.RP.SetPosition(newTime);
		}
	}
}

//Volume increase or decrease range from 0 to 100.
			
function RealPlayerDecreaseVolume(decreaseValue)
{	if(!ismac)
	{	if (document.RP.GetVolume()) 
		{ 	if(document.RP.GetVolume()>(1 + decreaseValue))
			{	document.RP.SetVolume(document.RP.GetVolume()-decreaseValue);}
	  		else
			{	document.RP.SetVolume(1);}	}}}

function RealPlayerIncreaseVolume(increaseValue)
{
	if(!ismac)
	{	if (document.RP.GetVolume()) 
		{ 	if(document.RP.GetVolume()<= (100 - increaseValue))
			{	document.RP.SetVolume(document.RP.GetVolume() + increaseValue);}
	  		else
			{	document.RP.SetVolume(100);}	}}}


function displayVolume()
{	if (document.images)
	{	if(document.RP.GetVolume()== 1)
		{	document.images['volume'].src='../images/' + butCol + '_volume_level_0.gif';	}
		else if(document.RP.GetVolume()<= 21)
		{	document.images['volume'].src='../images/' + butCol + '_volume_level_1.gif';	}
		else if(document.RP.GetVolume()<= 41)
		{	document.images['volume'].src='../images/' + butCol + '_volume_level_2.gif';	}
		else if(document.RP.GetVolume()<= 61)
		{	document.images['volume'].src='../images/' + butCol + '_volume_level_3.gif';	}
		else if(document.RP.GetVolume()<= 81)
		{	document.images['volume'].src='../images/' + butCol + '_volume_level_4.gif';	}
		else
		{	document.images['volume'].src='../images/' + butCol + '_volume_level_5.gif';	}
	}
}

var detectableWithVB;
function detectReal()
{
    pluginFound = detectPlugin('RealPlayer');
    // if not found, try to detect with VisualBasic
	
    if(!pluginFound && detectableWithVB)
	{
		pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') || detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') || detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
    }
	
    return pluginFound;
}
function detectPlugin() 
{
	// allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;

    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) 
	{
 		var pluginsArrayLength = navigator.plugins.length;

 		// for each plugin...
 		for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) 
		{
     		// loop through all desired names and check each against the current plugin name
     		var numFound = 0;
    		for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) 
			{
  				// if desired plugin name is found in either plugin name or description
				if((navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) 
				{
      				// this name was found
     				 numFound++;
  				}   
     		}
     		// now that we have checked all the required names against this one plugin,
     		// if the number we found matches the total number provided then we were successful
     		if(numFound == daPlugins.length) 
			{
  				pluginFound = true;
  				// if we've found the plugin, we can stop looking through at the rest of the plugins
  				break;
     		}
 		}
    }

    return pluginFound;

} 
// detectPlugin
 

// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) 
{
    document.writeln('<script language="VBscript">');
 
    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = true');
    document.writeln('End If');
 
    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');
 

    document.write('</scr' + 'ipt>');
}

if(getCookie('rmRpDetectReal')!='0'){
	if (!detectReal())
	{
		var message = 'You either do not have Real Player or the Real Player plugin installed.\nPlease click OK to see our Audio Help page\nwith instructions on how to install Real Player and the plugin.\nIf you received this message but you do have Real Player and the plugin, click Cancel to stop this message appearing again.';
		var url = '/audiohelp.html';
		if (confirm(message)) {
			window.opener.location.href=url;
		}
		else{
			setCookie('rmRpDetectReal','0','6');  //remember to change to days
		}
	}
}


function pageLoaded() {
	if (window.focus) {
		window.focus();
	}

	//initialise display functions
	if(!ismac && !isopera){
		setInterval('changeContent(RealPlayerGetState())',2000);
		setTimeout('displayVolume()',1800);
	}

}

//start Window protection script
function unloadMessage()
{
	message = "You will no longer be able to listen to the Zerogravity Radio Player if you leave this page."
    return message;
}

function protectWin(onoff)
{
	window.onbeforeunload = (onoff) ? null : null;
}

protectWin(false);

window.onblur = blurred;
window.onfocus = focussed;
document.onclick = clickedonlink;

function clickedonlink()
{
	protectWin(false);
}

function blurred()
	{
		protectWin(true);
	}
	
function focussed()
	{
		protectWin(false);		
	}
	
//end Window protection script	

// generic cookies write and read

function getCookie(strCName){
	var strCookie=document.cookie;
	var strCValue;
	var iStart=strCookie.indexOf(" " + strCName + "=");
	if(iStart==-1){
		iStart=strCookie.indexOf(strCName + "=");
	}
	
	if(iStart==-1){
		strCValue=null;
	}
	else{
		iStart=strCookie.indexOf("=",iStart)+1;
		var iEnd=strCookie.indexOf(";",iStart);
		if(iEnd==-1){
			iEnd=strCookie.length;
		}
		strCValue=strCookie.substring(iStart,iEnd);
	}
	
	return strCValue;
}

function setCookie(strCName,strCValue,dLife){
	var ddate=new Date();
	ddate.setMonth(ddate.getMonth()+eval(dLife));
	dCExpires=ddate.toGMTString();
	var strCPath='/radio/aod/';
	document.cookie=strCName+'='+strCValue+';expires='+dCExpires+';Path='+strCPath+';';
	
}

// end cookies

