window.addEvent('domready', function() { 

	//hiding showing form
	var reactSlide = new Fx.Slide('react', {
	    duration: 'long',
	    transition: Fx.Transitions.Pow.easeOut
	});
	reactSlide.hide();
	$('form-handle').addEvent('click', function(){
		this.toggle();
	}.bind(reactSlide));
	
	//pagination
	if ($$('#pagination div.pages').getElements('a').length > 12) {
		var pager = new Pagination({container: $$('#pagination div.pages')[0]});
	}
});



var Pagination = new Class({
	
	Implements: Options,
	
    initialize: function(options){
        this.setOptions(options);        
        this.setup(options.container);
    },
    
    buttons: $A,
    buttonWidth: 0,
    lastI: 0,
    firstI: 0,
    currentI: 0,    
    scrollFx: $empty,    
    
    setup: function(container){
    
    	this.buttons = container.getElements('a');
    	this.lastI = this.buttons.length - this.options.total;
    	this.scrollFx = new Fx.Scroll(container);
    	
    	//add clickers
    	$$('a.first').addEvent('click',function(event){
			event.preventDefault();
			this.goFirst();
		}.bind(this));		
		$$('a.next').addEvent('click',function(event){
			event.preventDefault();
			this.goNext();
		}.bind(this));		
		$$('a.prev').addEvent('click',function(event){
			event.preventDefault();
			this.goPrev();
		}.bind(this));		
		$$('a.last').addEvent('click',function(event){
			event.preventDefault();	
			this.goLast();
		}.bind(this));
		
    },
    
    goNext: function(){
   	    var next = (this.currentI + this.options.total);
		this.currentI = (next > this.lastI) ? this.lastI : next;
		this.scrollFx.toElement( this.buttons[this.currentI] );
    },
    
    goPrev: function(){
   	    var prev = (this.currentI - this.options.total);
		this.currentI = (prev < this.firstI) ? this.firstI : prev;
		this.scrollFx.toElement( this.buttons[this.currentI] );
    },
    
    goFirst: function(){
   		this.currentI = this.firstI;
   		this.scrollFx.toElement(this.buttons[this.currentI]);
    },
    
    goLast: function(){
    	this.currentI = this.lastI;
   		this.scrollFx.toElement(this.buttons[this.currentI]);
    },
    
    options: {
		total: 12,
		buttonFirst:'a.first',
		buttonNext: 'a.next',
		buttonPrev: 'a.prev',
		buttonLast: 'a.last'
    }
});