/*!
 * jQuery imagesLoaded plugin v1.0.3
 * http://github.com/desandro/imagesloaded
 *
 * MIT License. by Paul Irish et al.
 */

(function($, undefined) {

  // $('#my-container').imagesLoaded(myFunction)
  // or
  // $('img').imagesLoaded(myFunction)

  // execute a callback when all images have loaded.
  // needed because .load() doesn't work on cached images

  // callback function gets image collection as argument
  //  `this` is the container

  $.fn.imagesLoaded = function( callback ) {
    var $this = this,
        $images = $this.find('img').add( $this.filter('img') ),
        len = $images.length,
        blank = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==';

    function triggerCallback() {
      callback.call( $this, $images );
    }

    function imgLoaded() {
      if ( --len <= 0 && this.src !== blank ){
        setTimeout( triggerCallback );
        $images.unbind( 'load error', imgLoaded );
      }
    }

    if ( !len ) {
      triggerCallback();
    }

    $images.bind( 'load error',  imgLoaded ).each( function() {
      // cached images don't fire load sometimes, so we reset src.
      if (this.complete || this.complete === undefined){
        var src = this.src;
        // webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
        // data uri bypasses webkit log warning (thx doug jones)
        this.src = blank;
        this.src = src;
      }
    });

    return $this;
  };
})(jQuery);

/* Au lancement de la page
------------------------------------------------------ */
$(document).ready(function()
{
        /* Diaporama */
        $('#slider').imagesLoaded( function() {
           $('#slider').orbit({
              animation: 'fade',
              animationSpeed: 800,
              pauseOnHover: true
           });
        });

	/* Navigation */
	// if there is a subnav (!home && !contact)
	var navActive = $('#nav .active').size();
	if (navActive != 0)
	{
		// Record of the active id
		var idActive = $('#nav .active').attr('id');

		// Hover
		$('#nav').children('li').hover(function() {
			// if the cursor is above a nav that has a subnav and is not above the "active" nav
			if ($(this).children('ul').size() != 0  &&  $(this).children('ul').attr('class') != 'subActive') {
				$('#'+idActive+' ul').removeClass('subActive');
			}
		},function() {
			$('#'+idActive+' ul').addClass('subActive');
		});
	}
});
