var SL_Slider = new Class({ Implements: [Options], numNav: new Array(), timer: null, isSliding: 0, direction: 1, options: { slideTimer: 8000, orientation: 'horizontal', fade: false, isPaused: false, transitionTime: 1100, transitionType: 'cubic:out', container: null, items: null, itemNum: 0, numNavActive: false, numNavType: 'numbers', numNavHolder: null, playBtn: null, prevBtn: null, nextBtn: null }, initialize: function(options) {
    var self = this; this.setOptions(options); self.options.container.setStyle('overflow', "hidden"); if (self.options.isPaused == false) { self.options.container.addEvents({ 'mouseenter': function() { self.pauseIt(); }, 'mouseleave': function() { self.pauseIt(); } }); }
    if (self.options.playBtn != null) { self.options.playBtn.addEvents({ 'click': function() { self.pauseIt('playBtn'); }, 'mouseenter': function() { }, 'mouseleave': function() { } }); }
    if (self.options.prevBtn && self.options.nextBtn) {
        self.options.prevBtn.addEvents({ 'click': function() {
            if (self.isSliding == 0) {
                if (self.options.isPaused == false) { $clear(self.timer); self.timer = self.slideIt.periodical(self.options.slideTimer, self, null); }
                self.direction = 0; self.slideIt();
            } 
        }, 'mouseenter': function() { }, 'mouseleave': function() { } 
        }); this.options.nextBtn.addEvents({ 'click': function() {
            if (self.isSliding == 0) {
                if (self.options.isPaused == false) { $clear(self.timer); self.timer = self.slideIt.periodical(self.options.slideTimer, self, null); }
                self.direction = 1; self.slideIt();
            } 
        }, 'mouseenter': function() { }, 'mouseleave': function() { } 
        });
    }
    self.options.items.each(function(el, i) {
        el.setStyle('position', "absolute"); var itemH = el.getSize().y; var itemW = el.getSize().x; if (self.options.orientation == 'vertical') { el.setStyle('top', (-1 * itemH)); el.setStyle('left', 0); } else if (self.options.orientation == 'none') { el.setStyle('left', 0); el.setStyle('top', 0); el.set('opacity', 0); } else { el.setStyle('left', (-1 * itemW)); }
        if (self.options.numNavActive == true) { if (self.options.numNavType == 'titles' && $(el).getElement('h3') != null) { var navHeading = $(el).getElement('h3').get('html'); } else if (self.options.numNavType == 'thumbs' && $(el).getElement('img.thumb') != null) { var navHeading = '<img src="' + $(el).getElement('img.thumb').get('src') + '" />'; } else { var navHeading = (i + 1); }; var numItem = new Element('li', { id: 'num' + i }); var numLink = new Element('a', { 'class': 'numbtn', 'html': navHeading }); numItem.adopt(numLink); self.options.numNavHolder.adopt(numItem); self.numNav.push(numLink); numLink.set('morph', { duration: 100, transition: Fx.Transitions.linear, link: 'ignore' }); numLink.addEvents({ 'click': function() { self.numPress(i); } }); if (i == self.options.itemNum) { var initNum = self.numNav[i]; initNum.addClass('active'); } } 
    });
}, start: function() {
    var self = this; self.slideIt(self.options.itemNum); if (self.options.items.length > 1 && self.options.isPaused == false) { self.timer = self.slideIt.periodical(self.options.slideTimer, self, null); if (self.options.playBtn) { if (self.options.playBtn.get('text') != '') self.options.playBtn.set('text', 'Pause'); self.options.playBtn.addClass('active'); } }
    else { if (self.options.playBtn && self.options.playBtn.get('text') != '') self.options.playBtn.set('text', 'Play'); } 
}, slideIt: function(passedID) {
    var self = this; var curItem = self.options.items[self.options.itemNum]; if (self.options.numNavActive == true) { var curNumItem = self.numNav[self.options.itemNum]; }
    if (passedID != null) {
        if (self.options.itemNum != passedID) {
            if (self.options.itemNum > passedID) { self.direction = 0; } else { self.direction = 1; }
            self.options.itemNum = passedID;
        } 
    }
    else { self.changeIndex(); }
    var newItem = self.options.items[self.options.itemNum]; if (self.direction == 0) { var curX = self.options.container.getSize().x; var newX = (-1 * newItem.getSize().x); var curY = self.options.container.getSize().y; var newY = (-1 * newItem.getSize().y); }
    else { var curX = (-1 * self.options.container.getSize().x); var newX = newItem.getSize().x; var curY = (-1 * self.options.container.getSize().y); var newY = newItem.getSize().y; }
    if (self.options.numNavActive == true) { var newNumItem = self.numNav[self.options.itemNum]; newNumItem.addClass('active'); }
    var item_in = new Fx.Morph(newItem, { duration: self.options.transitionTime, transition: self.options.transitionType, link: 'ignore', onStart: function() { self.isSliding = 1; }, onComplete: function() { self.isSliding = 0; } }); if (self.options.items.length > 1) {
        if (self.options.orientation == 'vertical') {
            if (self.options.fade == true) { item_in.start({ 'opacity': [0, 1], 'top': [newY, 0] }); }
            else { item_in.start({ 'top': [newY, 0] }); } 
        } else if (self.options.orientation == 'none') { item_in.start({ 'opacity': [0, 1] }); } else {
            if (self.options.fade == true) { item_in.start({ 'opacity': [0, 1], 'left': [newX, 0] }); }
            else { item_in.start({ 'left': [newX, 0] }); } 
        }
        if (curItem != newItem) {
            var item_out = new Fx.Morph(curItem, { duration: self.options.transitionTime, transition: self.options.transitionType, link: 'ignore' }); if (self.options.numNavActive == true) { curNumItem.removeClass('active'); }
            if (self.options.orientation == 'vertical') {
                if (self.options.fade == true) { item_out.start({ 'opacity': [0], 'top': [(curY)] }); }
                else { item_out.start({ 'top': [(curY)] }); } 
            } else if (self.options.orientation == 'none') { item_out.start({ 'opacity': [1, 0] }); } else {
                if (self.options.fade == true) { item_out.start({ 'opacity': [0], 'left': [(curX)] }); }
                else { item_out.start({ 'left': [(curX)] }); } 
            } 
        } 
    }
    else { item_in.start({ 'opacity': [1, 1], 'left': [0, 0] }); };
}, pauseIt: function(pauseCaller) {
    var self = this; if (self.isSliding == 0 && self.options.items.length > 1) {
        if (self.options.isPaused == false) { self.options.isPaused = true; $clear(self.timer); if (self.options.playBtn != null) { if (self.options.playBtn.get('text') != '') self.options.playBtn.set('text', 'Play'); self.options.playBtn.removeClass('active'); } }
        else { self.options.isPaused = false; self.slideIt(); self.timer = self.slideIt.periodical(self.options.slideTimer, this, null); if (self.options.playBtn != null) { if (self.options.playBtn.get('text') != '') self.options.playBtn.set('text', 'Pause'); self.options.playBtn.addClass('active'); } } 
    }
    if (pauseCaller == 'playBtn' && self.options.isPaused == true) { self.options.container.removeEvents('mouseenter'); self.options.container.removeEvents('mouseleave'); } else { self.options.container.addEvents({ 'mouseenter': function() { self.pauseIt(); }, 'mouseleave': function() { self.pauseIt(); } }); };
}, changeIndex: function() {
    var self = this; var numItems = self.options.items.length; if (self.direction == 1) {
        if (self.options.itemNum < (numItems - 1)) { self.options.itemNum++; }
        else { self.options.itemNum = 0; } 
    }
    else if (self.direction == 0) {
        if (self.options.itemNum > 0) { self.options.itemNum--; }
        else { self.options.itemNum = (numItems - 1); } 
    } 
}, numPress: function(theIndex) {
    var self = this; if ((self.isSliding == 0) && (self.options.itemNum != theIndex)) {
        if (self.options.isPaused == false) { $clear(self.timer); self.timer = self.slideIt.periodical(self.options.slideTimer, this, null); }
        self.slideIt(theIndex);
    } 
} 
});