// Popup box
function show(obj, comment_url, post_id, str_date, comments_link) {
	if (obj && obj.href) {
		// Add image to popup
		var content = '<img width="600" src="' + obj.href + '" onclick="TINY.box.hide();"/><a href="javascript:;" class="popup-button popup-close" onclick="TINY.box.hide();">Close<a/>'; 
		// Add like and comment buttons to popup
		if (comment_url && post_id && str_date && comments_link) 
			if (comment_url.length > 0 && str_date.length > 0 && comments_link.length > 0 && post_id > 0)
				//alert("adding buttons");
				content += '<a href="javascript:;" class="popup-button popup-like" onclick="like(\'' + comment_url + '\', ' + post_id + ',\'' + str_date + '\');this.className=\'popup-button popup-button-on popup-like \';">Like<a/><a href="' + comments_link + '" class="popup-button popup-comment">Comment<a/><a href="?p='+ post_id + '" class="popup-button popup-open">Details</a>';
		// Show popup
		TINY.box.show(content,0,0,0,0);
	}
}
// Enable dropdown menu (IE5.5+)
startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
window.onload=startList;
var xmlHTTP = [];
// Activate "Like" button functionality
function like(comment_url, post_id, str_date) {
	if (comment_url.length > 0 && str_date.length > 0 && post_id > 0) {
		counter = document.getElementById("post-" + post_id + "-counter");
		if (counter && counter.innerHTML.length > -1) {
			// 0 likes - add to 1
			if (counter.innerHTML.length == 0) 
				counter.parentNode.innerHTML = "1 person likes this";
			else if (counter.innerHTML.length > 0)
				counter.parentNode.innerHTML = (Math.floor(counter.innerHTML) + 1) + " people like this";
		}
		else {
			alert("Hey! You've already voted.");
			return;
		}
		// Create XMLHTTP object using arrays to support
		// concurrent requests
		var i = xmlHTTP.length;
		try {xmlHTTP[i] = new XMLHttpRequest();} 
		catch (E) {
			try {
			xmlHTTP[i]=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
		if(xmlHTTP[i]) {
			// Set request url
			xmlHTTP[i].open("POST", comment_url, true);
			// Initialise post info
			var params = "author=A%20Visitor&human=yes%20dude&email=web.user@desalasworks.com&comment=" + str_date + " - I Like This!&comment_post_ID=" + post_id;
			// Set proper header information
			xmlHTTP[i].setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHTTP[i].setRequestHeader("Content-length", params.length);
			xmlHTTP[i].setRequestHeader("Connection", "close");
			// Send
			window.setTimeout(function() { xmlHTTP[i].send(params); }, 1);
		}
	}
}
var callbackDirty = false;
function callback(obj) {
	if (obj && obj.parentNode) {
		if (callbackDirty) {
			try {
				obj.parentNode.submit();
			} catch (e) {}
			
			msg = document.getElementById("callback-message");
			if (msg && msg.value) {
				msg.value = "Message Sent!";
			}
		} else {
			alert("Please fill in some details before sending!");
		}
	}
}
