
var core = function(){
  return {
		
		pos: 2,
		total: 6,
		front: true,
		firstRun: true,
		
	  init: function(){
			this.runSlideShow();
		},
		
		runSlideShow: function(){
		  this.mainSlide = Ext.get('main-slide');
			this.backSlide = Ext.get('back-slide');
			
			Ext.TaskMgr.start({
					run: this.nextSlide,
					scope: this,
					interval: 6000
			});
		},
		
		nextSlide: function(){
			if(this.firstRun == true){
			  this.firstRun = false;
				return;
			}
		  if(this.front == true){
			  this.mainSlide.fadeOut({duration:1.4, callback: this.swapSrc});
			} else {
			  this.mainSlide.fadeIn({duration:1.4, callback: this.swapSrc});
			}
		},
		
		swapSrc: function(){
			core.pos++;
			if(core.pos > core.total){
			  core.pos = 1;
			}
		  if(core.front == true){
			  core.mainSlide.dom.src = '/wp-content/themes/cloud9adventure/img/slides/00'+core.pos+'.jpg';
				core.front = false;
			} else {
			  core.backSlide.dom.src = '/wp-content/themes/cloud9adventure/img/slides/00'+core.pos+'.jpg';
				core.front = true;		
			}
		}
		
	}
}();

Ext.onReady(function(){ core.init(); });
