$(document).ready(function(){
  
  // Plugin HoverIntent + live
  (function(a){a.fn.hoverIntent=function(b,c){var d={sensitivity:7,interval:100,timeout:0,live:false};d=a.extend(d,c?{over:b,out:c}:b);var e,f,g,h;var i=function(a){e=a.pageX;f=a.pageY};var j=function(b,c){c.hoverIntent_t=clearTimeout(c.hoverIntent_t);if(Math.abs(g-e)+Math.abs(h-f)<d.sensitivity){a(c).unbind("mousemove",i);c.hoverIntent_s=1;return d.over.apply(c,[b])}else{g=e;h=f;c.hoverIntent_t=setTimeout(function(){j(b,c)},d.interval)}};var k=function(a,b){b.hoverIntent_t=clearTimeout(b.hoverIntent_t);b.hoverIntent_s=0;return d.out.apply(b,[a])};var l=function(b){var c=jQuery.extend({},b);var e=this;if(e.hoverIntent_t){e.hoverIntent_t=clearTimeout(e.hoverIntent_t)}if(b.type=="mouseenter"){g=c.pageX;h=c.pageY;a(e).bind("mousemove",i);if(e.hoverIntent_s!=1){e.hoverIntent_t=setTimeout(function(){j(c,e)},d.interval)}}else{a(e).unbind("mousemove",i);if(e.hoverIntent_s==1){e.hoverIntent_t=setTimeout(function(){k(c,e)},d.timeout)}}};return d.live?this.live("mouseenter",l).live("mouseleave",l):this.bind("mouseenter",l).bind("mouseleave",l)}})(jQuery)

   // Focus sur l'input Nom :
   $("#ctl00_ContentPane_usercontrols_contactform_contact_SenderName").focus();   
   
   // EmptySidebar + height when I click on send
   $('#ctl00_ContentPane_usercontrols_contactform_contact_SendMessage').one('click', function() {
      $("#emptySidebar").height($("#contentWrapper").height() - $("#widget").height() - 15);
   });
   
   
   // Hover sur la brochure
   $("#brochure").prepend('<img src="/App_Master/img/presentation/brochure_hover.jpg" class="download" />');
   $("#brochure").prepend('<img src="/App_Master/img/style/download.png" class="downloadIcone" />');
   $(".download").css("opacity" , "0");
   $(".downloadIcone").css("opacity" , "0");
   $("#brochure").hover(function(){                                                   
      $(this).children(".downloadIcone").stop(true, false).animate({opacity : "1", marginTop : "100px"}, 500);
      $(this).children(".downloadIcone").animate({marginTop : "90px"}, 700);
      $(this).children(".downloadIcone").animate({marginTop : "100px"}, 700);
      $(this).children(".downloadIcone").animate({marginTop : "90px"}, 700);
      $(this).children(".downloadIcone").animate({marginTop : "100px"}, 700);
      $(this).children(".downloadIcone").animate({marginTop : "90px"}, 700);
      $(this).children(".downloadIcone").animate({marginTop : "100px"}, 700);
      $(this).children(".downloadIcone").animate({marginTop : "90px"}, 700);
      $(this).children(".downloadIcone").animate({marginTop : "100px"}, 700);
      $(this).children(".downloadIcone").animate({marginTop : "90px"}, 1000);
      
      $(this).children(".download").stop(true, false).animate({opacity : "1"}, 100);              
   }, function(){
      $(this).children(".downloadIcone").stop(true, false).animate({opacity : "0"}, 300);
      $(this).children(".download").stop(true, false).animate({opacity : "0"}, 600); 
      $(this).animate({borderTopColor : "#fff", borderRightColor : "#fff", borderBottomColor : "#fff", borderLeftColor : "#fff"}, 2000); 
      
      setTimeout( function(){
        $(".downloadIcone").css("marginTop" , "70px");
      }, 350);
   }); 
   // Au click
   $("#brochure").click(function(){
      $(this).animate({borderTopColor : "#000", borderRightColor : "#000", borderBottomColor : "#000", borderLeftColor : "#000"}, 500);
   });
  
  
   // ################################## Menu ###############################################################################################
   // Menu déroulant 
   $("#menu ul li ul").hide();
   $("#menu ul li").hover(function(){
      $(this).children("ul").stop(true, false).show(); 
   }, function(){
      $(this).children("ul").stop(true, false).hide();
   }); 

   // Garder la couleur du hover dans le menu déroulant
   $("#menu ul li ul").hover(function(){
      $(this).parent("li:not(.selected)").children().addClass("hover");  
      $(".arrowMenu").removeClass("hover");  
   }, function(){
      $(this).parent("li:not(.selected)").children().removeClass("hover");  
   });
   
   // Arrow Menu
   $("#menu ul li ul li ul").parent().children("a").addClass("arrowMenu");
   $("#menu .arrowMenu").hover(function(){
      $(this).addClass("arrowMenuHover");
   }, function(){
      $(this).removeClass("arrowMenuHover");
   }); 
   
   
   // ################################## IMG Present ###############################################################################################
   // Cacher la div #intituled après 10s + réafficher au hover de la souris
   setTimeout( function(){
      $("#intituled").fadeOut();
   }, 5000);
    
    // Hover sur #imgPresent
    setTimeout( function(){1
      var config = {    
        over: function() { 
          $("#intituled").slideDown({easing: "easeOutBack"});
          $("#intituled").css("opacity" , "0.8").css("backgroundColor" , "#000");
        }, 
        out: function() { 
          $("#intituled").slideUp({easing: "easeInBack"});;
        }
      };
      $("#imgPresent").hoverIntent(config); 
    }, 6000);
    
   
   
   
   // ################################## Optimisation Sitefinity (Aide pour l'éditeur) ############################################################################################################
   
   // Margin #imgPresent 
   if($("#imgPresent").height() > 0 || $("#imgPresent #intituled").height() > 0){
      $("#imgPresent").css("marginBottom" , "5px");
   } 
   
   // padding #container #black ou #white 
   if($("#white").height() > 0){
      $("#white").css("paddingBottom" , "10px");
   }
   if($("#black").height() > 0){
      $("#black").css("paddingBottom" , "10px");
   }
   
   // padding #widget 
   if($("#sidebarWrapper #widget").height() > 0){
      $("#widget").css("paddingBottom" , "10px");
   } 
   
   // height #widget 
   if($("#sidebarWrapper #widget").height() < 1){
     $("#widget").css("height" , "0px");
   }  
  
   // enlever le padding et le outline au lien "a" 
   $("#sidebarWrapper img").parent("a").css("padding" , "0").css("outline" , "none");
      
});


// Charger les div vides après les images
$(window).load(function(){
   
   // ############################################################################ DIV VIDE HAUTEUR ##################################################
   
   // AUTRE || Display none #imgPresent
   if($("#imgPresent").height() < 1){
      $("#imgPresent").css("display" , "none");
   }
      
   // Hauteur de la div #empty    
   $("#empty").height($("#sidebarWrapper").height() - $("#contentWrapper").height() - 5);
   if($("#empty").height() > 0){
      $("#empty").css("borderTop" , "5px solid #000");
   }
   
   // Hauteur de la div #emptySidebar
   $("#emptySidebar").height($("#contentWrapper").height() - $("#sidebarWrapper").height() - 5);
   
   // Bordure de la div #emptySidebar
   if($("#widget").height() > 1){
	  $("#emptySidebar").css("borderTop" , "5px solid #000");
   }
   
   // Bordure 5px #emptySidebar
   if($("#widget").height() == 0){
      $("#emptySidebar").css("borderBottom" , "5px solid #383838");
   }
 
    
});

 
 
