/*
 * Chargeur.js
 */

/* Css class for display */
DISPLAYING_CLASS = 'display';


/*
 * DISPLAY_ONE
 * @param id : DOM node of the visible element
 * @param group : class group of elements to display or undisplay
 * 'prefix-on' for the visible element and
 * 'prefix-off' for unvisible elements
 */
function _display_one (id, group) {
	var newClassName = group + ' ' + DISPLAYING_CLASS;
	$("." + group).each(function(i) {
			$(this).attr("class", newClassName + '-off');
		});
	return $("#" + id).attr("class", newClassName + '-on');
}
function display_one (id, group) {
	$(document).ready(function() {
		_display_one (id, group);
	});
	return false;
}
function display (id) {
	var jq_el = $("#" + id);
	jq_el.removeClass(DISPLAYING_CLASS + '-off');
	return jq_el.addClass(DISPLAYING_CLASS + '-on');
}
function display_first(group) {
	$(document).ready(function() {
		var idElement = $("." + group + ":first").get(0).id;
		display(idElement);
	});
	return false;
}


/* 
 * LOAD_REMOTE_DATA
 * Load a html document or an image
 * @param id : DOM node or id for receptacle
 * @param url : url of remote document 
                or an image like "image:path.png"
 * @param data : parameters for url like { key1:value1, key2:value2 }
 */
function _load_remote_data(id, url, data) {
	var el = document.getElementById(id);
	if (!el) {
	  var jq_el = $(id);
	} else {
	  var jq_el = $(el);
	}
	// for a single image : just change DOM content
	if (url.substr(0, 6) == 'image:') {
		return jq_el.html('<img src="'+ url.substr(6) +'" />');
	}

	// else load Ajax
	if (!data) {
		jq_el.load(url);
	} else {
		jq_el.load(url, data);
	}
	return false;
}
function load_remote_data(id, url, data) {
	$(document).ready(function() {
		return _load_remote_data(id, url, data);
	});
	return false;
}


/*
 * LOAD_FADE
 * Display a fade effect on a block with id #chargeur-fade
 *  on top center of the page.
 * Undisplay the div #body by default - you put an other id with 'otherbody' arg
 */
function _load_fade(body) {
  var jq_el = $("#chargeur-fade");
  jq_el.fadeIn();
  jq_el.click(function () {
    $(this).fadeOut();
    $("#"+body).fadeTo('fast', 1);
    });
  var jq_bd = $("#"+body);
  jq_bd.fadeTo('normal', 0.33);
  return false;
}
function load_fade(otherbody) {
  if (!otherbody) {
    var otherbody='body';
  }
  $(document).ready(function() {
	 return _load_fade(otherbody);
  });
  return false;
}
