ObjDFcarousel = new Class({
options : {
 autoplayInterval : 10000,
 autoplayMaxLoops : 0,
 bigListFxTransition : Fx.Transitions.Quint.easeInOut,
 bigListFxDuration : 800
 },

 initialize : function(el, autoplay, options) {
 this.setOptions(options);
 this._el = $(el);
 this._elTitle = $E(".dfctitle", this._el);
 this._bigListContainer = $E("div.dfclista", this._el).getFirst();
 this._bigList = $ES("div.dfcelement", this._bigListContainer);
 this._sideList = $ES("ul.Thumb li a", this._el);
 this._selIndex = null;
 this._selCount = this._bigList.length;
 this._elAutoplay = $E(".i-autoplay", this._el);
 this._isInProgress = false;
 this._timerId = null;
 this._currentLoop = 0;

 // DOM SETUP
 this._bigListContainer.setStyles({"position" : "absolute", "left" : 0, "top" : 0});

 // NAVIGATORs SETUP
 this._sideList.each(function(item, index) {
 item.addEvent("click", (function(event) {
 event = new Event(event);
 event.preventDefault();
 if (this.nav.isAutoplayInProgress()) {
 // AUTOPLAY IN PROGRESS --> STOP AND RESUME IT (TO AVOID TOO FAST CHANGING)
 this.nav.stopAutoplay();
 this.nav.startAutoplay();
 }
 this.nav.selNews(this.index);
 return false;
 }).bind({
 "nav" : this,
 "index" : index
 }))
 }.bind(this));

 // AUTOPLAY NAVIGATOR SETUP
 this._elAutoplay.addEvent("click", (function(e){new Event(e).preventDefault();this.switchAutoplay()}).bind(this));

 // STARTUP
 this.selNews(0);

 // AUTOPLAY
 if ($pick(autoplay, false)) {
 this.startAutoplay();
 } else {
 this.stopAutoplay();
 }
 },

 startAutoplay : function() {
 this._elAutoplay.className = "pause";

 this._currentLoop = 0;

 // TIMER
 if (this._timerId == null) {
 this._timerId = window.setInterval((function(){this.selNextNews()}).bind(this), this.options.autoplayInterval);
 }
 },

 stopAutoplay : function() {
 this._elAutoplay.className = "play";

 // TIMER
 if (this._timerId != null) {
 window.clearInterval(this._timerId);
 this._timerId = null;
 }
 },

 isAutoplayInProgress : function() {
 return this._timerId != null;
 },

 switchAutoplay : function() {
 if (this.isAutoplayInProgress()) {
 this.stopAutoplay();
 } else {
 this.startAutoplay();
 }
 },

 selNews : function(i) {
 // IF ANIMATION IN PROGRESS --> RETURN
 if (this._isInProgress) {
 return false;
 }

 // PARAMETERs CHECK
 i = $pick(i, 0);

 // IF OLD INDEX SAME AS NEW --> RETURN
 if (this._selIndex == i) {
 return false;
 }

 this._isInProgress = true;

 // OUTER TITLE UPDATE
 this._elTitle.innerHTML = $E("h2", this._bigList[i]).innerHTML;

 // SIDE LIST UPDATE
 if (this._selIndex != null) {
 this._sideList[this._selIndex].getFirst().removeClass("sel");
 }
 this._sideList[i].getFirst().addClass("sel");

 // BIG LIST UPDATE
 new Fx.Style(this._bigListContainer, "top", {duration : this.options.bigListFxDuration, transition : this.options.bigListFxTransition}).start(-450 * i).chain((function() {
 this.nav._selIndex = this.index;
 this.nav._isInProgress = false;
 }).bind({
 "nav" : this,
 "index" : i
 }));
 },

 selNextNews : function() {
 var nextIndex;

 // DETERMINE NEXT INDEX
 if (this._selIndex >= this._selCount - 1) {
 if ( (this.options.autoplayMaxLoops > 0) && ((this._currentLoop + 1) >= this.options.autoplayMaxLoops) ) {
 this.stopAutoplay();
 return;
 }
 nextIndex = 0;
 this._currentLoop++;
 } else {
 nextIndex = this._selIndex + 1;
 }

 // SELECT NEWS
 this.selNews(nextIndex);
 }
});

ObjDFcarousel.implement(new Options);
