
// closure, mapping jQuery to $, window, document and undefined - useful for minifing tools
(function ($, window, document, undefined) {

	// menu dropdown
	$(document).ready(function () {
		$("li.subnav").hover(function () {
			$(this).children("a").addClass('hover');
			$(this).find("ul.subnav").slideDown('fast').show();
			$(this).hover(function () {
			}, function () {
				//When the mouse hovers out
				$(this).find("ul.subnav").slideUp('fast');
				$(this).children("a").removeClass('hover');
			});
		});
	});

	$(function () {
		if ($.fn.slideshowFade) {
			$('#slideshow').slideshowFade({
				buttons: false
			});
		}

		$('.listAnnuaire li').eq(4).css("margin-right", 0);
		$('.listAnnuaire li').eq(9).css("margin-right", 0);
		$('.listAnnuaire li').eq(14).css("margin-right", 0);
		$('.listAnnuaire li').eq(19).css("margin-right", 0);
		$('.listAnnuaire li').eq(24).css("margin-right", 0);
		$('.listAnnuaire li').eq(29).css("margin-right", 0);

		$(".logos li").mouseover(function () {
			$(".nb", this).css("display", "none");
			$(".rgb", this).css("display", "inline");
		})
		.mouseout(function () {
			$(".rgb", this).css("display", "none");
			$(".nb", this).css("display", "inline");
		});
	});


	// slideshowFade - jQuery plugin - creates a fading slideshow
	$.fn.slideshowFade = function (args) {
		if (!this.length)
			return this;
		var opts = $.extend({
			slides: '> ul > li', // slides selector
			buttons: true, 		// show buttons
			speed: 600, 			// speed of transition
			auto: 5000				// speed of auto transition
		}, args);
		this.each(function () {
			var parent = $(this), slides = parent.find(opts.slides), buttons = $(), timer = null, n = 0, s = '';

			slides.each(function () {
				this.id = parent[0].id + '-' + (++n);
				s += '<a href="#' + this.id + '">' + n + '</a>';
			});
			if (opts.buttons) {
				buttons = parent.append('<div class="nav">' + s + '</div>').
				find('.nav a').click(function () {
					var hash = this.hash.substr(1);
					parent.triggerHandler('slideChange', [slides.filter('#' + hash)]);
					return false;
				});
			}
			if (!slides.filter('.active').length) {
				slides.eq(0).addClass('active');
				buttons.eq(0).addClass('active');
			}
			function change(next) {
				var active = slides.filter('.active');
				if (!next || !next.jquery)
					next = active.next();
				if (!next.length)
					next = slides.eq(0);

				parent.trigger('slideChanging', [parent, slides, active, next]);

				next.addClass('next');
				active.fadeOut(opts.speed, function () {
					next.addClass('active').removeClass('next');
					active.removeClass('active').show();
					buttons.removeClass('active').filter('[href="#' + next[0].id + '"]').addClass('active');
				});
				parent.trigger('slideChanged', [parent, slides, active, next]);
			}
			function auto() {
				if (opts.auto)
					timer = setInterval(change, opts.speed + opts.auto);
			}
			parent.bind('slideChange', function (ev, slide) {
				clearInterval(timer);
				change(slide);
				auto();
			});
			auto();
		});
		return this;
	};


})(jQuery, window, document);

