vB_XHTML_Ready.subscribe(function(){
	new AJAX_Post_Thanks();
});

function AJAX_Post_Thanks(){
	this.init('posts');
}

AJAX_Post_Thanks.prototype.init = function(obj){
	if (AJAX_Compatible) {
		var anchors = fetch_tags(fetch_object(obj), 'a');
		for (var i = 0; i < anchors.length; i++) {
			if (anchors[i].name && anchors[i].name.indexOf('vB::Thanks::') != -1) {
				YAHOO.util.Event.on(anchors[i], "click", this.click, this, true);
			}
		}
	}
};

AJAX_Post_Thanks.prototype.click = function(e){
	e = e || window.event;
	var a = YAHOO.util.Event.getTarget(do_an_e(e)).name.split("::");
	return this.dothank(a[2], a[3]);
};

AJAX_Post_Thanks.prototype.dothank = function(postid, act){
	var me = this, a = act.substr(0), show = (a == 1 ? 'none' : '');
	YAHOO.util.Connect.asyncRequest("POST", "post_thanks.php", {
		success: function(o){
			if (o.responseText !== undefined) {
				fetch_object('post_thanks_box_' + postid).innerHTML = o.responseText;
				document.getElementsByName("vB::Thanks::" + postid + "::1" + act.substr(1))[0].style.display = show;
				fetch_object('post_thanks_separator_' + postid).style.display = show;
				
				if (act.substr(1) > 0) {
					fetch_object('post_groan_button_' + postid).style.display = show;
				}
				
				fetch_object('post_thanks_box_' + postid).style.display = (a == 1 || a == 2 ? '' : 'none');
				
				if (a == 1) {
					me.init("post_thanks_box_" + postid);
				}
			}
		},
		failure: function(o){
			if (o.responseText !== undefined) {
				alert(o.responseText);
			}
		},
		timeout: vB_Default_Timeout,
		scope: this
	}, SESSIONURL + "securitytoken=" + SECURITYTOKEN + "&do=post_thanks_" + (a == 1 ? "add" : "remove_" + (a == 2 ? "user" : "all")) + "&p=" + postid + "&using_ajax=1");
};