var wait = 0;
var enCours = 0;

function resetWait()
{
	wait = 0;
}

function showSection(i, r)
{
	//if(r === undefined)
	if(typeof r === 'undefined')
	{
		r = true;
	}
	if(r)
	{
		wait = 1;
		setTimeout('resetWait()', 7000);
	}
    enCours = enCours + 1;
    //console.log('En cours : '+ enCours);
    var curId = $('.js_shown').attr('id');
	if(curId != 'js_section' + i && enCours == 1) {
/*			$('#' + curId).hide('slide', { direction: 'left' }, 500, function() {
			$('#js_section' + i).addClass('js_shown');
			$('#js_section' + i).removeClass('js_hidden');
			$('#js_section' + i).show('slide', { direction: 'right' }, 500);
			$('#' + curId).addClass('js_hidden');
			$('#' + curId).removeClass('js_shown');
		});*/
		var test = curId.indexOf('js_subSection');
		if(test != -1)
		{
			curId = curId.substr(13);
		}
		else
		{
			curId = curId.substr(10);
		}
		$('#js_section' + curId).fadeOut('normal', function()
			{
				$('#js_section' + i).fadeIn('normal');
				$('#js_section' + i).addClass('js_shown');
				$('#js_section' + i).removeClass('js_hidden');
				$('#js_section' + curId).removeClass('js_shown');
				$('#js_section' + curId).addClass('js_hidden');
				//$('.js_shown').attr('style', 'display: block;');
				$('.js_shown').css('display', 'block');
				enCours = 0;
			}
		);
		$('#js_subSection' + curId).fadeOut('normal', function()
			{
				$('#js_subSection' + i).fadeIn('normal');
			}
		);
	}
	else if (curId == 'js_section' + i)
	{
	   enCours = 0;
	}
}

function billboard(j, speed)
{
	if(wait == 1)
	{
		setTimeout('billboard(' + j + ',' + speed + ')', 1000);
	}
	else
	{
		var newId = j + 1;
		if(!document.getElementById('js_section' + newId))
		{
			newId = 0;
		}
		showSection(newId, false);
		setTimeout('billboard(' + newId + ', ' + speed + ')', speed);
	}
}

function starter(speed)
{
	var ct = 0;
	while(document.getElementById('js_section' + ct))
	{
		ct++;
	}
	var start = Math.floor(Math.random() * ct);
	billboard(start, speed);
}