/*v1.2*/
(function($) {
$.fn.fSlide = function(container, col, wot) {
	var $this = $(this);
	$this.majNav = function() {
		function majNavLink(action,href,know) { $('.'+action).attr('href', (href) ? href : know); }
		majNavLink('prev',$(wot+'.active').parent().prev().children('a:not(.prev)').attr('href'),$(wot+'.active').attr('href'));
		majNavLink('next',$(wot+'.active').parent().next().children('a:not(.next)').attr('href'),$(wot+'.active').attr('href'));
	};
	$this.view = function(wot,init) {
		if(!init) $this.each(function() { $(this).removeClass('active'); $($(this).attr('href')).fadeOut('slow'); });
		$($(wot).attr('href')).fadeIn('slow');
		$(wot).addClass('active');
		if(init)	$(container).scrollTop();
	}
	$this.nav = function(name) {
		function isNavLink(action,href) { return (href) ? true : false; }
		var notEnd = isNavLink(name,
			(name == 'prev') ? $(wot+'.active').parent().prev().children('a:not(.'+name+')').attr('href')
								  : $(wot+'.active').parent().next().children('a:not(.'+name+')').attr('href')
		);
		if(notEnd) {
			$this.each(function() { $(this).removeClass('active'); $($(this).attr('href')).fadeOut('slow'); });
			$('a[href='+$('.'+name).attr('href')+']:not(.'+name+')').addClass('active');
			$($('.'+name).attr('href')).fadeIn('slow');
			$this.majNav();
		}
		else if(name == 'next') {
			$this.each(function() { $(this).removeClass('active'); $($(this).attr('href')).fadeOut('slow'); });
			$(wot+':not(.prev):not(.next)').first().addClass('active');
			$($(wot+'.active').attr('href')).fadeIn('slow');
			$this.majNav();
		}
	}
	$this.parent().parent().prepend('<li><a class="prev" href="#">Précédent</a></li>')
			 					  .append('<li><a class="next" href="#">Suivant</a></li>');
	$(col).css({position: 'absolute',top: 0,left: '20px',display: 'none'})
			.first().css('display', 'block');
	$this.each(function() {
		if(location.hash == '') $(wot+':not(.next):not(.prev)').first().addClass('active');
		else {
			var hash = $(this).attr('href').indexOf('#');
			($(this).attr('href').substring(hash) == location.hash) ? $this.view(this, true)
																					  : $(this).removeClass('active');
		}
		$this.majNav();
		$(this).click(function(e) { e.preventDefault(); $this.view(this); $this.majNav(); resetTime(); });
	});
	function resetTime() {
		$(document).stopTime('diapoTime');
		$(document).everyTime(6000, 'diapoTime', function() { $this.nav('next'); });
	}
	$('.prev').click(function(e){ e.preventDefault(); $this.nav('prev'); resetTime(); });
	$('.next').click(function(e){ e.preventDefault(); $this.nav('next'); resetTime(); });
	$(document).everyTime(6000, 'diapoTime', function() { $this.nav('next'); });
	return $this;
};
})(jQuery);
$('#diapoMenu a').fSlide('#diapoWrap', '.slide', '#diapoMenu li a');
