var total = 0;
var intervalID;
var timeoutID;
window.addEvent('domready', function() {
	if( $('bouton_aide') ) timeoutID = setTimeout(startButton, 5000);	
});

function startButton() {
	$('bouton_aide').setStyle('opacity', 0);
	var myFx = new Fx.Tween($('bouton_aide'), {duration: 500, onComplete: function() {
		if( $('bouton_aide') ){
			intervalID = setInterval(tweenImgHelp, 2000);
		}
	}});
	myFx.start('opacity', '1');
}

function tweenImgHelp() {
	if(total > 2) {
		myFx = new Fx.Tween($('bouton_aide'), {duration: 500});
		myFx.start('opacity', '0');
		clearInterval(intervalID);
		return false;
	}
	var myFx = new Fx.Tween($('bouton_aide'), {duration: 500, onComplete: function() {
		if( $('bouton_aide') ){
			myFx = new Fx.Tween($('bouton_aide'), {duration: 500});
			myFx.start('opacity', '1');
		}
	}});
	myFx.start('opacity', '0');
	total++;
}

function removeHelp() {
	if( $('bouton_aide') ) {
		var request = new Request.JSON({
			url: '/ajax/setHelp.html',
			onComplete:	function() {
				clearInterval(intervalID);
				clearTimeout(timeoutID);
				$('bouton_aide').dispose();
			}
		}).post();
	}
}
