// JavaScript Document

slider_modul = new Class ({
initialize: function(options){ 
this.options = Object.extend({ autoroll: 0, total: 0, delaytime: 10 }, 
options || {}); this.elements = []; this._next = 0; },

start: function() {
if(!$('slider-content-container') || !$('slider-content-container').getChildren()) return;
this.container = $('slider-newsitem');
this.container.setStyles ({ overflow: 'hidden',
display: 'block', position: 'relative' });
$('slider-content-container').getChildren().each(function (el){
el.setStyles({ opacity: 0, display: 'inline-block', width: this.container.offsetWidth, position: 'absolute', top: 0, left: 0 });
el.remove().inject (this.container); this.elements.push(el); },this);
this.animfirst(); },
	
run: function() {
if(!this.options.autoroll || this.options.total<2) return;
this._next = this._current < this.options.total - 1?this._current+1:0;
this.timer = setTimeout(this.swap.bind(this), this.options.delaytime*1000);	},
	
goNext: function() { return (this._current < this.options.total - 1)?this._current+1:0; },
goPrev: function() { return this._current > 0 ? this._current - 1 : this.options.total - 1; },
next: function() { this._next = this.goNext(); this.swap(); },
prev: function() { this._next = this.goPrev(); this.swap(); },
	
toogle: function() { },
swap: function() { if(!this.elements.length) return; clearTimeout(this.timer); this.animrun(); },

animfirst: function (){ this._current = 0; var el2 = this.elements[this._current];
new Fx.Style(el2, 'opacity').start(0, 1);
new Fx.Style(this.container, 'height').start(0, el2.offsetHeight);
this.run(); },
	
animrun: function() { var el1 = this.elements[this._current]; this._current = this._next; var el2 = this.elements[this._current];
new Fx.Style(el1, 'opacity').start(1, 0);
new Fx.Style(el2, 'opacity').start(0, 1);
new Fx.Style(this.container, 'height').start(el1.offsetHeight, el2.offsetHeight);
this.run(); }
});
	
var slider_m = new slider_modul({ autoroll: 1, total: 3, delaytime: 5 });
window.addEvent('domready', function() { slider_m.start(); });
