// JavaScript Document
$(function()
{
	$('#liste').jScrollPane({
 			showArrows: true,
 			arrowScrollOnHover: true
 });
	
});
$(function()
			{
				// this initialises the demo scollpanes on the page.
				$('.scroll-pane').jScrollPane();
			});

$(function(){
  $(".autoEmpty").each(function(){
    var defaultText = $(this).val();
    $(this).focus(function(){
      if($(this).val() == defaultText){
        $(this).val(''); }    
    });
    $(this).blur(function(){
       if($(this).val() ==''){
        $(this).val( defaultText); }
    });      
  });


});
/****** Bulle d'info A propos et Contact *****/
$(function(){ 
  $("#Apropos").hide();$("#Contact").hide();
  $("#menu li a ").each(function(){
    $(this).click(function(){
        var A; var B;
        var title = $(this).attr("title");
        if ((title == "A propos") || (title == "Contact")) {
          if (title == "A propos") { A = "#Apropos"; B = "#Contact"; };
          if (title == "Contact") { A = "#Contact"; B = "#Apropos" };
          if ($(A).hasClass("none")) {
            if ($(B).hasClass("")) { $(B).slideUp("slow"); $(B).toggleClass('none');};
            $(A).slideDown("slow");
          } else { 
            $(A).slideUp("slow"); 
          };
          $(A).toggleClass('none');
          return false;
        };
    });
  });  
});

/****** FONCTION DE CACHE DES VIDEOS DANS LA PARTIE PORTFOLIO ******/
$(function(){ 	
 $("#caches a").hover(function() {
		$(this).next("em").animate({opacity: "show", top: "-75"}, "slow");
	}, function() {
		$(this).next("em").animate({opacity: "hide", top: "-85"}, "fast");
	});
});

/*$(function(){ 
  $("#caches li").each(function(){
    $(this).click(function(){
      var classe = "."+$(this).attr("id");
      if ($(this).hasClass("none")) { $(classe).slideUp(1000);} 
      else { $(classe).slideDown(1000); };
      $(this).toggleClass('none');
      return false; 
    });
  }); 
});*/
$(function(){ 
  $("#caches li").each(function(){
    $(this).click(function(){
      var color = $("span:first", this).text();
      var classe = "."+$(this).attr("id");
      $(classe).animate({ backgroundColor: color }, "fast")
		    .animate({ backgroundColor: "#c4a5ed" }, "slow")
      return false; 
    });
  }); 
});
/****** FONCTIONS POUR LES CATEGORIES ******/
$(function(){
 $(".cat-item ").each(function(){ 
   $(this).width(200);
   $(this).mouseover(function(){
     $(this).stop().animate({ width: '215'});
     $("a", this).stop().animate({marginLeft: '30'});
   });
   $(this).mouseleave(function(){
     $(this).stop().animate({ width: '200'});
     $("a", this).stop().animate({marginLeft: '15'});
   });
 });
}); 
/****** MENU ******/
$(function(){ 
  $("#menu .hover").css({opacity:"0"});
  $("#menu li").mouseover(function(){
    $(".hover", this).stop().animate({opacity: "1"});

  });
  $("#menu li").mouseleave(function(){
    $(".hover", this).stop().animate({opacity: "0"});

  });
});

/****** FOOTER ******/
$(function(){ 
  $(".social a").each(function(){
    $(this).mouseover(function(){
      $(this).stop()
      .css({"background-position" : "bottom center"})
      // first jump
      .animate({top:"-5px"}, 100).animate({top:"0px"}, 200)
      // second jump 
      .animate({top:"-2px"}, 100).animate({top:"0px"}, 200)
/*      // the last jump
      .animate({top:"-6px"}, 50).animate({top:"0px"}, 50);*/
    });
    $(this).mouseleave(function(){
      $(this).css({"background-position" : "top center"});
    });
    });
});

$(function(){
	$('a[href*=#]').click(function() {
		cible=$(this).attr('href');
		scrollTo(cible);
		//return false;
	});
});

function scrollTo(cible){
  cible = cible.substr(cible.indexOf("#"), cible.length);
	if($(cible).length>=1){
		hauteur=$(cible).offset().top;
	}
	else{
		hauteur=$("a[name="+cible.substr(1,cible.length-1)+"]").offset().top;
	}
	hauteur -= (windowH()-$(cible).height())/2;
	$('html,body').animate({scrollTop: hauteur}, 1000,'easeOutQuint');
	return false;
}

function  windowH(){
	if (window.innerHeight) return window.innerHeight  ;
	else{return $(window).height();}
}
$(function(){
		   
	$('.sticky').each(function(){
		var parent = $(this).parent();
  var ContactH = $("#Contact").height();
  var AproposH = $("#Apropos").height();
  var tamponC=0; var tamponA=0; var tampon = 20;
		var elem = $(this);
  var dTop = elem.offset().top;
		parent.css('position','relative');
		elem.css('position','abslute');
		$(window).scroll(function(){
   tampon =0;
   eTop = dTop;
		 if ($("#Contact").hasClass("none")) {tamponC = 0;} else { tamponC = ContactH; eTop = eTop+ContactH; }
		 if ($("#Apropos").hasClass("none")) {tamponA = 0;} else { tamponA = AproposH; eTop = eTop+AproposH;}
		 tampon = tamponC+tamponA+tampon;
		 //dTop = dTop + tampon;
			if(scrollY()>eTop){
			 
				elem.stop().animate({top:scrollY()-parent.offset().top+20},500);
			}else{
				elem.stop().animate({top:dTop-parent.offset().top+tampon},500);
			}
		});
		if(scrollY()>dTop){
			elem.stop().animate({top:scrollY()-parent.offset().top+20},500);
		}
	 });
});

/**
* Return the position of the top
* */

 function scrollY() {
	 	var	scrOfY = 0;
			if(typeof( window.pageYOffset) =='number') {
				//Netscape compliant
				scrOfY = window.pageYOffset;
			}else if(document.body && (document.body.scrollTop)){
				//DOM compliant
				scrOfY = document.body.scrollTop;
			}else if( document.documentElement && (document.documentElement.scrollTop)){
				//IE6 standards compliant mode
				scrOfY = document.documentElement.scrollTop;
			}
			return scrOfY;
 }

