$(document).ready(function(){
   // General actions
   $("#light").show();
   
   // Menu
   $("#menu li[class!=home]").click(function(){
      $("#menu li").removeClass("active");
      $(this).addClass("active");
   });
   

   // Slideshow
   $("#slideshow").disableTextSelect().bind("contextmenu", function(){ return false; });
   var slideTimer;
   slideTimer = setTimeout(slideshow, 0);
   function slideshow(){
      window.setTimeout(function(){
         slideCont = "#slideshow";
         $(slideCont).animate({opacity:.0}, 750, function(){
            $.get("fonctions.php?slideshow=1", function(data){
               $(slideCont+" img:last").remove();
               $(slideCont).append('<img src="'+ data +'" alt="" />').animate({opacity:1}, 450);
            });
            slideTimer = setTimeout(slideshow, 0);
         });
      }, 8000);
   }
   
   
   // Videos
   contentHeight = $("#main #content").height()
   if (contentHeight >= 440){
      $(".videos #content, .cv #content, .galleries #content, .photos #content").css({height:"440px", maxHeight:"none"});
      $(".videos #content, .cv #content, .galleries #content, .photos #content").jScrollPane({
         scrollbarWidth: 12
      });
   }
   
      // Video
      lightBg = false;
      $("#light a").click(function(){
         $("#black").animate({opacity:"toggle"});
         if (!lightBg){ $(this).addClass("active"); lightBg = true; }
         else{ lightBg = false; $(this).removeClass("active"); }
         return false;
      });

      $("#black").click(function(){
         $(this).animate({opacity:"toggle"});
         $("#light a").addClass("active");
         lightBg = true;
         return false;
      });
      
      
   // Photos
   $("#thumbnails a").click(function(){
      var img = $(this).attr("href"), photo = "#photo #picture";
      
      $(photo).fadeOut(600, function(){
         $(this).load(function(){
            $(this).fadeIn();
         }).attr("src", img);
      });
      
      return false;
   }).hover(function(){
         $(this).css({opacity:0.9}).animate({opacity:1}, 250);
      }, function(){
         $(this).animate({opacity:0.9}, 500);
   });
      
   
   // Rollover
   $(".video, .gallery").hover(function(){
         $(this).find(".title, .infos, .black").hide();
         $(this).stop().find(".title, .infos").fadeIn(250);
         $(this).stop().find(".black").fadeIn(150);
      }, function(){
         $(this).find(".title, .infos").fadeOut(350);
         $(this).find(".black").fadeOut(500);
   });
   
   
   // Galleries
   $(".gallerie a[rel]").colorbox({
      slideshow:true,
      slideshowStart: "Play",
      slideshowStop: "Pause"
   }).hover(function(){
         $(this).find("img").css({opacity:.8}).animate({opacity:1}, 250);
      }, function(){
         $(this).find("img").animate({opacity:.8}, 500);
   });
   
   // Contact
   $(".mail").each(function(){
	   var email = $(this).html();
	   $(this).html(email).replaceWith('<a href="mailto:' + $(this).text() + '">' + $(this).text() + '</a>');
	});
   
   $("#form #mail[value='Adresse e-mail'], #form #mail[value='E-mail address'], #form #message").focus(function() {
   	if(this.value == this.defaultValue){
   		this.value = "";
   	}
   });
});