
/* Init */

jQuery(
  
  function ($) {

    $.Body = $('body');

    $.Window = $(window);
    
    $.Scroll = ($.browser.mozilla || $.browser.msie) ? $('html') : $.Body;
    
        
    $('[data-controller]').Instantiate();
     var _opt = {
	duration: 1200,
	easing: "easeInOutExpo"
	};
	
	 		
	
	$current=Math.floor(($.Scroll.scrollTop()+600)/1200);
	
	
	var $newY = $current*1200-($.Window.height()-1200)/2;
	$.Scroll.animate({
		scrollTop:$newY,	
	},_opt);
	
	$first = $("#story-welcome");
	$first.show("slow");
    
  } 
 
);

/* ---------------------------------- */

/* Events */



/* ---------------------------------- */

/* Auto Start */

(function($) {

  $.fn.Instantiate = function() {
    
      this.each(function() { 

          var $self = $(this),
          $controller = $self.attr('data-controller');
                  
          if ($self[$controller])
            $self[$controller]();
          });
  }
  
 
})(jQuery);

/* ---------------------------------- */
/* Body */

(function($) {

  
   $.fn.MainBody = function() {
   
     this.each(function() { 
      
        var $self = $(this);
            
            
     });
     
   return this;
     
  }
    
   
    
})(jQuery);

/* ---------------------------------- */
/* logo */

(function($) {

  
   $.fn.logo = function() {
   
     this.each(function() { 
      
        var $self = $(this);
            
      	
		$self.click(function() {
			var _opt = {
				duration: 1000,
				easing: "easeInOutExpo"
			};


			var $newY = 0-($.Window.height()-1200)/2;
				$.Scroll.stop();
				$.Scroll.animate({
				scrollTop:$newY,	
			},_opt);
				return false;
			});	
		
		
            
     });
     
    return this;
     
  }
  	    	  
    
})(jQuery);




/* ---------------------------------- */
/* mainNav */

(function($) {

  
   $.fn.mainNav = function() {
   
     this.each(function() { 
      
        var $self = $(this);
            
      	var $current=0;
      	var $prevPageBtn = $self.find('#prev');
        var $nextPageBtn = $self.find('#next');
        
 		$.Window.bind('scroll',
            function(e){
 			$current=Math.floor(($.Scroll.scrollTop()+600)/1200);
 		})
 		
 		$.Window.resize(function(){
 			$current=Math.floor(($.Scroll.scrollTop()+600)/1200);
			scrollToCurrent($current);
		})


		$prevPageBtn.click(function() {
			$current=prevPage($current);
			scrollToCurrent($current);
			return false;
		});	
		
		$nextPageBtn.click(function() {
			$current=nextPage($current);
			scrollToCurrent($current);
			return false;
		});
		
		
            
     });
     
    return this;
     
  }
  	    
	function scrollToCurrent($pos){
		var _opt = {
		duration: 1000,
		easing: "easeInOutExpo"
		};


		var $newY = $pos*1200-($.Window.height()-1200)/2;
		$.Scroll.stop();
		$.Scroll.animate({
			scrollTop:$newY,	
		},_opt);
			
		return false;
	}
          
          
        
		
		
	function prevPage($pos){
		if($pos>0){
			$pos--;
			}
		return $pos;
	}

	function nextPage($pos){
		if($pos<13){
			$pos++;
		}
	return $pos;			
	}
	  
    
})(jQuery);



/* ---------------------------------- */
/* Sections */


(function($) {

  /* Project */

    $.fn.Project = function() {
     this.each(function() { 
      	var $pos=0;
      	var $contentVisible=false;
      	
        var $self = $(this);
        
	  
		
		resizeMe($self);
		$self.resize(function(e){
			resizeMe($self);
 		})
        
        var $prevBtn = $self.find('.slideshow .prevImg');
        var $nextBtn = $self.find('.slideshow .nextImg');
        
        var $infoBtn = $self.find('.info');
        var $infoWindow = $self.find('.slideshow .projectContent');
       
        var $col = $self.find('#column');
		$col.fadeOut(0);
	
	        
        var $ul = $self.find('.slideshow .slidesContainer ul');
        
      	$prevBtn.click(function() {
			$pos=prevImage($ul, $pos);
			return false;
		});
		  $nextBtn.click(function() {
			$pos = nextImage($ul, $pos);
			return false;
		});	
		
		$nextBtn.mouseover(function(){
			$(this).animate({opacity:1}, 500);	
		});
		
		$nextBtn.mouseout(function(){
			$(this).animate({opacity:0}, 500);	
		});
		
		$prevBtn.mouseover(function(){
			$(this).animate({opacity:1}, 500);	
		});
		
		$prevBtn.mouseout(function(){
			$(this).animate({opacity:0}, 500);	
		});

		
		

		
		$infoBtn.click(function() {
			var $me = $(this);
			if($contentVisible==false){
				$me.css("background-image", "url(images/fermer.png)");
				$contentVisible=true;
				showContent($infoWindow);
			}else{
				$me.css("background-image", "url(images/about.png)");
				hideContent($infoWindow);
				$contentVisible=false;
			}
			return false;
		});
		
		var tmpWidth=0;
		$self.find('.slideshow .slidesContainer ul li').each(function(i){
			tmpWidth += 1000;
			
		});
		
		$ul.width(tmpWidth);

        
     });
     
    return this;
     
  }
  
  
  function resizeMe($container){
 	 
 	 
  	$head = $container.find("header");
  	
  	$visTop = 600-($.Window.height()/2);
  	
  	$headY=0;
  	//$headY = 600-($.Window.height()/2);
	$headY = $visTop+($.Window.height()/2)-295;
			
	$head.stop();
	$head.animate({
		marginTop:$headY+"px"
	});
	
	
	$slideshow = $container.find(".slideshow");
  	
  	$slideY=0;
  	$slideY = $visTop+($.Window.height()/2)-250;
			
	$slideshow.stop();
	$slideshow.animate({
		marginTop:$slideY+"px"	});
	
  }
  
   
  function showContent($container){
  	var _opt = {duration: 500,easing: "easeOutExpo"};
			
	$container.stop();
	$container.animate({
		marginLeft:"0px"
	},_opt);
	
	var $col = $container.find('#column');
	$col.fadeIn("slow");
	
	
	
	
  }
  function hideContent($container){
  	var _opt = {duration: 500,easing: "easeInExpo"};
			
	$container.stop();
	$container.animate({
		marginLeft:"1000px"
	},_opt);
	
	var $col = $container.find('#column');
	$col.fadeOut("normal");
  }
  
	function prevImage($container,$loc) {
		
		if($loc>0){
			$loc--;
			
			var _opt = {
				duration: 500,
				easing: "easeOutExpo"
			};
			
			
			
			$container.stop();
			$container.animate(
			{
				marginLeft:0-($loc*1000)+"px"
			},
			_opt
			);
		}
		
		return $loc;
		
	}
 	function nextImage($container,$loc) {
		$tmpLoc = $loc;
		$tmpLoc++;
		if($tmpLoc*1000<$container.width()){

			$loc++;

			var _opt = {
				duration: 500,
				easing: "easeOutExpo"
			};
			
			
			
			$container.stop();
			$container.animate(
			{
				marginLeft:0-($loc*1000)+"px"
			},
			_opt
			);
		}
		
		return $loc;		
	}
    
})(jQuery);


