if(jQuery) (function($){
	
	function updateParentCheckbox(){
		var group = $(this);
		var o = group.data("config");
		var callback = group.data("callback");
		
		var group_parent = $(group).find('.specialCheckboxsParent IMG');
		var cpt_group = cpt_checked = 0;
		$(group).find('.specialCheckboxsChildrens INPUT:checkbox').each( function() {
			var input = $(this);
			if($(input).attr('checked')==true) cpt_checked++;
			cpt_group++;
		});
		if(cpt_group==cpt_checked) group_parent.attr('src',o.imgAll);
		else if(cpt_checked==0) group_parent.attr('src',o.imgNone);
		else group_parent.attr('src',o.imgPartial);
	}
	function updateChildrensCheckboxs(){
		var group = $(this);
		var o = group.data("config");
		var callback = group.data("callback");
		
		var group_parent = $(group).find('.specialCheckboxsParent IMG');
		if(group_parent.attr('src')==o.imgAll){
			group_parent.attr('src',o.imgNone);
			$(group).find('.specialCheckboxsChildrens INPUT:checkbox').attr('checked',false);
		} else {
			group_parent.attr('src',o.imgAll);
			$(group).find('.specialCheckboxsChildrens INPUT:checkbox').attr('checked',true);
		}
	}
	
	$.extend($.fn, {
		specialCheckboxs: function(o, callback) {
			if( !o ) o = {};
			if( o.imgAll == undefined ) o.imgAll = '/images/rechercheV12/specialcheckboxs/checkbox_all.gif';
			if( o.imgPartial == undefined ) o.imgPartial = '/images/rechercheV12/specialcheckboxs/checkbox_part.gif';
			if( o.imgNone == undefined ) o.imgNone = '/images/rechercheV12/specialcheckboxs/checkbox_null.gif';
			$(this).each( function() {
				var all_groups = $(this);
				$(all_groups).find('.specialCheckboxsAllGroups').click( function() {
					$(all_groups).find('.specialCheckboxsParent IMG').attr('src',o.imgAll);
					$(all_groups).find('.specialCheckboxsChildrens INPUT:checkbox').attr('checked',true);
				}).show();
				$(all_groups).find('.specialCheckboxsNoneGroups').click( function() {
					$(all_groups).find('.specialCheckboxsParent IMG').attr('src',o.imgNone);
					$(all_groups).find('.specialCheckboxsChildrens INPUT:checkbox').attr('checked',false);
				}).show();
				$(all_groups).find('.specialCheckboxsGroup').each( function() {
					var group = $(this);
					$(group).find('.specialCheckboxsParent').each( function() {
						var group_parent = $(this);
						var html = '<img style="cursor: pointer;" align="absmiddle" /> ';
						$(group_parent).children('LABEL').before(html);
						$(group_parent).children('IMG,LABEL').click( function() {
							updateChildrensCheckboxs.call(group);
							if( callback ) {
								callback($(this));
							}
						});
					});
					$(group).find('.specialCheckboxsChildrens').each( function() {
						var group_childrens = $(this);
						$(group_childrens).find('INPUT:checkbox').change( function() {
							updateParentCheckbox.call(group);
							if( callback ) {
								callback($(this));
							}
						});
					});
					group.data("config", o);
					group.data("callback", callback);
					updateParentCheckbox.call(group);
				});
			});
		},
	});
	
})(jQuery);