/* ThankCool by [DomeniC] --> AJAX client side */
function thankcool(msg_id){
	var el = $('#tc_' + msg_id);
	var bt = $('#tcb_' + msg_id);
	var url = smf_scripturl.replace(/index.php/, '');
	if(!el) return false;
	if(!bt) return false;
	$.post(url + 'thankcool.php', {id: msg_id, se: new Date().getTime()}, function(json) {
		if(json.status == 'error')
			return alert('error! ' + json.message);
		bt.css('cursor', 'default');
		bt.html('<b>ThankCooled!</b>');
		el.html(json.newlist);		
	}, 'json');
}

/*	*	*	*	*	*	*		*
*	Modified , fixed Bugs & add Effect		*
*	by: ExpertDuck					*
*	version:0.1						*
*	required:jQuery Core 1.3.2 or newest	*
*	*	*	*	*	*	*	*	*/

$(function(){

	var url = smf_scripturl.replace(/index.php/, 'thankcool.php');
	
	$('a.thx').css({'cursor':'pointer'}).click(function(e){
		
		var _x = e.pageX; //capture MouseX
		var _y = e.pageY; //capture MouseY
		if(!e.pageX){ //forIE
				_x = e.offsetX;
				_y = e.offsetY;
		}
		
		var thankId = $(this).attr('id').match(/tcb_([0-9]+)/)[1];
		if(!thankId || thankId<=0)//ensure :P
			thankId = $(this).attr('id').replace(/tbc_/,'');
		
		var el_refer = $('a[name="msg'+thankId+'"]').next();
		var el_bt = $(el_refer).find('.thx');
		var el_target = $(el_refer).find('.thx-target');
		var el_list = $(el_refer).find('.success');

			$.post(url,{'id':thankId,'se': new Date().getTime()},
				function(data)
				{
					if(data.status == 'error')
						return alert('error! ' + data.message);
			
					$(el_bt).text('ThankCooled').replaceWith('<span>ThankCooled</span>').removeClass('thx');
					$(el_list).html(data.newlist);
					var cool=$(el_target).text();
						$(el_target).append('<span class="fadeFX">+1</span>');
						$(el_target).find('.fadeFX').css({'color':'red','font-size':'1.5em'})
.fadeOut(1000,function(){	$(el_target).text(++cool);}	);
						
				}
			,'json');
		return false;
	}); //end click eventlistener
});
