RibbonScroller = function() {
  this.__constructor();
}

$.extend(RibbonScroller.prototype, {

	timer					: null,
	current_mouse_delta 	: 0,
	reductor 				: 25,
	
	viewport_top			: 0,
	viewport_bottom			: 0,
	viewport_center			: 0,
	viewport_width			: 0,
	
	max_slider_margin		: 0,
	
	curr_scroll_left		: 0,
	new_scroll_left			: 0,
	max_scroll				: 0,
	scroll_amount			: 0,
	
	__constructor: function() {
		
		
		$(".ribbon-scroll-viewport").attr('scrollLeft', 0 );
		
		var __instance = this;

		this.timer = setInterval(function() { __instance.DoScroll() }, 30);

		__instance.CalculateViewport();
		
		$(window).resize(function() {
			__instance.CalculateViewport();
		});
		
		
		$("body").mousemove(function(e) {
			if( 
				e.clientY + $(window).scrollTop() >= __instance.viewport_top &&  
				e.clientY + $(window).scrollTop() <= __instance.viewport_bottom
			) {
				__instance.current_mouse_delta = __instance.viewport_center - e.clientX;
			} else {
				__instance.current_mouse_delta = 0;
			}
			
		});
	},
	
	CalculateViewport: function() {
		this.viewport_top		= $(".ribbon-scroll-viewport").position().top;
		this.viewport_bottom	= this.viewport_top + $(".ribbon-scroll-viewport").height();
		this.viewport_width		= $(window).width();
		this.viewport_center	= this.viewport_width / 2;
		
		this.max_scroll 		=  $(".ribbon-scroll-viewport .ribbon") - this.viewport_width;
		
	},
	
	DoScroll: function() {
		if( Math.abs(this.current_mouse_delta) > 300  ) {
			
			this.curr_scroll_left	= $(".ribbon-scroll-viewport").attr('scrollLeft');
			this.new_scroll_left	= this.curr_scroll_left - this.current_mouse_delta/45;
			
			if( this.new_scroll_left < 0 ) this.new_scroll_left = 0;
	
			$(".ribbon-scroll-viewport").attr('scrollLeft', this.new_scroll_left );
			
			this.scroll_amount = this.new_scroll_left / this.max_scroll;
			if( this.scroll_amount > 1 ) this.scroll_amount = 1;
		}
	},
	
	GetCurrentDelta: function() {
		return this.current_mouse_delta;
	}
	
	
	
});
