/**
 * Fetch http://<wherever we are now>/<name>, put the contents into an element with ID <name>, and start incrementing it's value with a timer.
 *
 * @param {name} String This represents both the URL to fetch and the element ID into which the data will be placed.
 */
function progressiveRequest(name) {
	var request = null;

	/* Create an XMLHttpRequest object: should be compatible with IE6+/Firefox/Safari/Opera */
	if (typeof XMLHttpRequest == "undefined") {
		/* Native XHR not available. Use one of these possible XHR ActiveX implementations (in order of preference) */
		mshxr = ["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];

		for (var i = 0; i < msxhr.length; i++) {
			try {
				request = new ActiveXObject(msxhr[i]);
				break;
			} catch (e) {}
		}
		throw new Error("No XMLHTTP object available");
	} else {
		request = new XMLHttpRequest();
	}

	request.open("GET", "jackpot?gid=121", true);

	/* Note: heavy use of closures. */
	request.onreadystatechange = function() {
		/* On success, extract the "jackpot" property and put the value into the element */
		if ((request.readyState == 4 || request.readyState == 'complete') && request.status == 200) {
			var response  = eval('(' + request.responseText + ')');
			var container = document.getElementById(name);
			if (container) {
        		    container.innerHTML = response.jackpot;

				container.incrementValue = function() {
					var value = parseFloat(container.innerHTML) +  (Math.floor((Math.random() * 5)) / 100);
					container.innerHTML = value.toFixed(2);

					setTimeout("document.getElementById('" + name + "').incrementValue()", 500);
				}

				container.incrementValue();
			}
		}
	}
	request.send('');
}
