
var NSlider = new Class ({
    'version': '0.0.1',

    Implements: [ Options ],

    getOptions: function() {
	return {
	    mask: '',
	    duration: 750,
	    delay:    5000,

	    foobar: false
	};
    },

    initialize: function(options){
	this.currentCol = 0;

	this.setOptions(this.getOptions(), options);

	this.mask = $(this.options.mask);
	this.mask.addEvent('mouseover', this.onOver.bind(this) );
	this.mask.addEvent('mouseout', this.onOut.bind(this) );
	bl = this.mask.getStyle('border-left-width').toInt();
	br = this.mask.getStyle('border-right-width').toInt();
	this.width  = this.mask.getSize().x - bl - br;
	bt = this.mask.getStyle('border-top-width').toInt();
	bb = this.mask.getStyle('border-bottom-width').toInt();
	this.height = this.mask.getSize().y - bt - bb;
	this.mask.setStyle('overflow', 'hidden');
	this.mask.setStyle('position', 'relative');

	this.columns = $$('#'+this.options.mask+' div.nslidercol');
	for ( i=0; i<this.columns.length; i++) {
	    el = this.columns[i];
	    el.setStyle('display', 'block');
	    el.setStyle('width',   this.width+'px' );
	    el.setStyle('height',  this.height+'px' );
	    el.setStyle('float',  'left' );
	}


	this.masks= $(this.options.mask+'sheet');
	if ( !this.masks ) { this.mask = null; return; }
	masksw = this.width*this.columns.length;
	this.masks.setStyle('width', masksw +'px');
	this.masks.setStyle('position', 'absolute');
	this.masks.setStyle('top', 0);
	this.masks.setStyle('left', 0);
	this.masks.setStyle('float', 'left');


	this.stopped = 0;
	this.effect = new Fx.Tween(this.masks, { duration: this.options.duration } );	
    },

    /* ******************************************************************** */
    /* ******************************************************************** */

    start: function() {
	if ( !this.mask ) { return; }

	this.timer = this.doSlide.periodical(this.options.delay, this);
    },

    stop: function() {
	$clear(this.timer);
    },

    onOver: function() {
	this.stopped = 1;
	if ( this.started ) {
	    this.effect.pause();
	    this.paused = 1;
	}
    },

    onOut: function() {
	this.stopped = 0;
	if ( this.started ) {
	    this.effect.resume();
	    this.paused = 0;
	}
    },

    /* ******************************************************************** */
    /* ******************************************************************** */

    doSlide: function() {
	if ( !this.mask ) { return; }
	if ( this.stopped) { return; }

	if ( this.paused ) {
	    return;
	}

	if( this.currentCol < this.columns.length-1 ) {
	    this.currentCol += 1;
	}
	else {
	    this.currentCol = 0;
	}

        var x = (this.currentCol* - this.width);
	this.started = 1;
        this.effect.start('left', x);

    },

    /* ******************************************************************** */
    /* ******************************************************************** */

    foo: function() {}
});


