// JavaScript Document

var sfs_scroller = new Class({
	options: {
		scroller:'',
		viewer:'',
		arrow_prev:'',
		arrow_next:'',
		direction:"x"
	},

	initialize: function(options) {
		var th = this;
		this.current_page = 1;
		this.total_pages = 0;
		this.window_size=0;
		this.setOptions(options);
		this.viewer_width = this.options.viewer.getSize().x;
		this.viewer_height = this.options.viewer.getSize().y;
		this.scroll_width = this.options.scroller.getSize().x;
		this.scroll_height = this.options.scroller.getSize().y;
		if(this.options.viewer.getStyle('position') != 'absolute') {
			this.options.viewer.setStyle('position','relative');
		}
		this.options.scroller.setStyle('position','absolute');
		
		if(this.options.direction == 'x') {
			this.total_pages = Math.ceil(this.scroll_width / this.viewer_width);
			this.window_size = this.viewer_width;
			this.options.viewer.setStyle('height',this.scroll_height);
			
		} else {
			this.total_pages = Math.ceil(this.scroll_height / this.viewer_height);
			this.window_size = this.viewer_height;
		}
		this.arrow_next = this.options.arrow_next;
		this.arrow_prev = this.options.arrow_prev;
		this.arrow_next.addEvent('click',function() {
			th.current_page = Math.min(th.total_pages,th.current_page+1);
			th.move();
			return false;
		});
		this.arrow_prev.addEvent('click',function() {
			th.current_page = Math.max(1,th.current_page-1);
			th.move();
			return false;
		});
	},
	
	test:function() {
		//alert(this.viewer_width);	
	},
	move:function() {
		//alert (this.current_page);
		sc = this.options.scroller
		sc.tween((this.options.direction=='x'? 'left' : 'top'),-(this.current_page-1)*this.window_size);
	},
	moveto:function(to) {
		this.current_page = to;
		this.move();
	},
	setpage:function(page) {
		this.current_page = page;
		sc = this.options.scroller
		if(this.options.direction=='x') {
			sc.setStyle({left:(this.current_page-1)*this.window_size});
		} else {
			
		}
		
		
	}
	
	
})

sfs_scroller.implement(new Events); // Implements addEvent(type, fn), fireEvent(type, [args], delay) and removeEvent(type, fn)
sfs_scroller.implement(new Options);// Implements setOptions(defaults, options)