var hoverBoxEn = false;

// XMLHTTP Connector
function openConnection() {
	var connection=false;
	try {
		connection=new XMLHttpRequest();
	} catch(e) {
		try {
			connection=new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				connection=new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				connection=false;
			}
		}
	}
	return connection;
}

// Rate content
function rate(id,rating) {
	var connection=openConnection();
	if(connection) {
		connection.open("GET", "/rate.php?id="+id+"&r="+rating, true);
		connection.onreadystatechange=function() {
			if(connection.readyState==4) {
				document.getElementById("c"+id).innerHTML = connection.responseText;
			}
		}
		connection.send("");
	}	
}

// Update position of hover box
function updateHoverBoxPosition(e) {
	var x, y;
	if(!e) var e = window.event;
	var hoverBoxObj = document.getElementById("hoverBox");

	if(e.pageX || e.pageY)	{
		x = e.pageX;
		y = e.pageY;
	} else if(e.clientX || e.clientY) {
		x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}

	hoverBoxObj.style.left = 15 + x + "px";
	hoverBoxObj.style.top = y + "px";
}

// Display hover box
function hoverBox(content) {
	if(hoverBoxEn==false) return;
	if(!document.getElementById("hoverBox")) {
		hoverBoxEl = document.createElement("div");
		hoverBoxEl.id = "hoverBox";
		hoverBoxEl.style.display = "none";
		hoverBoxEl.style.position = "absolute";
		document.body.appendChild(hoverBoxEl);
	}
	var hoverBoxObj = document.getElementById("hoverBox");
	hoverBoxObj.innerHTML = "<img src=\"" + content + "\" />";
	hoverBoxObj.style.display = "block";
	document.onmousemove = updateHoverBoxPosition;
}

function hoverBoxOff() {
	if(hoverBoxEn==false) return;
	document.getElementById("hoverBox").style.display = "none";
}
