(function($){
	$(window).load(function() {
		$('.slideshow:eq(0) .images img:eq(0)').css({
			top:function(i){
				return (($(this).parent().height()-$(this).height())/2);
			},
			left:function(i){
				return (($(this).parent().width()-$(this).width())/2);
			}
		}).fadeIn('fast');	
			

		$('.slideshow:eq(0) .images img:eq(0)').css({
			top:function(i){
				return (($(this).parent().height()-$(this).height())/2);
			},
			left:function(i){
				return (($(this).parent().width()-$(this).width())/2);
			}
		}).show();	

		$('.slideshow:gt(0)').hide();

		jQuery.fn.slideshow = function() {

			$(this).each(function() {
				var $this = $(this);
				var id = '#' + $this.attr('id');

				$(id + ' .images img:eq(0)').show();				
				// $(id + ' .images img:gt(0)').hide();				
				
				/*var layerOn = function( e ){
		 			if(e){ var texte = $(e).attr('alt')} 
						else{	var texte = $(id + '.slideshow .images :visible').attr('alt') }
					$("<p/>", {
					  "class": "description",
					  text: texte
					}).appendTo($this).fadeTo('fast','0.75');
				}

				var layerOff = function( element ){
					$('p.description').fadeOut('fast',function(){ 
						$(this).remove();
						if(element){
							layerOn( element );
						}
					});			
				}

				$(id + ".slideshow").hover(
					function(){	layerOn(); },
					function(){	layerOff();	}			
				);*/

				$(id + ".slideshow .images img").each(function(){
					$(this).css({
						top:function(i){
							return (($(this).parent().height()-$(this).height())/2);
						},
						left:function(i){
							return (($(this).parent().width()-$(this).width())/2);
						}
					});					
				});

				$(id + ' .back,' + id + ' .next').bind({
					click: function(){
						if(!$(id + ' .images img').is(':animated')){
							if($(this).hasClass('back')){
								if($(id + ' .images :visible').is(':first-child')){
						      element = $(id + ' .images :last-child');
								}
								else{
						      element = $(id + ' .images :visible').prev('img');				
								}					
							}
							else{
								if($(id + ' .images :visible').is(':last-child')){
									element =	$(id + ' .images :first-child');
								}
								else{
									element = $(id + ' .images :visible').next('img');
								}					
							}
				      $(id + ' .images :visible').fadeOut();				
							$( element ).fadeIn();
							layerOff( element );				
						}
					},
					mouseenter: function(){
						$(this).find('img').fadeTo(200,'0.60');
					},
					mouseleave: function(){
						$(this).find('img').fadeOut(200);				
					}
				});

			});

		}

		$('.slideshow').slideshow();


		$('#categories a').bind('click',function(e){
			$('#categories a').removeClass('active');
			$(this).addClass('active');
			
			href = $(this).attr('href');
			$('.slideshow').each(function() {
				id = ('#' + $(this).attr('id'));
				if(id == href){
					if(!$(this).is(':visible')){
						$(this).fadeIn('fast');
						$(id + ".slideshow .images img").each(function(){
							$(this).css({
								top:function(i){
									return (($(this).parent().height()-$(this).height())/2);
								},
								left:function(i){
									return (($(this).parent().width()-$(this).width())/2);
								}
							});					
						});						
					}
				}
				else{
					$(this).fadeOut('fast');					
				}
			});
			e.preventDefault();
		});

/* "Mémoire" pour l'effet "actif" du sous-menu portfolio
***********************************************************/
		if ($('#categories2 ul li a').length) {
			var adresseActuelle = window.location.pathname;
			var pageAccueilFR = "/default.php";
			var pageAccueilEN = "/english.php";
			var aLaRacine = "/";
			if( adresseActuelle == pageAccueilFR || adresseActuelle == pageAccueilEN || adresseActuelle == aLaRacine ) {
				$('#categories2 ul li:nth-child(2) a').addClass('active');
			} else {
				$('#categories2 ul li a').filter('[href$='+adresseActuelle+']').addClass('active');
			}
		}

	});
})(jQuery);
