jQuery(function($) { 
	$('.gallery').addClass('galleryS');
	$('.thumbs').addClass('thumbsS');
	// $('.nojs').remove();
	if(jQuery.browser['msie']) {
		$('body>.unsupported').html("Ce site peut ne pas s'afficher correctement dans Internet Explorer. Nous vous recommandons d'utiliser un navigateur conforme aux standards du web, par exemple Opera, Google Chrome ou Firefox.");
		$('body>.unsupported').css('display','block');
		}

	/*jQuery.each($('.gallery li'),function(index,val) {
			$(val).width($(val).children().width()-4); // why -4 ?
		}); // TODO fix this (if pics not loaded) */

	$('ul.gallery').galleria({
			history   : true, // activates the history object for bookmarking, back-button etc.
			clickNext : true, // helper for making the image clickable
			insert    : '#main_image', // the containing selector for our main image
			onImage   : function(image,caption,thumb) { 

				if($.galleria.current != '') {
					image.parent().css("background-image","url('"+
							$.galleria.current+"')");
					image.parent().css("background-repeat","no-repeat");
					image.parent().css("background-position","center");
				}
				image.parent().width(image.width());
				$('.imdesc').remove();
				$('#main_image span').clone().addClass('imdesc').prependTo('#footer');
				image.css('display','none').fadeIn(600);




				
				var _li = thumb.parents('li');
				
				// fade out inactive thumbnail
				_li.siblings().children('img.selected').fadeTo(600,0.3);
				
				// fade in active thumbnail
				thumb.fadeTo('fast',1).addClass('selected');
				
				// add a title for the clickable image
				// image.attr('title','Next image >>');
				image.mousewheel(function(event,delta) {
						if(delta < 0)
							$.galleria.next();
						else
							$.galleria.prev();
					});
			},
			onThumb : function(thumb) { // thumbnail effects goes here
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// if thumbnail is active, fade all the way.
				var _fadeTo = _li.is('.active') ? '1' : '0.3';
				
				// fade in the thumbnail when finnished loading
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
				
				// hover effects
				thumb.hover(
					function() { thumb.fadeTo('fast',1); },
					function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
				);
			}
		});
		
		}); 
