initImages = function( id ) {
  document.observe('dom:loaded',function()
    {
      var options = { duration: 1, scope: 'banner', queueLimit: null };
      var tabsHandler = new Tabs( options );
      
      options = {};
      options.showFunction = tabsHandler.showFunction.bind( tabsHandler );
      options.hideFunction = tabsHandler.hideFunction.bind( tabsHandler );

      var tabs = new Control.Tabs( $(id), options );
      tabsHandler.tabs = tabs;
      var tabsTimer = new TabsTimer( tabs, tabsHandler, { interval: 5000 } );
    }
  );
}

Tabs = Class.create({
  initialize: function(options){
	  this.options = {
			duration: 1,
			scope:    '',
			slow:     false
		};
		Object.extend(this.options,options || {});
	},
	showFunction: function( item ) {
     new Effect.Appear( item, { duration: this.getDuration(), afterFinish: this.effectAfterFinish.bind( this ), queue: { position: 'end', scope: item.id } } )
  },
  hideFunction: function( item ) {
    new Effect.Fade( item, { duration: this.getDuration(), queue: { position: 'end', scope: item.id } } )
  },
  effectAfterFinish: function() {

  },
  getDuration: function() {
    return this.options.slow ? this.options.duration * 2 : this.options.duration;
  }
}
)

TabsTimer = Class.create({
	initialize: function( tabs, tabsHandler, options){
	  this.tabs = tabs;
	  this.tabsHandler = tabsHandler;
	  this.options = {
			interval: 8000
		};
		Object.extend(this.options,options || {});
		
		this.tabs.observe( 'afterChange', this.schedule.bind( this ) );
		this.schedule();
	},
	schedule: function() {
	  this.reset();
	  this.timeout = window.setTimeout( this.next.bind( this ), this.options.interval );
	},
	next: function() {
	  this.tabsHandler.options.slow = true;
	  try {
  	  this.tabs.links.each(function(link,i){
  			if(this.activeLink == link && this.links[i + 1]){
  				this.setActiveTab(this.links[i + 1]);
  				throw new Exception;
  			}
  		}.bind(this.tabs));
  		this.tabs.first();
	  }
    catch(e) {}
    
	  this.tabsHandler.options.slow = false;
	},
	reset: function() {
	  try {
	    window.clearTimeout( this.timeout );
	  } catch(e) {}
	}
}
);