jQuery.fn.blocdp = function() {	// Deploie et replie les blocs de droite
	if(this.hasClass("close")){
		this.removeClass("close");
	} else {
		this.addClass("close");
	}
};

jQuery.preloadImages = function(){
  for(var i = 0; i<arguments.length; i++){
    jQuery("<img>").attr("src", arguments[i]);
  }
}

jQuery.fn.onglet = function() {	// Deploie et replie les blocs onglets
	return this.each(function() {
		var itemsLink   = $("a",this);
		
		var closeAll = function() {
			itemsLink.each(function(i) {
				$('#'+$(this).attr('rel')).css('display','none');
				$(this).removeClass('on');
			});
		};
	
		// hide all on init
		closeAll();
	
		// show first element
		$(itemsLink[0]).addClass('on');
		$('#'+$(itemsLink[0]).attr('rel')).css('display','block');
	
		// add event on each link
		itemsLink.each(function(i) {
			$(this).click(function(){
				// hide all on click
				closeAll();
				// display clicked item
				$('#'+$(this).attr('rel')).css('display','block');
				$(this).addClass('on');
				return false;
			});
		});
	});

};

jQuery.fn.accordeon = function() {	// Deploie et replie les blocs onglets

	this.each(function(i) {

		var element = this;
		var pilots = $("div.faqlegend > a",element);
		var items = $("dl",element);
		var itemsLink = $("dl > dt > a",element);

		var replier = false;

		items.each(function(i) {
			$(items[i]).removeClass("on");
		});

		// add event on each link
		items.each(function(i) {
			$(itemsLink[i]).click(function(){
				if($(items[i]).hasClass("on")){
					$(items[i]).removeClass("on");
				} else {
					$(items[i]).addClass("on");
				}
				return false;
			});
		});
		pilots.each(function(i) {
			$(pilots[i]).click(function(){
				replier = false;
				items.each(function(i) {
					if($(items[i]).hasClass("on")){
						replier = true;
					}
				});
				items.each(function(i) {
					if(replier){
						$(items[i]).removeClass("on");
					} else {
						$(items[i]).addClass("on");
					}
				});
				return false;
			});
		});

	});

};

jQuery.fn.submitForm = function(){
	  for(var i = 0; i < arguments.length; i++){
	  	var arg = arguments[i];
	  	for(var name in arg) {
	  		$('#'+name).attr('value',arg[name]);
	  	}
	  }
	this.submit();
}

