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= '<h2>Alaska Oil &amp; Gas Congress 2011</h2><div class="left top10">Join the thought-leaders and decision makers that enable energy development in Alaska. Understand the current landscape and get the critical details you need to capitalize on opportunities in the state.<br/><br/><a href="/conference"><img src="/images/learn.png" height="30"></img></a></div>';
    	var four = '<h2>In-State Energy Supply Summit</h2><div class="left top10">Realize Alaska’s immediate energy needs. Investigate solutions to prevent a supply crisis in gas and power. Discover the opportunities.<br/><br/><a href="/conference"><img src="/images/agenda.png" height="30"></img></a></div>';
    	/*var third = '<h2>Register Now and Save!<br/>Early Bird Offer Expires August 23, 2011</h2><div class="left top15">Take advantage of the early bird offer when you register and pay by Tuesday, August 23, 2011.<br/><br/><a href="/pricing"><img src="/images/learn.png" height="30"></img></a></div>'
    	var four = '<h2>Discover Alaska</h2><div class="left top10">Don\'t miss the chance to enjoy the beauty of Alaska while you are in town for the Alaska Oil &amp; Gas Congress<br/><br/><a href="/venue"><img src="/images/learn.png" height="30"></img></a></div>'*/
		var third = '<h2>Download the 2011 Alaska Oil & Gas Congress Brochure</h2><div class="left top10">This year’s information-packed program brings you the latest regulatory and policy developments, pipeline progress reports, natural gas supply/demand forecasts, project development updates on state and federal lands and the OCS, and much more!<br/><br/><a href="javascript:downloadAgenda();"><img src="/images/downloadagenda.png" height="35"></img></a></div>';
		
		var six = '<h2>Enrich your understanding on all things offshore in Alaska...</h2><div class="left top10">Get the latest on Arctic geopolitics, offshore & OCS potential, permits, new policy, spill prevention and response in Arctic waters and more<br/><br/><a href="http://alaskaoilandgascongress.com/offshore1"><img src="/images/learn.png" height="30"></img></a></div>';
		var seven = '<h2>Get all the pipeline updates ...</h2><div class="left top10">Alaska Pipeline Project to the lower 48, in-state gas line and TAPS! Hear first-hand from TransCanada, Alaska Gasline Development Corp. and Ayeska Pipeline Service Company. <br/><br/><a href="/pipeline"><img src="/images/learn.png" height="30"></img></a></div>';
		
		var five = '<h2>VIDEO: The Berger Commission and Its Aftermath: Looking Back 33 Years Later</h2><div class="left top10">Thomas R. Berger, the chairman of the 1975-1977 Mackenzie Valley Pipeline Inquiry, gave a keynote address at the recent Arctic Gas Symposium sharing his unique perspective on developments in northern energy developments.<br/><br/><a href="/Berger">Watch Video</a></div>';
		
		var second = '<h2>VIDEO: Developing Locally Means Thinking Regionally</h2><div class="left top10">Senator Lesil McGuire explores the role of subnational jurisdictions in the exploration and development of energy resources in the U.S. and Canadian Arctic in a special keynote address given at the 2010 Arctic Gas Symposium.<br/><br/><a href="/McGuire">Watch Video</a></div>';
		
		var eight = '<h2>VIDEO: The National Energy Board’s Arctic Offshore Drilling Review</h2><div class="left top10">Robert Steedman (Professional Leader, Environment) of the National Energy Board gave an insightful presentation on the NEB’s review of Arctic safety and environmental offshore drilling requirements at the recent Arctic Gas Symposium. <br/><br/><a href="/Steedman">Watch Video</a></div>';
		
		
    	var items = [first,second,third,four,five,six,seven,eight];
    	
    	var extra="";
    	if(val == 2) extra = " 15% #dddddd";
    	
    	this.body.setStyle('background',"url('../images/slideshow/"+val+".png') no-repeat"+extra);
    	this.text.update(items[val]);
    }
});
