/* 
 * Menu Jquery
 */
$(document).ready(function(){
        $("ul.sub-menu").parent().append("<span></span>"); //Affiche simplement le bouton (ici représenté par une flèche) qui sert à afficher le menu déroulant lorsque le JavaScript est activé.
	$("ul.topnav li span").mouseenter(function() { //Lorsque l'on clique sur le bouton (flèche)...

		//Les événements suivants sont appliqués à la sous-navigation (menu déroulant).
		$(this).parent().find("ul.sub-menu").slideDown('fast').show(); //Ouverture du menu déroulant lorsque l'on clique sur le bouton

		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.sub-menu").slideUp('slow'); //Lorsque l'on survol à l'extérieur du menu déroulé, le menu déroulant remontra
		});

		//Les événements suivant s'appliquent lors du survol du bouton de la flèche.
		}).hover(function() {
			$(this).addClass("subhover"); //Lorsque l'on survol, ajout de la classe "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //Lorsque l'on survol à l'extérieur, enlève la classe "subhover"
	});
    });
    
    
 
    
/* 
 * Effet Accordeon 
 
    
 $(document).ready(function($) {
    $('.acc-content').hide(); 
    $('.acc-title a.acc-slide').click(function(){
    $('.acc-content').slideToggle();
        return false; 

    });

});

*/
    
 $(document).ready(function($) {
	$('.acc-content').hide(); 
	$('.acc-title a.acc-slide').click(function() {
		$(this).parent().next('.acc-content').slideToggle();

       	return false; 

    });

});


    
/* 
 * Scroll
 */

$(document).ready(function() {
  function filterPath(string) {
  return string
    .replace(/^\//,'')
    .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
    .replace(/\/$/,'');
  }
  var locationPath = filterPath(location.pathname);
  var scrollElem = scrollableElement('html', 'body');

  $('a[href*=#]').each(function() {
    var thisPath = filterPath(this.pathname) || locationPath;
    if (  locationPath == thisPath
    && (location.hostname == this.hostname || !this.hostname)
    && this.hash.replace(/#/,'') ) {
      var $target = $(this.hash), target = this.hash;
      if (target) {
        var targetOffset = $target.offset().top;
        $(this).click(function(event) {
          event.preventDefault();
          $(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
            location.hash = target;
          });
        });
      }
    }
  });

  // use the first element that is "scrollable"
  function scrollableElement(els) {
    for (var i = 0, argLength = arguments.length; i <argLength; i++) {
      var el = arguments[i],
          $scrollElement = $(el);
      if ($scrollElement.scrollTop()> 0) {
        return el;
      } else {
        $scrollElement.scrollTop(1);
        var isScrollable = $scrollElement.scrollTop()> 0;
        $scrollElement.scrollTop(0);
        if (isScrollable) {
          return el;
        }
      }
    }
    return [];
  }

});

    
/* 
 * Over portfolio
 */

$(document).ready(function($) {

    var current = null;
    var tt = parseInt($('#ngg-gallery-thumbnail a:first span.ngg-title').css('top'));
    var ll = parseInt($('#ngg-gallery-thumbnail a:first span.ngg-descr').css('left'));

    
	$('#ngg-gallery-thumbnail a').mouseover(function(){
	
	if(current && $(this).index() != current.index()) {
         current.find('span.ngg-bg').stop().fadeOut();
         current.find('span.ngg-title').show().animate({
         top : tt -25,
         opacity : 0
         });
         current.find('span.ngg-descr').show().animate({
         left : ll -50,
         opacity : 0
         });
	}
	if(current && $(this).index() == current.index()) {
	   return null;
	}
    $(this).find('span.ngg-bg').hide().stop().fadeTo(500,0.8);
    $(this).find('span.ngg-title').css({
         opacity : 0,
         top : tt + 25
     }).animate({
         opacity : 1,
         top : tt
     });
     $(this).find('span.ngg-descr').css({
         opacity : 0,
         left : ll + 50
         }).animate({
           opacity : 1,
           left : ll
         });
                
		current = $(this);
	
	}); 


});

