/*************************************************************
 * Content Rotation
 * created by Michel Komarov (iCoder.com)
 *
 * Permanent link:
 * http://askmichel.icoder.com/2006/10/30/content-rotation/
 *
 * Got a question?
 * http://askmichel.icoder.com
 *
 * `i Code to help you profit`
 *  http://www.icoder.com
 *************************************************************/

if ("undefined" == typeof(content_rotation_instance))
	content_rotation_instance = 1;
else ++content_rotation_instance;

document.write('<div id="content_rotation'+content_rotation_instance+'"></div>');
function showContents(http_request,content_rotation_instance) {
	if (http_request.readyState == 4 && http_request.status == 200) {
		var content_div = document.getElementById("content_rotation"+content_rotation_instance);
		if (content_div) content_div.innerHTML = http_request.responseText;
	}
}
function getPage(url,content_rotation_instance) {
	var http_request = false;
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else
	if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("MSXML2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (http_request) {
		http_request.onreadystatechange = function(){ showContents(http_request,content_rotation_instance); };
		http_request.open('GET', url, true);
		http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http_request.send(null);
	}
}
if (content_rotation_list.length > 0) {
	var url = content_rotation_list[Math.floor(Math.random()*(content_rotation_list.length-1))];
	if (0 == url.indexOf("http://") || 0 == url.indexOf("https://")) {
		var pos = url.indexOf("/", 8);
		if (pos > -1) url = url.substr(pos);
		else url = "/";
	}
	var fullUrl = location.protocol+"//"+location.host;
	if (0 != url.indexOf("/")) {
		var path = location.pathname;
		var pos = path.lastIndexOf("/");
		if (pos > -1) path = path.substr(0,pos+1);
		else path = "";
		fullUrl = fullUrl+path;
	}
	getPage(fullUrl+url,content_rotation_instance);
}

