// Sets and updates the data in the Now Playing box including album art, artist, title and album

// Determine the browser
	var nVer = navigator.appVersion;
	var nAgt = navigator.userAgent;
	var browserName  = navigator.appName;
	var fullVersion  = ''+parseFloat(navigator.appVersion); 
	var majorVersion = parseInt(navigator.appVersion,10);
	var nameOffset,verOffset,ix;
	// In MSIE, the true version is after "MSIE" in userAgent
	if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
		browserName = "Microsoft Internet Explorer";
		fullVersion = nAgt.substring(verOffset+5);
	}
	// In Opera, the true version is after "Opera" 
	else if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
		browserName = "Opera";
		fullVersion = nAgt.substring(verOffset+6);
	}
	// In Chrome, the true version is after "Chrome" 
	else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
		browserName = "Chrome";
		fullVersion = nAgt.substring(verOffset+7);
	}
	// In Safari, the true version is after "Safari" 
	else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
		browserName = "Safari";
		fullVersion = nAgt.substring(verOffset+7);
	}
	// In Firefox, the true version is after "Firefox" 
	else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
		browserName = "Firefox";
		fullVersion = nAgt.substring(verOffset+8);
	}
	// In most other browsers, "name/version" is at the end of userAgent 
	else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) 
	{
		browserName = nAgt.substring(nameOffset,verOffset);
		fullVersion = nAgt.substring(verOffset+1);
		if (browserName.toLowerCase()==browserName.toUpperCase()) {
	 		browserName = navigator.appName;
		}
	}
	// trim the fullVersion string at semicolon/space if present
	if ((ix=fullVersion.indexOf(";"))!=-1) fullVersion=fullVersion.substring(0,ix);
	if ((ix=fullVersion.indexOf(" "))!=-1) fullVersion=fullVersion.substring(0,ix);
	majorVersion = parseInt(''+fullVersion,10);
	if (isNaN(majorVersion)) {
		fullVersion  = ''+parseFloat(navigator.appVersion); 
		majorVersion = parseInt(navigator.appVersion,10);
	}

// If brower is Safari
	if (browserName == "Safari" || browserName == "Firefox" || browserName == "Chrome") {
		function refreshAlbumArtSafari()
		{
			document.images['album-art'].src = '../NowPlaying/album.jpg?' +
			Date.parse(new Date().toString());
			window.doc.location.reload( false );
		}
		function refreshSongInfoSafari()
		{
			loadSongInfoSafari ();
			setTimeout("refreshAlbumArtSafari()", 1000);
		}
		function reloadImageSafari()
		{
			setTimeout("refreshSongInfoSafari()", 3000);
		}
		function startIntervalSafari()
		{
			oInterval=window.setInterval("reloadImageSafari()",10000);
		}
		function loadSongInfoSafari()
		{
			function setInnerHTML( html, count )
			{
				if( ! count )
					count = 1;
				if( count < 5) {
					setTimeout( function() { document.getElementById('song-info').innerHTML = html; }, 50 );
					++count;
					setTimeout( function() { setInnerHTML( html, count ); }, 50 );
				}
			}
			// Synchronous request, wait till we have it all
			var url = '../NowPlaying/tta.html';
			var html;
			var req = false;
			if (window.XMLHttpRequest) {
				try {
					req = new XMLHttpRequest();
						try {
							netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
						} catch (e) {
							//alert("Permission could be denied for cross-browser scripting.");
						}
				} catch (e) {
					req = false;
				}
			}
			req.open('GET', url, false);
			req.send(null);
			html = req.responseText;
			setTimeout( function() { document.getElementById('song-info').innerHTML = html; }, 50 );
			setInnerHTML( html, 1 );
		}
		function AttachEvent(obj,evt,fnc,useCapture)
		{
			if (obj.addEventListener) {
				obj.addEventListener(evt, fnc, useCapture ? true : false);
				return true;
			}
			else if (obj.attachEvent) {
				return obj.attachEvent("on"+evt, fnc);
			}
			else
				return false;	
		}
		var url = '../NowPlaying/tta.html';
		var oInterval="";
		loadSongInfoSafari ();
		AttachEvent(window,'load',startIntervalSafari);
	}

// If browser is MS Internet Explorer
	else if (browserName == "Microsoft Internet Explorer") {
		var doc = new ActiveXObject("htmlfile");
		doc.open();
		doc.write("<html><head><meta http-equiv='refresh' content='5'><title>Title Page</title><base target=_self></head><body bgcolor=#000000 text=#FFFFFF topmargin=0 leftmargin=0><div id='divSongInfoHidden'><iframe id='SongInfoHidden' src='../NowPlaying/tta.html' name='SongInfoHidden' width=300 height=60 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no background-color: #000033 text=#FFFFFF></iframe></div></body></html>");
		doc.close();
		AttachEvent(window,'load',startInterval);
		function AttachEvent(obj,evt,fnc,useCapture)
		{
			if (obj.addEventListener) {
				obj.addEventListener(evt, fnc, useCapture ? true : false);
				return true;
			}
			else if (obj.attachEvent) {
				return obj.attachEvent("on"+evt, fnc);
			}
			else
				return false;	
		}
		var oInterval="";
		function startInterval()
		{
			oInterval=window.setInterval("reloadImage()",10000);
			window.doc.location.reload( false );
			var ttaIframe = "";
			var ttaIframe = doc.getElementById('SongInfoHidden');
			var ttaContent = ttaIframe.contentWindow.document.body.innerHTML;
			var songinfoDiv = document.getElementById('song-info');
			songinfoDiv.innerHTML = ttaContent;
			if(document.images)
			{
				document.images['album-art'].src = '../NowPlaying/album.jpg?' +
				Date.parse(new Date().toString());
			}
		}
		function reloadImage()
		{
			window.doc.location.reload( false );
			setTimeout("refreshSongInfo()", 3000);
		}
		function refreshSongInfo()
		{
			var ttaIframe = "";
			var ttaIframe = doc.getElementById('SongInfoHidden');
			var ttaContent = ttaIframe.contentWindow.document.body.innerHTML;
			var songinfoDiv = document.getElementById('song-info');
			if (songinfoDiv.innerHTML != ttaContent)
		   {
				songinfoDiv.innerHTML = ttaContent;
				setTimeout("refreshAlbumArt()", 1000);
		   }
		}
		function refreshAlbumArt()
		{
			if(document.images)
			{
				document.images['album-art'].src = '../NowPlaying/album.jpg?' +
				Date.parse(new Date().toString());
			}
		}
	}
