	// how many seconds you want between updates of the track info
	var updateInterval = 45;
	
	// Define some messages for the "contact us" section in the stream player:
	var contactAutomation = "<a href=\"mailto:wuvtamfm@vt.edu?subject=Website+Feedback\">wuvtamfm@vt.edu</a>";
	var contactDJ = "540-231-WUVT [540-231-9888] / <a href=\"aim:goim?screenname=WUVTFMBLACKSBURG\">WUVTFMBLACKSBURG</a> on AIM"

	// Define the "cute" automation name:
	var cuteAutomationName = "Our Robot Johnny 5 <em>(Automation)</em>";

	// DJ playlist link and variable for use later in displaying link:
	var djPlaylistLink = "http://www.wuvt.vt.edu/playlists_dj?action=chooseDate&s_DJName=";
	var myDJLink = "";

/*	// define the alternate message for the web stream
	var altMsg = "<b>Requests?</b> <font color=\"white\">(540) 231-9888</font> or "
				 + "<font color=\"white\"><a href=\"mailto:wuvtamfm@vt.edu\">wuvtamfm@vt.edu</a></font>";
*/
				 
	// this function from: http://snipplr.com/view/132/detect-ie/
	function isIE() {
	return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
	}

	// this function uses an AJAX request to grab the latest track.
	// (this function made using the tutorial at:   http://www.xul.fr/en-xml-ajax.html)
	function getLatestTrack(varStream) {

		// define these for the date and time to be combined:
		var myDate = "";
		var myTime = "";
		
		var xhr;
		var child;
		var brother;
		var crack;
		
		// Create the XMLHTTP object (for both IE & non-IE browsers)
		try {		// try the standard version first!  ==> this means ie7/8, moz, webkit, opera
			xhr = new XMLHttpRequest();
		} catch (err) {
			try {
				xhr = new ActiveXObject('MSXML2.XMLHTTP.6.0');		// latest MSXML
			} catch (err) {
				try {
					xhr = new ActiveXObject('MSXML2.XMLHTTP.3.0');		// newer MSXML
				} catch(err) {
					try {
						xhr = new ActiveXObject("MSXML2.XMLHTTP");	// newish
					} catch (err) {
						try {
							xhr = new ActiveXObject("Microsoft.XMLHTTP");    // Trying the old & busted activex control for Internet Explorer 
						} catch(err) {
							//// wheee put code here to unhide the refesh button!
							//document.getElementById("btnRefresh").style.display = "block";
							alert("Your browser is unable to make AJAX requests.  Please upgrade or speak to your system administrator.");
						}
					}
				}
			}
		}
		
		// define the inline callback function
		xhr.onreadystatechange = function() {
			// if the XMLHTTP object is ready:
			if (xhr.readyState == 4) {
				// update the track info if the HTTP server request was successful:
				if (xhr.status == 200) {
					
					for (child = xhr.responseXML.firstChild; child != null; child = child.nextSibling) {	
						for (brother = child.firstChild; brother != null; brother = brother.nextSibling)
						{	
								// create function to find artist and track title. 
							for (crack = brother.firstChild; crack != null; crack = crack.nextSibling) {

								if (brother.nodeName == "title") {
									document.getElementById("currTitle").innerHTML = crack.data;
								}
								if (brother.nodeName == "artist") {
									document.getElementById("currArtist").innerHTML = crack.data;
								}
								if (brother.nodeName == "album") {
									document.getElementById("currAlbum").innerHTML = crack.data;
								}
								if (brother.nodeName == "label") {
									document.getElementById("currLabel").innerHTML = crack.data;
								}
								if (brother.nodeName == "dj") {									
									if (crack.data == "Automation") {
										document.getElementById("contact").innerHTML = contactAutomation;
										document.getElementById("currDJ").innerHTML = cuteAutomationName;
									} else {
										document.getElementById("contact").innerHTML = contactDJ;

										myDJLink = "<a href=\"" + djPlaylistLink + escape(crack.data) + "\" title=\"View DJ's Playlists (in a new window)\" target=\"_blank\">" + crack.data + "</a>";
										myDJLink = myDJLink.replace("%20", "+");
										document.getElementById("currDJ").innerHTML = myDJLink;
									}
										
								}
								if (brother.nodeName == "date") {
									myDate = crack.data;

									document.getElementById("currDate").innerHTML = myDate + " " + myTime;

								}
								if (brother.nodeName == "time") {
									myTime = crack.data;

									document.getElementById("currDate").innerHTML = myDate + " " + myTime;
								}
								
							}
						}	
					}
		
				}
			}
		};
		
		// activate the HTTP response
		
		xhr.open("GET", "http://www.wuvt.vt.edu/playlists/latest_track_xml.php", true);

//		// fix for IE caching bug:  from http://www.webmasterworld.com/forum91/4202.htm
//		if (isIE()) {
			xhr.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
//		}

		xhr.send(null);
//		xhr.overrideMimeType("text/xml");
	}

	
	// this function is called in the onLoad section of the body to update the track info:
	function startTimerUpdates() {
		// start a looping timer:
		setInterval("getLatestTrack(false)", updateInterval * 1000);
	}

	// this function is called in the onLoad section of the body to update the track info AND initially update values!
	function startDisplay() {
		getLatestTrack(false);

		// start a looping timer:
		setInterval("getLatestTrack(false)", updateInterval * 1000);
	}



// ----------------------- EMAIL LINK GENERATOR! (2011-01-14 / JM) ---------------------------
var myCRLF = "%0D%0A";

var myEmail =   "wuvtamfm@vt.edu";
var mySubject = "HTML5 Web Player Problems";
var myMessage =                 "Describe your problem here:" + myCRLF + myCRLF + myCRLF + myCRLF;
myMessage = myMessage +         "Your browser information: (automatically filled in - please leave it here!)"  + myCRLF;
myMessage = myMessage +         "Browser:%20%20%20%20" + navigator.userAgent + myCRLF;
myMessage = myMessage +         "Platform:%20%20%20%20" + navigator.platform + myCRLF;

mySubject = mySubject.replace(" ", "%20");
myMessage = myMessage.replace(" ", "%20");
myMessage = myMessage.replace(",", "%2C");
myMessage = myMessage.replace(":", "%3A");
myMessage = myMessage.replace(";", "%3B");
myMessage = myMessage.replace("(", "%28");
myMessage = myMessage.replace(")", "%29");
myMessage = myMessage.replace("/", "%2F");

function displayProblemMessageLink() {
        myLinkString =  "wuvtamfm@vt.edu";
        myLinkURL =     "mailto:" + myEmail + "?subject=" + mySubject + "&body=" + myMessage;

        myLinkHTML =    "<a href = \"" + myLinkURL + "\">" + myLinkString + "</a>";

        document.write(myLinkHTML);
}
// --------------------------------------- END LINK GENERATOR -----------------------------------



/*	---------------------------------------------------------IGNORE BELOW---------------------------------------	
	// this function shows the alternate message: (for the stream player)
	function showStreamTrack() {
		getLatestTrack();
		document.getElementById("currTrack").innerHTML = "<b style=\"font-weight: bolder\">Now Playing:</b> <span style=\"color:white\">"
														 + document.getElementById("currTrack").innerHTML + "</span>";
	}

	// this function is called in the onLoad section of the body to update the track info for the stream:
	function startStreamUpdates() {
		// start a looping timer:
		setInterval("getLatestTrack(true)", updateInterval * 1000);
	}

	// this function is called in the onLoad section of the stream player to update the track info:
	function startStreamUpdates() {
		// start a looping timer:
		setInterval("getLatestTrack()", updateInterval * 1000);
		// start a looping timer:
		setInterval("showAltMsg()", updateInterval + (0.7 * updateInterval) * 1000);
	}
	---------------------------------------------------------------------------------------------------------- */

