/* Copyright (c) 2007 Yves ASTIER (yves.astier@hotmail.fr)
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 * Use only for non-commercial usage.
 * Usage autorisé uniquement dans un cadre non-commercial.
 *
 * Version : 1.2
 *
 * Requires: jQuery 1.2+
 */
(function($)
{
	$.fn.CheckImg = function(img0, img1, path)
	{
		var I = function(etat) {
			return etat ? 1 : 0;
		};

		var GetChk = function(Obj)
		{
			return I(Obj.attr('checked'));
		};

		var AddAttr = function(Obj, Attr)
		{
			var a = Obj.prev().attr(Attr);
			Obj.attr(Attr, a == null ? '' : a);
		};

		if(!path) path = '';
		var ImgArray = [path + img0, path + img1];

		$(this)
			.attr('style', 'display:none;visibility:hidden;')
			.after('<img />')
			.next()
			.each(function()
				{
					$(this).attr('src', ImgArray[GetChk($(this).prev())]);
					AddAttr($(this), 'title');
					AddAttr($(this), 'alt');
					$(this).attr('class', 'checkImg');
				}
			)
			.bind('click', function()
				{
					var a = I(!GetChk($(this).prev()));
					$(this).attr('src', ImgArray[a]);
					$(this).prev()[0].checked = Boolean(a);
				}
			);

		return this.each(function(){});
	}
})(jQuery);