$(function(){
  //Dropdown menu
  var ddto;
  var d = null;
  $("#nav li").hover(function(){
  		clearTimeout(ddto);
  		if(d && d.attr("id") != $(this).attr("id")) {
  			slideup(d); 
  			d = null;
  		}
  		if(!d || d.attr("id") != $(this).attr("id")) {
			$(this).find("span").hide().stop(true, true).slideDown(400);
		}
  },
  function(){
  		d = $(this);
  		ddto = setTimeout(function(){slideup(d);}, 500);
  });
  function slideup(e){
  	d = null;
  	e.find("span").slideUp(100);
  }
  //Play button mouseover
  $(".playButton").hover(function(){
    $(this).attr("src","imgs/bouton_play_rollover.png");
  },
  function(){
    $(this).attr("src","imgs/bouton_play.png");
  });
  
  //Green box mouseover
  $(".greenBox").hover(function(){
    $(this).css("background-image","url('imgs/bouton_portail_rollover.png')");
  },
  function(){
    $(this).css("background-image","url('imgs/bouton_portail.png')");
  });
  
  //FANCYBOX
  $(".pdf").fancybox({
  	'type':'iframe',
  	'width':1040,
  	'height':800
  });
  $(".form").fancybox({
      'type':'iframe',
      'width': 600,
      'height': 450,
      'scrolling': 'no'
    });
  $(".form2").fancybox({
      'type':'iframe',
      'width': 600,
      'height': 450
    });


  $(".video").click(function(e) {
  	var url = $(this).attr("href").replace(new RegExp("watch\\?v=", "i"), 'v/')
    $.fancybox({
            'padding' : 0,
            'type' : 'swf',
            'href' : url,
            'swf' : { 'wmode' : 'transparent', 'allowfullscreen' : 'true' }
        });
    e.preventDefault();
  });
  $(".portaillink").attr("href", "#portails").fancybox();
  
  
  
});
