SlideShow = Ext.extend(Object, {
    constructor: function(config){
    	SlideShow.superclass.constructor.apply(this);
    	
    	this.list = config.list;
    	this.limit = config.limit;
    	this.body = Ext.get(config.body);
    	
    	this.text = Ext.get('rotate-asp');
    	
    	this.init();
		
    },
    init:function()
    {	
		this.counter = 0;
		
		this.task = {
			run:this.rotateImage,
			scope:this,
			interval:10000
		};
		
		this.runner = new Ext.util.TaskRunner();
				
		var l = Ext.get(this.list);
		if(l != null){
			l.on('click',this.selectImage,this,{delegate:'a'});
			
			this.initLastLink();
			
			this.delayRotate();
			//this.runner.start(this.task);
		}
    },
    initLastLink:function(){
    	var ul = Ext.get(this.list);
    	
    	var li = new Ext.Element(ul.dom.children[this.counter]);
    	
    	this.lastLink = li.child('a');
    	this.lastLink.addClass('selected');
    },
    delayRotate:function(){
    	if(this.dtask)this.dtask.cancel();
    	
    	this.dtask = new Ext.util.DelayedTask(function(){
			this.runner.start(this.task);	
		},this);
		
		this.dtask.delay(10000);
    },
    rotateImage:function(){
    	var ul = Ext.get(this.list);
		
		this.lastLink.removeClass('selected');
    	
    	this.counter = (++this.counter)%this.limit;
    	
    	var li = new Ext.Element(ul.dom.children[this.counter]);
    	
    	this.lastLink = li.child('a');
    	this.lastLink.addClass('selected');
    	
    	this.setBackground(this.counter);
    },
    selectImage:function(e,target,o){
    	var el = new Ext.Element(target);
    	el.addClass('selected');
    	
    	if(this.lastLink){
    		this.lastLink.removeClass('selected');
    		this.lastLink = el;
    	}
    	
    	var img = el.dom.firstChild.data -1;
    	
    	this.runner.stopAll();
  		
  		this.counter = img;
  		this.setBackground(img);
  		
  		
  		this.delayRotate();
    },
    setBackground:function(val){
    	
    	var first = '<h1 style="font-size: 16px;">12th Annual Arctic Oil & Gas Symposium</h1><div class="left top15">Featuring keynotes, panel discussions and an unparalleled speaker faculty, the 2012 program covers all the most pressing issues &ndash; offshore, infrastructure, policy and pipeline updates and more!<br/><br/><a href="/agenda"><img src="/images/agenda.png" height="35"></img></a></div>';
		
		var second = '<h1 style="font-size: 16px;">The Who&rsquo;s Who of Arctic Oil & Gas Development</h1><div class="left top15">The passionate and knowledgeable speakers for 2012 include influential decision makers from government, industry and Aboriginal groups who are moving responsible Northern development forward. <br/><br/><a href="/speakers"><img src="/images/LearnMore.png" height="30"></img></a></div>';
		
		var third = '<h1 style="font-size: 16px;">Time is Running Out to Save $200 </h1><div class="left top15">Save $200 off the full Program fee! Register by February 14, 2012 to take advantage of our early bird offer.<br/><br/><a href="/pricing"><img src="/images/LearnMore.png" height="30"></img></a></div>';
		
		var  four= '<h1 style="font-size: 16px;">The latest Northern infrastructure and Arctic pipeline updates</h1><div class="left top15">Get first-hand details on the progress of natural gas pipeline projects, the all-weather road and Fiber Optics Link Project<br/><br/><a href="/infrastructure"><img src="/images/LearnMore.png" height="30"></img></a></div>';
		
		var  five= '<h1 style="font-size: 16px;">Enrich your understanding of all things offshore in the Arctic</h1><div class="left top15">Hear the results from the NEB\'s Arctic Offshore Drilling Review, Arctic spill preparedness and response progress, policy developments and more.<br/><br/><a href="/offshore"><img src="/images/LearnMore.png" height="30"></img></a></div>';
		
		var  six= '<h1 style="font-size: 16px;">Delve into top issues at 2 interactive workshops</h1><div class="left top15">Enhance your learning by attending these practical sessions on remote sensing technologies and a 101 on hydraulic fracturing and water use. <br/><br/><a href="/workshops"><img src="/images/LearnMore.png" height="30"></img></a></div>';
		
    	
		
    	var items = [first,second,third,four,five,six];
    	
    	/*var extra="";
    	if(val == 2) extra = " 15% #dddddd";+extra*/
    	
    	var bgVal = val;
    	/*
    	if(val >= 3 && val <=8){
    		bgVal = 3; 
    	}
    	
    	if(val >=9 && val <=12){
    		bgVal = 4;
    	}*/
    	
    	this.body.setStyle('background',"url('../images/slideshows/"+bgVal+".png') no-repeat");
    	this.text.update(items[val]);
    }
});
