/**
 * @author Bruno Bornsztein <bruno@missingmethod.com>
 * @copyright 2007 Curbly LLC
 * @package Glider
 * @license MIT
 * @url http://www.missingmethod.com/projects/glider/
 * @version 0.0.4
 * @dependencies prototype.js 1.5.1+, effects.js
 */

/*  Thanks to Andrew Dupont for refactoring help and code cleanup - http://andrewdupont.net/  */

Glider = Class.create();
Object.extend(Object.extend(Glider.prototype, Abstract.prototype), {
	initialize: function(wrapper, options){
	    this.wrapper    = $(wrapper);
	    this.scroller   = this.wrapper.down('div.scroller');
	    this.sections   = this.wrapper.getElementsBySelector('div.section');
	    this.options    = Object.extend({ controlsEvent:'click', duration: 1.0, frequency: 3 }, options || {});
		this.laste		=	"section1";
		var i =0;
		
		//alert(Prototype.Browser.IE);
			  
	    this.sections.each( function(section, index) {
	      section._index = index;
		  i++;
		  if(i!=1) new Element.hide($("section"+i));
	    });  
		
		//alert(i);

	    this.events = {
	      click: this.click.bind(this)
	    };

	    this.addObservers();
			
	  	},
	
  addObservers: function() {
		this.controls = this.wrapper.getElementsBySelector('.controls a');
		this.controls.invoke('observe', this.options.controlsEvent, this.events.click);
  },	
  

  click: function(event) {
		var element = Event.findElement(event, 'a');
		var visible = Element.visible($(this.laste));
		if(visible) {
				new Element.hide($(this.laste));
				//new Effect.Fade($(this.laste));
		}
		this.laste = element.href.split("#")[1];
		new Effect.Appear($(element.href.split("#")[1]));
		Event.stop(event);

 	},
		
	periodicallyUpdate: function()
	{ 
		
	}

});


