/**
 * jquery plugin: ajax status changer
 *
 * http://www.604media.com/jquery
 *
 * Copyright (c) 2008 Tim Kraumanis
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Version: 1.420
 */

(function($) {


$.fn.changer = function(settings) {

    // settings
    settings = $.extend({
		selector: 	'active',
        icon: 		'images/admin_iconCheck.gif',
        iconO: 		'images/admin_iconCheckO.gif',
		ask:		false,
		message:	'Are you sure?',
		resultId:	'workingmsg',
		fadeTime:	'500',
		call: 		'setStatus'
    }, settings || {});

    return this.each(function() {
							  
		var change = $(this).children('img').hasClass('true');
		
		if (change) $(this).children('img').attr('src',settings.icon); else $(this).children('img').attr('src',settings.iconO);
		
		$(this).click(function() {
		
			var h = $(this).children('img').hasClass('true');
			var data = $(this).attr('href');
			
			
			if (settings.ask) agree=confirm(settings.message); else agree=true;
			
			if (h) {
				data = data + '&value=false';
				
				if (agree) {
					$(this).children('img').attr('src',settings.iconO).removeClass('true').addClass('false');
					eval(settings.call + '(data, false, "' + $(this).children('img').attr('id') + '")');
				}
			} else {
				data = data + '&value=true';
								
				if (agree) {
					$(this).children('img').attr('src',settings.icon).addClass('true').removeClass('false');
					eval(settings.call + '(data, true, "' + $(this).children('img').attr('id') + '")');
				}
			};
			return false;
		
		});
    
	

	});
	
	function setStatus(data) {
		//alert(data);
	$j('#workingMsg').html('Saving changes...').show();
	$j.ajax({
	   type: "GET",
	   url: "update_status.php",
	   data: data,
	   success: function(){
		 $j('#workingMsg').html('Changes saved');
		 $j('#updatemsg').show().animate({opacity:1},1500).fadeOut(500);
	   }
	 });
	}

};



})(jQuery);
