
		ScrollableTeaserController = function () {

			this.registerScroller = function (query, onPage, scrollerConfig, autoScrollConfig) {
				if (!scrollerConfig) {
					scrollerConfig = {vertical: true, mousewheel: true, keyboard: false};
				}
				
				var scroller = $(query);

				scroller.scrollable(scrollerConfig);
				
				if (autoScrollConfig) {
					scroller.autoscroll(autoScrollConfig);
					
					var controlsContainer = scroller.parent().find('.scrollControlsContainer').eq(0);
					
					controlsContainer.mouseenter(function () {
						var scrollerAPI = $(this).parent().find('.twitterTickerBoxContainer').eq(0).data("scrollable");
						scrollerAPI.pause();
					});
					controlsContainer.click(function () {
						var scrollerAPI = $(this).parent().find('.twitterTickerBoxContainer').eq(0).data("scrollable");
						scrollerAPI.pause();
					});
					
					controlsContainer.mouseleave(function () {
						var scrollerAPI = $(this).parent().find('.twitterTickerBoxContainer').eq(0).data("scrollable");
						scrollerAPI.play();
					});
				}

				var newProperties = {
					onPage: onPage,
					numPages: Math.ceil(scroller.data('scrollable').getSize()/onPage),
					numItems: scroller.data('scrollable').getSize(),
					currentPage: 0
				};

				this.updateProperties(query, newProperties);
				this.updateControls(query);
				
				scroller.data('scrollable').begin(0);

				scroller.bind("onSeek", function () {
					ScrollableTeaserController.getInstance().updateControls(this);
				});

			};
			

			this.next = function (query) {
				var scroller = $(query);
				var scrollerAPI = scroller.data("scrollable");
				var properties = scroller.data('scrollableProperties');
				var config = scrollerAPI.getConf();

				if (properties) {
					properties.currentPage = Math.floor(scrollerAPI.getIndex()/properties.onPage);
					
					var targetPage = properties.currentPage+1;
					
					if (targetPage <= (properties.numPages-1)) {
						var targetItem = properties.onPage*targetPage;

						if (targetItem < properties.numItems) {
							properties.currentPage = targetPage;
							scrollerAPI.seekTo(targetItem);
							this.updateProperties(scroller, properties);
						}
					} else if (config.circular) {
						targetPage = 0;

						properties.currentPage = targetPage;
						scrollerAPI.next();
						this.updateProperties(scroller, properties);
					}
				}
			};


			this.previous = function (query) {
				var scroller = $(query);
				var scrollerAPI = scroller.data("scrollable");
				var properties = scroller.data('scrollableProperties');
				var config = scrollerAPI.getConf();
				

				if (properties) {
					properties.currentPage = Math.floor(scrollerAPI.getIndex()/properties.onPage);
					
					var targetPage = properties.currentPage-1;

					if (scrollerAPI.getIndex() % properties.onPage) {
						targetPage = properties.currentPage;
					}
					
					if (targetPage >= 0) {
						var targetItem = properties.onPage*targetPage;

						if (targetItem >= 0) {
							properties.currentPage = targetPage;
							scrollerAPI.seekTo(targetItem);
							this.updateProperties(scroller, properties);
						}
					} else if (config.circular) {
						targetPage = properties.numPages-1;

						properties.currentPage = targetPage;
						scrollerAPI.prev();
						this.updateProperties(scroller, properties);
					}
				}
			};


			this.updateControls = function (query) {
				var scrollerAPI = $(query).data('scrollable');
				var properties = $(query).data('scrollableProperties');
				var config = scrollerAPI.getConf();
				
				var btnUp = $(query).parent().find('.scrollControlsContainer .up');
				var btnDown = $(query).parent().find('.scrollControlsContainer .down');

				properties.currentPage = Math.floor(scrollerAPI.getIndex()/properties.onPage);

				if (config.circular) {
					btnUp.toggleClass('disabled', false);
					btnDown.toggleClass('disabled', false);
				} else {
					btnUp.toggleClass('disabled', (scrollerAPI.getIndex() == 0));
					btnDown.toggleClass('disabled', (properties.currentPage == (properties.numPages-1)) || (properties.numPages == 0));
				}

				this.updateProperties(query, properties);
			};
			

			this.updateProperties = function (query, properties) {
				$(query).each(function () {
					$(this).data('scrollableProperties', properties);
				});
			};
			
		};

		ScrollableTeaserController.instance = null;
		ScrollableTeaserController.getInstance = function () {
			if (!ScrollableTeaserController.instance) {
				ScrollableTeaserController.instance = new ScrollableTeaserController();
			}

			return ScrollableTeaserController.instance;
		};

