function initGallery() {
	var galleries = $('.ad-gallery').adGallery({
	  loader_image: 'fileadmin/templates/tv/images/ad.gallery/loader.gif',
	  width: 600, // Width of the image, set to false and it will read the CSS width
	  height: false, // Height of the image, set to false and it will read the CSS height
	  thumb_opacity: 0.7, // Opacity that the thumbs fades to/from, (1 removes fade effect)
						  // Note that this effect combined with other effects might be resource intensive
						  // and make animations lag
	  start_at_index: 0, // Which image should be displayed at first? 0 is the first image
	  description_wrapper: false, // Either false or a jQuery object, if you want the image descriptions
											   // to be placed somewhere else than on top of the image
	  animate_first_image: true, // Should first image just be displayed, or animated in?
	  animation_speed: 200, // Which ever effect is used to switch images, how long should it take?
	  display_next_and_prev: false, // Can you navigate by clicking on the left/right on the image?
	  display_back_and_forward: true, // Are you allowed to scroll the thumb list?
	  scroll_jump: 0, // If 0, it jumps the width of the container
	  slideshow: {
		enable: false,
		autostart: false,
		speed: 5000,
		start_label: 'Lancer le diaporama',
		stop_label: 'Arreter le diaporama',
		stop_on_scroll: false, // Should the slideshow stop if the user scrolls the thumb list?
		countdown_prefix: '(', // Wrap around the countdown
		countdown_sufix: ')',
		onStart: function() {
		  // Do something wild when the slideshow starts
		  //alert('started');
		  $('.ad-slideshow-start').hide();
		  $('.ad-slideshow-stop').show();
		},
		onStop: function() {
		  // Do something wild when the slideshow stops
		  $('.ad-slideshow-start').show();
		  $('.ad-slideshow-stop').hide();
		}
	  },
	  effect: 'fade', // or 'slide-vert', 'resize', 'fade', 'none' or false
	  enable_keyboard_move: true, // Move to next/previous image with keyboard arrows?
	  cycle: true, // If set to false, you can't go from the last image to the first, and vice versa
	  // All callbacks has the AdGallery objects as 'this' reference
	  callbacks: {
		// Executes right after the internal init, can be used to choose which images
		// you want to preload
		init: function() {

		  // preloadAll uses recursion to preload each image right after one another
		  this.preloadAll();
		}
	  }
	});

	$( ".ad-gallery" ).dialog({autoOpen: false, resizable: false, draggable: false, modal: true, width: 644, title: 'Photos',closeText: 'Fermer'});
	$( ".ad-gallery" ).css({'background':'#FCFCFC'});
	$(".slideShow a").click(function() {
		var photoPosition = $('.slideShow li').index($(this).parent());
		$( ".ad-gallery" ).dialog('open');
		galleries[0].showImage(parseInt(photoPosition));
		galleries[0].slideshow.start();
		
	   $(".ui-widget-overlay").click(function(){
		  $(".ad-gallery" ).dialog('close');
		  return false;
		});
	  return false;
	});
}
  $(window).load( function() {
    initGallery();
  });



