/* All code copyright 2008 Grzegorz Jaskowiec */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Follows: HorizontalScroller ver 0.9b (class)
 * Simple class for scroller
 * Copyright 2008 GJ.
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

var HorizontalScroller = new Class({

 initialize: function(element, options) {
 this.setOptions({
 movePrev:"",
 moveNext:"",
 numberOf:"3",
 visible:"4",
 contentPrefix:"ob",
 items:".item",
 action: null
 }, options);

 this.el = $(element);
 this.elID = element;
 this.currentChosen=0;
 this.movePrev =$(this.options.movePrev);
 this.moveNext =$(this.options.moveNext);
 this.contentPrefix = this.options.contentPrefix;
 this.contentCount=0;
 this.action = this.options.action;

 this.contentHandlers = $$('#' + this.elID + ' '+this.options.items);


 this.scroll_fx = new Fx.Scroll(this.elID, {
 wait: false,
 duration: 1200,
 
 offset: {'x': 0, 'y': 0},
 transition: Fx.Transitions.Bounce.easeOut
});

 this.contentHandlers.each(function(item, index) {
 imgs = item.getElement('div.m');	
 if(imgs)
 imgs.addEvents(
 {
	 'mouseenter':function(){this.addClass('hover')},
	 'mouseleave':function(){this.removeClass('hover')}
 });									
 imgs.addEvent('click',function(){this.action.goTo(index)}.bind(this));
 
 
 if(index%this.options.numberOf==0) {
 item.setProperty('id', this.contentPrefix +'_' + index/this.options.numberOf);
 this.contentCount=this.contentCount+1;
 }
 }.bind(this));

 this.movePrev.addEvent('click', function(event) {
 event = new Event(event).stop();
 if(this.currentChosen>0) {
 this.scroll_fx.toElement(this.contentPrefix +'_' + (this.currentChosen-1));
 this.currentChosen=this.currentChosen-1;
 }

 this.changeActivity();

 }.bind(this));


 this.moveNext.addEvent('click', function(event) {
 event = new Event(event).stop();
 if(this.currentChosen<(this.contentCount-this.options.visible)) {
 this.scroll_fx.toElement(this.contentPrefix +'_' + (this.currentChosen+1));
 this.currentChosen=this.currentChosen+1;
 }
 this.changeActivity();

 
 
 }.bind(this));

this.scroll_fx.toElement(this.contentPrefix +'_0');
 this.changeActivity();
 },

 changeActivity: function() {
 if(this.currentChosen>0) this.movePrev.removeClass('notActive'); else this.movePrev.addClass('notActive');
 if(this.currentChosen<(this.contentCount-this.options.visible)) this.moveNext.removeClass('notActive'); else this.moveNext.addClass('notActive');
 }
 });

HorizontalScroller.implement(new Options, new Events);


