var BannerFade = new Class({
	options: {
		banner: 'bannerMarkets',
		images: 'bannerimages',
		items: 'bannernav',
		currentClassName: 'current',
		offset: 211,
		slideShow: false,
		refreshRate: 10000,
		useConsole: false,
		hideTabs:false
	},
	initialize: function(options) {		
		// Set the Options.
		this.setOptions(options);

		// Do this within a try/catch so there are no nasty 'uncaught exception' error messages if anything goes wrong
		try {
		
			// Get the Container, Panels and Tabs as Class properties..
			BannerFade.container = $(this.options.banner);
			BannerFade.imagecontainer = $(this.options.images);
			BannerFade.tabs  = $$('#' + this.options.items + ' li');
			
			count = BannerFade.tabs.length;
			offset = this.options.offset; 
			currentClassName = this.options.currentClassName;
			
			//if(this.options.hideTabs) {
			//	$(this.options.items).setStyle('display', 'none');
			//}
			
			BannerFade.tabs.each(function(element, i) {
				
				fx = new Fx.Styles(BannerFade.imagecontainer, {duration:800, wait:false});
			 
				element.addEvent('mouseenter', function(){	
					BannerFade.container.current = i;
					
					fx.start({
						'top': -(offset * i)
					});
					BannerFade.tabs.each(function(el){
						 el.removeClass(currentClassName);											
					});
					element.addClass(currentClassName);
				});
			});
			
			// If set in the Options, start a periodical effect.
			if(this.options.slideShow) {
				BannerFade.interval = this.beginPeriodical();
				// BannerFade.container.addEvent("mouseenter", this.resetPeriodical.bindWithEvent(this));
				// BannerFade.container.addEvent("mouseleave", this.beginPeriodical.bindWithEvent(this));
			}

		} catch(err) {
			if(this.options.useConsole) {}
		}
	
	},
	periodicalBanner: function() {
		
		// Do this within a try/catch so there are no nasty 'uncaught exception' error messages if anything goes wrong
		try {
		
			if(!BannerFade.container.current){
				BannerFade.container.current = 0;
			}
			len = BannerFade.tabs.length;
	
			if(BannerFade.container.current == len -1) {
				BannerFade.container.current = 0;
			}else{
				BannerFade.container.current++;
			}
	
			fx.start({
				'top': -(offset * BannerFade.container.current)
			});
			
			BannerFade.tabs.each(function(el){
				 el.removeClass(currentClassName);											
			});
			
			BannerFade.tabs[BannerFade.container.current].addClass(currentClassName);

		} catch(err) {
			if(this.options.useConsole) {}
		}
		
	},
	beginPeriodical:function() {

		this.resetPeriodical();
		var myRefreshRate = this.options.refreshRate;
		BannerFade.interval = this.periodicalBanner.periodical(myRefreshRate);
		return BannerFade.interval;
	},
	resetPeriodical:function() {
		return $clear(BannerFade.interval);
	}
	
});

// Extend the Scrollpanel Class with the Options Class.  
BannerFade.implement(new Options());

// Add the Class init to the DomReady signal.
window.addEvent('domready', function() {
																		 
	var BannerObj = new BannerFade({
		banner: 'bannerMarkets',
		images: 'bannerimages',
		items: 'bannernav',
		currentClassName: 'current',
		offset: 211,
		slideShow: true,
		refreshRate: 15000,
		useConsole: false,
		hideTabs:true
	});

});
