/**
 * Script: Wood For Good
 * Version : 1.0.3
 * Revision Date : 27/07/2011
 * Purpose : This script initialises on dom ready, MODx vars are passable via class initialisation
 */
var pageinateIt = new Class({
    //implements
    Implements: [Options],

    //options
    options: {
        docid: '',	
		totalpages: '',
		pagereset: 1
    },

    //initialization
    initialize: function (options) {
		this.setOptions(options);
		var jaxurl = this.options.docid;
		var totalpages = this.options.totalpages
		//var pagereset = this.options.pagereset;
		this.pageinate(jaxurl,totalpages);
	},

    //a method that does whatever you want
    pageinate: function(jaxurl,totalpages){
		var pageCount = 1;
		var nextPageSel = $$('.nextPage');

		nextPageSel.addEvent('click', function (e) {
			var nextPage = this.get('id');
			//alert(nextPage);
			e.stop();
			if(nextPage == 'nextPage'){
				var getNext = 1+pageCount;
			}
		
			
			var animate = new Fx.Morph('cases', {
			  duration: 'short',
			  transition: Fx.Transitions.Sine.easeOut
			});
			new Request.HTML({
				url: jaxurl+'&page=' + getNext,
				onRequest: function () {
					animate.start({
					  'margin-left': [0, 20],
					  'opacity': 0 
					});
				},
				onComplete: function (response) {
					(function () {
					  $('cases').empty().adopt(response);
					  animate.start({
						'margin-left': [-20, 0],
						'opacity': 1
					  });
					}).delay(300);
					//alert(totalpages);
					if(pageCount==(totalpages-1)){ 
						pageCount= 0;
					}else{
						pageCount++;
					}
				}
			  
			}).send();
		});
		var nextGenreSel = $$('.genres li');
		nextGenreSel.each(function (e) {
			
			alert('f');
			
		});
		
	}
});
