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>Regulatory Compliance for Financial Institutions Conference 2011</h2><div class="left top10 text">Canada\'s Premier event for banking and insurance professionals. Delivering practical and current compliance information and future trends from the regulators and leading experts.<br/><br/><a href="/why-attend"><img src="/images/learn.png" height="30"></img></a></div>';
    	var second = '<h2>Workshops</h2><div class="left top10">Back by popular demand are the pre-conference workshops, <span class="bold">Fundamentals of Compliance</span> and a <span class="bold">Guidebook to Developing an LCM Program</span>, which have been updated to reflect new trends and emerging concerns.<br/><br/><a href="/workshops"><img src="/images/agenda.png" height="30"></img></a></div>'
    	var third = '<h2>Save up to $200!<br/>Early Bird Offer Expires October<br/> 19, 2011</h2><div class="left top15">Take advantage of the early bird offer when you register and pay by October 19, 2011(pay only $1995).<br/><br/><a href="/pricing"><img src="/images/learn.png" height="30"></img></a></div>';
    	/* '<h2>Save up to $300!<br/>Early Bird offer expires July 22, 2011</h2><div class="left top15">Take advantage of the early bird offer when you register and pay by July 22, 2011(pay only $1895).<br/><br/><a href="/pricing"><img src="/images/learn.png" height="30"></img></a></div>';*/
		
    /*	var four = '<h2>New Developments from the FCAC</h2><div class="left top10">"The momentum to increase financial literacy levels in Canada and around the world is stronger than ever,"  says FCAC\'s Commissioner, Ursual Menke.  Gain strategies to promote best practices and spark new business initiatives while staying compliant with the consumer protection initiatives of the FCAC.<br/><br/><a href="/agenda"><img src="/images/learn.png" height="30"></img></a></div>'*/
	
	   	var five = '<h2>Credit Unions: Breaking through the Shackles of Provincial Boundaries to Nurture Growth and Expansion - Sunrise Seminar</h2><div class="left top10 text" style="margin-top: 4px;">Credit Unions are on the verge of entering the federal playground, which will open up a wealth of new challenges and competition. Let the experts guide you through the hurdles of the federal charter option to maximize the business opportunities.<br/><a href="/agenda/credit"><img src="/images/learn.png" height="30"  style="margin-top: 4px;"></img></a></div>'
	   	var six = '<h2>Conducting Enhanced Due Diligence for Compliance with FINTRAC Directives</h2><div class="left top10  text">The importance of a solid forensic fraud analysis system in today\'s climate cannot be understated. Hear directly from FINTRAC on the necessary steps you must take to protect your FI when dealing with Politically Exposed Foreign Persons.<br/><br/><a href="/agenda"><img src="/images/learn.png" height="30"></img></a></div>'
	   	var seven = '<h2>Developing and Implementing a Comprehensive AML/ATF Compliance Program</h2><div class="left top10">You know your AML compliance obligations, but how can you discharge those duties efficiently and in a cost effective manner? Gain expert strategies to create a tailor-made compliance program to suit your unique business needs.<br/><br/><a href="/agenda/aml"><img src="/images/learn.png" height="30"></img></a></div>';
	   	var eight = '<h2>Leveraging Advancing Technologies to Better Manage Privacy Obligations</h2><div class="left top10">Canada and the world have moved into the cloud and beyond. Privacy concerns are heightened in this digital era of advancing technologies. Ensure that you are equipped to protect privacy now and into the future.<br/><br/><a href="/agenda/obligations"><img src="/images/learn.png" height="30"></img></a></div>';
	   	var nine = '<h2>FATCA: An Overview of the Provisions and the Impact on FIs</h2><div class="left top10">For Canadian multinational FI, FATCA compliance is now a reality. The costs of implementing systems changes, monitoring and reporting will be borne primarily by non-U.S. FIs. How can you best prepare to manage increased costs to avoid costly compliance errors.<br/><br/><a href="/agenda/fatca"><img src="/images/learn.png" height="30"></img></a></div>';
	   	
	   	var ten = '<h2>Banking Track - Transitioning into the New Framework of Capital Adequacy Standards and Managing Liquidity Risk</h2><div class="left top10">Learn what you should do now to prepare for the tougher new global banking rules.<br/><br/><a href="/banking"><img src="/images/learn.png" height="30"></img></a></div>';
	   	var eleven = '<h2>Banking Track - Identifying Emerging Trends and Clearing Compliance Hurdles in the Payment Card Industry</h2><div class="left top10">Are you doing everything you can to ensure compliance with the new Code of Conduct? Gain a solid understanding of changes to the industry to meet and exceed regulatory obligations.<br/><br/><a href="/agenda/payment"><img src="/images/learn.png" height="30"></img></a></div>';
	   	var twelve = '<h2>Insurance Track - Managing the Impact of Recent Regulatory and Legislative Changes on the Administration of Insurance</h2><div class="left top10  text" style="margin-top: 4px;">The unprecedented disruption in the global financial markets has resulted in increased regulatory scrutiny across all levels of the insurance industry. Refresh your business model by getting a solid footing on regulatory and legislative changes that are on the horizon.<br/><a href="/insure"><img src="/images/learn.png" height="30" style="margin-top:4px;"></img></a></div>'
	   	var thirteen = '<h2>Insurance Track - Moving Towards Standardization and Future Trends for Outsourcing to Managing General Agents</h2><div class="left top10">Choosing the right MGA will increase your access to lucrative business opportunities.  With the anticipated overhaul to the model of insurance distribution, knowing what to expect from the regulators is key ensuring compliance.<br/><br/><a href="/agenda/general-agents"><img src="/images/learn.png" height="30"></img></a></div>';
	   	
    	var items = [first,five,twelve,six,third];
    	
    	var extra="";
    	if(val == 2) extra = " 15% #dddddd";
    	
    	var bgVal = val;
    	/*
    	if(val >= 3 && val <=8){
    		bgVal = 3; 
    	}
    	
    	if(val >=9 && val <=12){
    		bgVal = 4;
    	}*/
    	
    	this.body.setStyle('background',"url('../images/slideshow/"+bgVal+".png') no-repeat"+extra);
    	this.text.update(items[val]);
    }
});
