/*
Flash-less scroller with overlay.
Original coding by Rick Osborne, Dixon Ticonderoga, 2007-10-13
Dude, I am totally über-l33t.  omgponies.
 */
function ajax(url, vars, callbackFunction){
	var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
	request.open("GET", url, true);
	// request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	request.onreadystatechange = function(){
		if((request.readyState == 4) && (request.status == 200)) {
			if(request.responseXML) callbackFunction(request.responseXML);
			else if(request.responseText) callbackFunction(request.responseText);
		}
	}
	request.send(vars);
} // ajax
function doScroll() {
	var si = document.getElementById('scrollimgs');
	var i;
	var c;
	for(i = 0; i < si.childNodes.length; i++) { // >
		c = si.childNodes[i];
		var ol = parseInt(c.style.left);
		c.style.left = (ol - document.scrollSpeed) + 'px';
	} // for i
	for(i = 0; i < si.childNodes.length; i++) { // >
		c = si.childNodes[i];
		var l = parseInt(c.style.left);
		if((l + c.width) < 0) { // >
			c.style.left = (l + si.totalWidth) + 'px';
		} // if offscreen
	} // for i
	if(!document.stopScroll) setTimeout(doScroll, 150);
} // doScroll
function fadeScroll(o) {
	if(o == null) o = 0.05;
	var si = document.getElementById('scrollimgs');
	si.style.opacity = o;
	if(si.style.opacity < 1.0) { //>
		o += 0.1;
		setTimeout('fadeScroll('+o+')',100);
	} else {
		document.stopScroll = false;
		doScroll();
	}
} // fadeScroll
function setupScroll(x) {
	if(typeof(x) != 'object') return null;
	var si = document.getElementById('scrollimgs');
	var r = x.documentElement;
	var i;
	var l = 0;
	var a = [];
	for(i = 0; i < r.childNodes.length; i++) { //>
		var n = r.childNodes[i];
		if(n.nodeName.toUpperCase() == 'IMG') a.push(n);
	} // for i
	for(i = 0; i < a.length; i++) { //>
		var o = Math.floor(Math.random() * a.length);
		var t = a[o];
		a[o] = a[i];
		a[i] = t;
	} // var i
	for(i = 0; (i < a.length) && (i < 4); i++) { //>
		var n = a[i];
		var m = document.createElement('IMG');
		var w = parseInt(n.getAttribute('width'));
		m.src = n.getAttribute('src');
		m.width = w;
		m.height = parseInt(n.getAttribute('height'));
		m.style.left = l + 'px';
		l += w + 2;
		si.appendChild(m);
	} // for i
	si.totalWidth = l;
	si.style.opacity = 0;
	si.style.display = 'block';
	setTimeout("fadeScroll()",2000);
} // setupScroll
function fetchScroll(url) {
	var s = document.getElementById('scroll');
	var si = document.createElement('DIV');
	si.id = 'scrollimgs';
	s.appendChild(si);
	var o = document.createElement('A');
	o.href = url;
	document.scrollSpeed = 1;
	// o.onclick = function() { document.stopScroll = !document.stopScroll; if(!document.stopScroll) doScroll(); return false; };
	o.onmouseover = function() { document.scrollSpeed = 4; }
	o.onmouseout = function() { document.scrollSpeed = 1; }
	o.id = 'scrolloverlay';
	s.appendChild(o);
	ajax('/scroll.xml', null, setupScroll);
} // fetchScroll
