$(document).ready(function() {

    /****************************************************************/
    // ===== Pretty Photo
    /****************************************************************/

    $("a[rel^='prettyphoto']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		opacity: 0.80, /* Value between 0 and 1 */
  	   	showTitle: true /* true/false */
    });


    /****************************************************************/
    // ===== Pour le menu
    /****************************************************************/
    $("div#menu ul > li.parent").hover(
	function () {
	    $(this).addClass('isOver');
	},
	function () {
	    $(this).removeClass('isOver');
	}
    );

    /****************************************************************/
    // ===== Pour le slide du haut
    /****************************************************************/
   $('ul#portfolio').innerfade({
                        speed: 1000,
                        timeout: 5000,
                        type: 'sequence',
                        containerheight: 	'339px',
                        slide_timer_on: 	'yes',
                        slide_ui_parent: 	'portfolio',
                        slide_ui_text:		'null',
                       	pause_button_id: 	'null',
                       	slide_nav_id:		'slide_nav'
                    	});
                    	$.setOptionsButtonEvent();


                   		$("#pause_button").click(function() {
                   			$.pause();
                        });
                        $("#fleche_d").click(function() {
                    		$.next();
                        });

                        $("#fleche_g").click(function() {
                        	$.prev();
                        });

                    	$("#first_button").click(function() {
                        	$.first();
                        });

                    	$("#last_button").click(function() {
                        	$.last();
                        });

    /****************************************************************/
    // ===== Pour le slide du bas
    /****************************************************************/
    var currentPosition = 0;
      var slideWidth = 816;
      var slides = $('.slide_show');
      var numberOfSlides = slides.length;

      // Remove scrollbar in JS
      $('#slidesContainer').css('overflow', 'hidden');

      // Wrap all .slides with #slideInner div
      slides
        .wrapAll('<div id="slideInner"></div>')
        // Float left to display horizontally, readjust .slides width
            .css({
          'float' : 'left',
          'width' : slideWidth
        });

      // Set #slideInner width equal to total width of all slides
      $('#slideInner').css('width', slideWidth * numberOfSlides);

      // Insert controls in the DOM
      /*$('#slideshow')
        .prepend('<span class="control" id="leftControl">Clicking moves left</span>')
        .append('<span class="control" id="rightControl">Clicking moves right</span>');*/

      // Hide left arrow control on first load
      manageControls(currentPosition);

      // Create event listeners for .controls clicks
      $('.control')
        .bind('click', function(){
        // Determine new position
            currentPosition = ($(this).attr('id')=='slide_bas_right') ? currentPosition+1 : currentPosition-1;

            // Hide / show controls
        manageControls(currentPosition);
        // Move slideInner using margin-left
        $('#slideInner').animate({
          'marginLeft' : slideWidth*(-currentPosition)
        });
      });

      // manageControls: Hides and Shows controls depending on currentPosition
      function manageControls(position){
        // Hide left arrow if position is first slide
            if(position==0){ $('#slide_bas_left').hide() } else{ $('#slide_bas_left').show() }
            // Hide right arrow if position is last slide
        if(position==numberOfSlides-1){ $('#slide_bas_right').hide() } else{ $('#slide_bas_right').show() }
      }

});

