var host = 'http://'+location.hostname+'/federation';
J(document).ready( function () {
	J(":input[type=checkbox]").each(function(){
		checkboxReplacement(J(this));
	})
});

  	
function checkboxReplacement(box){
	var on = 'un';
	if(J(box)){
		if(J(box).attr('checked')){
			on = '';
			checked = true;
		}else{
			checked = false;
		}
		J(box).addClass('replaced');
		var img = document.createElement('img');
		img.className = 'checkbox_replacement';
		img.src = host+'/templates/occe/images/'+on+'check.jpg';
		J(img).insertAfter(J(box));
		J(img).click(function(){
			selectAction(J(this), J(box));
		});
	}
}

function selectAction(img, box){
	if(J(box).attr('checked') == true){
		on = 'un';
		checked = false;
	}else{
		on = '';
		checked = true;
	}
	J(box).attr('checked', checked);
	J(img).attr('src', host+'/templates/occe/images/'+on+'check.jpg');
	majActions();
}

function majActions(){
	var toShow = new Array();
	var toHide = new Array();
	var actions;
	J(":input[type=checkbox]").each(function(){
		if(J(this).attr('checked') == true){
			actions = J("#action"+J(this).val()).val().split(';');
			jQuery.each(actions, function(){
				if(jQuery.inArray(parseInt(this), toShow)==-1){
					toShow.push(parseInt(this));
				}
			});
		}
	});
	if(toShow.length != 0){
		J(".action").each(function(){
			J(this).animate({opacity: 0.2 }, 'slow');
		});
		jQuery.each(toShow, function(){
			J("#act_"+this).animate({opacity: 1 }, 'slow');
		});
	}else{
		J(".action").each(function(){
			J(this).animate({opacity: 1 }, 'slow');
		});
	}

}