jQuery(document).ready(function($) {
  
  $('body').addClass('js');
  
  $(window).load(function(){ // --- fix the problem to get img size with safari;
    // --- lightbox
    var path = absUrl+'/img/';
  	var settings = {
      imageLoading:	 path+'lightbox-ico-loading.gif',	// (string) Path and the name of the loading icon
      imageBtnPrev:	 path+'lightbox-btn-prev.png',		// (string) Path and the name of the prev button image
      imageBtnNext:  path+'lightbox-btn-next.png',		// (string) Path and the name of the next button image
      imageBtnClose: path+'lightbox-btn-close.png',		// (string) Path and the name of the close btn
      imageBlank:		 path+'lightbox-blank.gif',			  // (string) Path and the name of a blank image (one pixel)
      maxHeight: Math.floor( $('html').height()*.7 ),
      maxWidth: Math.floor( $('html').width()*.7 ),
  	}
  	$('.page-node:not(#an-american-prayer) article > aside img').each(function() {
      var path = $(this).attr('src').replace(/bd/g,'HD');
      $(this).wrap('<a href="'+path+'">');
  	});
  	$('.page-node:not(#an-american-prayer) article > aside a').lightBox(settings).css({'display':'block'});
  	// --- diaporama
    f_diaporama($('.page-node:not(#an-american-prayer) article > aside'),'a');
  });
  f_securePictures($('.page-node article>aside'));
  f_securePictures($('.page-list article'));
  
  /*
   * Diaporama /!\ PLUGIN-IT!
   */
  function  f_diaporama($thisgalerie,target) { // NE FONCTIONNE QUE POUR UNE GALLERIE! À CORRIGER!
    $thisgalerie.height( $(target, $thisgalerie).height()+'px' ).width( $(target, $thisgalerie).width()+'px' ).addClass('diaporamizr');
    if( $(target,$thisgalerie).length > 1 ) f_diaporama_launch($thisgalerie,target);
  }
  function f_diaporama_launch($thisgalerie,target){
    $img = $(target+':last', $thisgalerie);
    $imgs = $(target, $thisgalerie);
    $imgs.removeAttr('style');
    var timeout = setTimeout(function(){
      $img.css('opacity', '0');
      var timeout2 = setTimeout(function(){
        $img.prependTo($thisgalerie)
        f_diaporama_launch($thisgalerie,target);
      },700);//time set in css
    },5000);
  }
  // end of Diaporama.
  
  // ------ f_securePictures ------
  function f_securePictures(target){
    // ------ remove click on content picture ------
    $('img',target).mousedown(function(e){
      if($(this).parents('a').length == 0)
        return false;
    });

    // ------ remove right click on content picture ------
    $('img',target).hover(function() {
      $(document)[0].oncontextmenu = function() { return false; };
    }, function() {
      $(document)[0].oncontextmenu = function() { return true; };
    });
  }
  // end of f_securePictures.
});
