Object.extend(Glider.prototype, {
	initialize: function(wrapper, options){
		this.scrolling  = false;
		this.wrapper    = $(wrapper);
		this.scroller   = this.wrapper.down('div.scroller');
		this.sections   = this.wrapper.getElementsBySelector('.section');
		this.options    = Object.extend({ duration: 1.0, frequency: 3, images: "images/" }, options || {});

		this.sections.each( function(section, index) {
			section._index = index;
		});

		if(this.options.autoGlide) this.start();
	},

	goTo: function(sectionId){
		var index = sectionId - 1;
		var currentIndex=0;
		
		if(this.current)
			currentIndex = this.current._index;

		if((index < this.sections.length) && (index >= 0)) {
			this.moveTo(this.sections[index], this.scroller, { duration: this.options.duration });
		}
	},

	moveTo: function(element, container, options){
		this.current = $(element);
		
		Position.prepare();
 		var containerOffset = Position.cumulativeOffset(container),
			elementOffset = Position.cumulativeOffset($(element));

		this.scrolling 	= new Effect.SmoothScroll(container, 
			{duration:options.duration, x:(elementOffset[0]-containerOffset[0]), y:(elementOffset[1]-containerOffset[1])});

		var controls = this.wrapper.getElementsBySelector('div.vcontrols img');
		var sectionId = (this.current ? this.current._index + 1 : 1);

		var images=this.options.images;
		controls.each( function(control, idx) {
			if(control.id.match("section"+sectionId))
				control.src = images+"/camSelection_roundButtonOver.png";
			else
				control.src = images+"/camSelection_roundButtonOut.png";
			});

		return false;
	}

});

