/* 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.1
 *
 * Requires: jQuery 1.2+
 */
(function($)
{
	$.fn.CheckImg = function(img0, img1, path)
	{
		if(!path) path = '';
		var ImgArray = [img0, img1];

		$(this).attr('style', 'display:none;visibility:hidden;').each(
			function()
			{
				this.ImgChk = $(this).attr('checked') == true ? 1 : 0;
			}
		).after('<img />').next().each(
			function()
			{
				$(this).attr('src', path + ImgArray[this.ImgChk = $(this).prev()[0]['ImgChk']]);
				AddAttr($(this), 'title');
				AddAttr($(this), 'alt');
				AddAttr($(this), 'class');
			}
		).bind('click', function() 
		{
			this.ImgChk = this.ImgChk?0:1;

			$(this).attr('src', path + ImgArray[this.ImgChk]);
			$(this).prev()[0].checked = Boolean(this.ImgChk);
		});
	},
	AddAttr = function(Obj, Attr)
	{
		var a = Obj.prev().attr(Attr);
		Obj.attr(Attr, a == null ? '' : a);
	}
})(jQuery);
