/*
 mwaextraadmin4_vmoods by ZONE365.com
 Created by Sniper
 http://www.zone365.com
 for vbulletin 3.7
*/

function vB_AJAX_mwaextraadmin4_vmoods_Init() 
{
	this.init = function()
	{
		if (AJAX_Compatible && (typeof vb_disable_ajax == 'undefined' || vb_disable_ajax < 2))
		{
			var mwaextraadmin4_vmoods_current = YAHOO.util.Dom.get('mwaextraadmin4_vmoods-mine').getAttribute('title');
			
			YAHOO.util.Event.addListener(['mwaextraadmin4_vmoods_div','mwaextraadmin4_vmoods_reset'], 'click', vB_AJAX_mwaextraadmin4_vmoods_Click);
			YAHOO.util.Event.addListener('mwaextraadmin4_vmoods_div', 'mouseover', vB_AJAX_mwaextraadmin4_vmoods_Mouseover);
			YAHOO.util.Event.addListener('mwaextraadmin4_vmoods_div', 'mouseout', vB_AJAX_mwaextraadmin4_vmoods_Mouseout);
		
			if (YAHOO.util.Dom.get('vmood-mine'))
			{
				if (YAHOO.util.Dom.get('vmood-mine').src)
					YAHOO.util.Dom.setStyle('vmood-mine', 'opacity', 0.25);
					
				YAHOO.util.Dom.get("vmood-mine").className = 'vmood_mine';
			}
			
			if (mwaextraadmin4_vmoods_current != 'none')
				YAHOO.util.Dom.setStyle('mwaextraadmin4_vmoods-mine', 'display', 'block');
		}
	}
	
	vB_AJAX_mwaextraadmin4_vmoods_Mouseover = function(e)
	{
		var target = YAHOO.util.Event.getTarget(e);
		var classname = target.className;

		if (classname != 'undefned' && classname == 'vmood' && target.src)
			YAHOO.util.Dom.setStyle(target, 'opacity', 0.25); 
		
	    YAHOO.util.Event.stopEvent(e);
	}
	
	vB_AJAX_mwaextraadmin4_vmoods_Mouseout = function (e)
	{
		var target = YAHOO.util.Event.getTarget(e);
		var classname = target.className;

		if (classname != 'undefned' && classname == 'vmood' && target.src)
			YAHOO.util.Dom.setStyle(target, 'opacity', 1); 
		
	    YAHOO.util.Event.stopEvent(e);
	}
	
	vB_AJAX_mwaextraadmin4_vmoods_Click = function(e)
	{
		var target = YAHOO.util.Event.getTarget(e);
		var mwaextraadmin4_vmoods_current = YAHOO.util.Dom.get("mwaextraadmin4_vmoods-mine").getAttribute("title");
		var classname = target.className;
		
		this.change = function()
		{
			if (classname != 'undefned' && classname == 'vmood')
			{
				if (target.src)	
					YAHOO.util.Dom.setStyle(target, 'opacity', 0.25);
								
				YAHOO.util.Connect.asyncRequest("POST", "ajax.php?do=mwaextraadmin4_vmoods_update&securitytoken=" + SECURITYTOKEN + "&vmood=" + target.title, {
					success: this.handle_ajax_response,
					failure: vBulletin_AJAX_Error_Handler,
					timeout: 15000,
					scope: this
				}, SESSIONURL + "do=mwaextraadmin4_vmoods_update&securitytoken=" + SECURITYTOKEN + "&vmood=" + PHP.urlencode(target.title));
			}
		}

		this.handle_ajax_response = function(ajax)
		{
			var mymood = YAHOO.util.Dom.get('mwaextraadmin4_vmoods-mine');
			var mymood_li = YAHOO.util.Dom.get('vmood-mine');
			
			if (mymood_li)
			{
				mymood_li.className = 'vmood';
				mymood_li.setAttribute('id', 'vmood-' + mymood.getAttribute('title'));
			}
			
			mymood.setAttribute('src', 'mwaextraadmin4/vmoods/' + ajax.responseText + '.gif');
			mymood.setAttribute('alt', ajax.responseText);
			mymood.setAttribute('title', ajax.responseText);

			target.className = 'vmood_mine';
			target.setAttribute('id', 'vmood-mine');
			
			if (target.src)
				YAHOO.util.Dom.setStyle('vmood-' + mwaextraadmin4_vmoods_current, 'opacity', 1.0);
				
			YAHOO.util.Dom.setStyle('mwaextraadmin4_vmoods-mine', 'display', 'block');

			nomood = YAHOO.util.Dom.get('mwaextraadmin4_vmoods-none');
			
			if (nomood && ajax.responseText == 'none')
			{
				showhide = 'block';
				showmood = 'none';
			}
			else
			{
				showhide = 'none';
				showmood = 'block';	
			}
			
			YAHOO.util.Dom.setStyle('mwaextraadmin4_vmoods-none', 'display', showhide);
			YAHOO.util.Dom.setStyle('mwaextraadmin4_vmoods-mine', 'display', showmood);
		}

		this.change();
		
		YAHOO.util.Event.stopEvent(e);
	};
	
	YAHOO.util.Event.addListener(window, 'load', this.init);
}