

var scroll_manager = function(){};

scroll_manager.scroll_multiplier = 50;   // Basicall the scroll speed.
scroll_manager.max_scroll_speed = 60;    // The max scroll speed.
scroll_manager.x_position = 0;           // The target x position.
scroll_manager.total_page_width = 29999; // The total page width.

scroll_manager.on_mousewheel = function (event, delta) {
	if(window.sidescroll != 'off') {
		var addedScroll = -delta * scroll_manager.scroll_multiplier;
		
		if (addedScroll > scroll_manager.max_scroll_speed) {
	        addedScroll = scroll_manager.max_scroll_speed;
	    };
	    if (addedScroll < -scroll_manager.max_scroll_speed) {
	        addedScroll = -scroll_manager.max_scroll_speed;
	    };
	    scroll_manager.set_scroll_target(scroll_manager.x_position + addedScroll, true);
	}
};

scroll_manager.set_scroll_target = function (pos, is_mousewheel) {
	var page_width = scroll_manager.total_page_width - parseInt($(window).width());
	
	scroll_manager.x_position = pos;
    if (scroll_manager.x_position < 0) {
        scroll_manager.x_position = 0;
    }
    if (scroll_manager.x_position > page_width) {
        scroll_manager.x_position = page_width;
    }
	$(window).scrollLeft(scroll_manager.x_position);
};

scroll_manager.on_scrollbar_drag = function (e) {
	scroll_manager.x_position = $(window).scrollLeft();
};

$(window).scroll(scroll_manager.on_scrollbar_drag);
$(document).mousewheel(scroll_manager.on_mousewheel);
