function loadXMLDoc(offset, all, starts) {
	if (isloading == 1)
		return; // You're already loading the content!
	url = urls.join('&');
	isloading = 1;
	xmlhttp=null;
	if (window.XMLHttpRequest) // code for Firefox, Opera, IE7, etc.
		xmlhttp=new XMLHttpRequest();
	else if (window.ActiveXObject) // code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

	if (xmlhttp != null) {
		document.getElementById('commentlist').innerHTML = '<div align="center"><img src="'+site+'images/ajax-loader.gif" alt="Loading..." /></div>' + document.getElementById('commentlist').innerHTML;
		fullurl = url+'&off='+offset+'&sho='+all+(starts?'&start='+starts:'');
		var wait = opacity(99, 0, 500, 0);
		setTimeout("xmlhttp.onreadystatechange=function() { " +
			"if (xmlhttp.readyState == 4) {" +
				"if (xmlhttp.status == 200) {" +
					"document.getElementById('commentlist').innerHTML=xmlhttp.responseText;" +
					"reset_commentcount();" +
					"setTimeout(\"isloading = 0;\", opacity(1, 100, 800, 1));" +
				"} else {" +
					"document.getElementById('commentlist').innerHTML = 'Problem retrieving data: ' + xmlhttp.statusText;" +
					"}" +
				"}" +
			"};" +
		"xmlhttp.open(\"GET\", fullurl, true);" +
		"xmlhttp.send(null);", wait);
	} else {
		document.getElementById('commentlist').innerHTML = 'Your browser does not support XMLHTTP';
	}
}

function reset_commentcount() {
	xmlhttp=null;
	if (window.XMLHttpRequest) // code for Firefox, Opera, IE7, etc.
		xmlhttp=new XMLHttpRequest();
	else if (window.ActiveXObject) // code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

	if (xmlhttp != null) {
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					document.getElementById('comment_count').innerHTML=xmlhttp.responseText;
					document.getElementById('pcomment_count').innerHTML=xmlhttp.responseText.replace('c', 'C');
				} else {
					document.getElementById('comment_count').innerHTML = 'Unknown comments';
					document.getElementById('pcomment_count').innerHTML = 'Unknown Comments';
				}
			}
		}

		xmlhttp.open("GET", url + '&type=1', true);
		xmlhttp.send(null);
	} else {
		document.getElementById('comment_count').innerHTML = 'Unknown comments';
		document.getElementById('pcomment_count').innerHTML = 'Unknown Comments';
	}
}

function opacity(opacStart, opacEnd, millisec, is_fadein) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;
	var regx = /^comment/
	var comments = document.getElementsByTagName('li');
	var start, end;
	if( is_fadein ) {
		start = 0;
		end = comments.length;
	} else {
		start = comments.length - 1;
		end = 0;
	}

	for(i = start; comments.length;) {
		if( regx.test(comments[i].id) ) {
			//determine the direction for the blending, if start and end are the same nothing happens
			if(opacStart > opacEnd) {
				for(o = opacStart; o >= opacEnd; o--) {
					setTimeout("changeOpac(" + o + ",'" + comments[i].id + "')",(timer * speed));
					timer++;
				}
			} else if(opacStart < opacEnd) {
				for(o = opacStart; o <= opacEnd; o++) {
					setTimeout("changeOpac(" + o + ",'" + comments[i].id + "')",(timer * speed));
					timer++;
				}
			}
		}
		if( is_fadein ) {
			if( i < end - 1 ) {
				i++;
			} else {
				break;
			}
		} else {
			if( i > 0 ) {
				--i;
			} else {
				break;
			}
		}
	}
	return timer * speed;
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
	if( !opacity ) {
		object.display = 'none';
	} else {
		object.display = '';
	}
}

var xmlhttp, commenthttp, start=location.hash.substring(9), fullurl;