(function( $ ){ $.fn.aRotator = function(options) {
		
	var defaults = {
		interval: 4000,
		transition: 500,	
		hoverStop: false,
		title: false
	};
	
	var options = $.extend(defaults, options);

	return this.each(function(index) {
		var $this = $(this);
				
		$active = $this.find('.paging a:first');
		$active.addClass('active');
				
		var imageWidth = $this.width();
		var imageSum = $this.find(".image_reel .cadre").size();
		var imageReelWidth = imageWidth * imageSum;
		//Adjust the image reel to its new size
		$this.find(".image_reel").css({'width' : imageReelWidth});
		
		function rotate(){
			var triggerID = $active.attr("rel") - 1; //Get number of times to slide
			var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide
			$this.find(".paging a").removeClass('active'); //Remove all active class
			$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
			//Slider Animation
			if(options.title==true)	{ $this.find(".image_reel .cadre .titre").fadeOut('fast'); $this.find(".image_reel .cadre .comment").fadeOut('fast'); }
			
			$this.find(".image_reel").animate(
				{	left: -image_reelPosition },
				options.transition,
				function(){
					if(options.title==true)	{ $this.find(".image_reel .cadre .titre").fadeIn('fast'); $this.find(".image_reel .cadre .comment").fadeIn('fast'); }
				}
			);
		}; 
	
		//Rotation  and Timing Event
		function rotateSwitch(){
			$this.data("timer", setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
				$active = $this.find('.paging a.active').next(); //Move to the next paging
				if ( $active.length === 0) { //If paging reaches the end...
					$active = $this.find('.paging a:first'); //go back to first
				}
				rotate(); //Trigger the paging and slider function
			}, options.interval)); //Timer speed in milliseconds
		};
		
		$this.find('.paging a').click(function(){
			$active = $(this);
			rotate();
		});
		
		$this.mouseover(function(){
			if(options.hoverStop==true){
		    clearTimeout($this.data("timer"));
			}
		});
		
		$this.mouseout(function(){
			if(options.hoverStop==true){
		    rotateSwitch();
			}
		});
		
		rotateSwitch();
		
	});
   
}})( jQuery );
