$(document).ready(function(){
  
  var total = $('#slider img').length;
  var rand = Math.floor(Math.random()*total);
  $('#slider').nivoSlider({
      startSlide:rand,	
     'effect'                :'random',
  	 'slices'                :15,
     'directionNav'          :true, //Next & Prev
  	 'directionNavHide'      :true, //Only show on hover
     'controlNav'            :true,
     'animSpeed'             :500,
     'pauseTime'             :5000,
  	 'controlNavThumbs'      :false, //Use thumbnails for Control Nav
  	 'keyboardNav'           :true, //Use left & right arrows
  	 'pauseOnHover'          :true, //Stop animation while hovering
  	 'manualAdvance'         :false, //Force manual transitions
  	 'captionOpacity'        :0.8 //Universal caption opacity      
  });

 
  /* Fancybox Propriétés */
	/* Ouverture classique */
  $("a.fancy").fancybox({
     'zoomOpacity'           : true,
     'zoomSpeedIn'           : 500,
     'zoomSpeedOut'          : 500,
		 'transitionIn'		       : 'fade',
		 'transitionOut'		     : 'fade',     
     'overlayOpacity'        : 0.85,
     'overlayColor'          : '#000',
     'hideOnContentClick'    : false
  });
  
  /* iframe (ex:site web) */
	$(".iframe").fancybox({
		 'zoomOpacity'           : true,
     'zoomSpeedIn'           : 500,
     'zoomSpeedOut'          : 500,		
     'width'				         : '85%',
		 'height'			           : '85%',
     'autoScale'     	       : false,
     'transitionIn'		       : 'fade',
		 'transitionOut'		     : 'fade',
		 'overlayColor'          : '#000',
		 'type'				           : 'iframe'
	});  


  /* PNG pour ie 5.5+ */
  $(document).pngFix(); 

  /* Remplacement titre Cufon  */
  Cufon.replace('h1');
	Cufon.replace('h2');
  Cufon.replace('h3');    

	/* Comportement Rollover avec class="rollover" */
	$("img.rollover").each(function(){
		attachRollOverEvent(this);
	});
	
	/* Remplacement image actif avec class="actif" */
	$("img.actif").each( function(){
		attachActif(this);
	});	  

  
}); /* fin doc ready */


/* ======== Fonctions ========================================================================== */ 
/* Screenshot apercu fonction */ 
this.screenshotPreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");								 
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
    });	
	$("a.screenshot").mousemove(function(e){
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

/* Comportement Rollover avec class="rollover" */
attachRollOverEvent = function(imageId){
	$(imageId).mouseover( function(){ $(this).attr("src", $(this).attr("src").replace('.','_roll.')) } );
	$(imageId).mouseout( function(){ $(this).attr("src", $(this).attr("src").replace('_roll','')) } );
}

/* Change image pour les "actif" */
attachActif = function(imageId){
	$(imageId).attr("src", $(imageId).attr("src").replace('.','_actif.'));
}

/* Recommander le site a un ami */
url = window.location;
titre = document.title;
sujet = "Je pense que ce site web peut vous intéresser";
function recommander(){ 
  window.location = "mailto:"+prompt('Entrez l\'adresse email de la personne a qui vous désirez recommander ce site','')+"?subject="+sujet+"&body="+titre+" : "+url;
} 

/* Imprime la page */
function impression(str) {
	window.print();
}

/* Ajouter aux favoris */ 
function favoris() {
    if ((navigator.appName.indexOf("Microsoft",0)>=0) && (parseInt(navigator.appVersion)>=4)) {
        window.external.AddFavorite("http://www.lemoulindethuboeuf.com/","Moulin Thuboeuf" );
    } else {
        alert("La fonction \"Ajouter aux favoris\" n'est proposée que par Internet Explorer 4 et versions supérieures")
    }
}

/* Appel de la fancy via flash (parc auto) */
function  callFancy(my_href) {
  var j1 = document.getElementById("liencache");
  j1.href = my_href;
  $('#liencache').trigger('click');
}



