/* Downloaded from http://www.fubiz.net/ - Packaged by answeb - http://www.answeb.net/ */
var clrzSlider = new Class({
    Implements: [Options, Events],
    options: {
        perpage: 1,
        setpage: 0,
        containerwidth: 0,
        container: "slide_container",
        items: "#contentslider div.item",
        contentslider: "contentslider",
        btnnext: "div.carouselbar_content .next a",
        btnprev: "div.carouselbar_content .previous a",
        layout: "horizontal",
        transition: Fx.Transitions.Quint.easeInOut,
        windowscroll: 1,
        autostart: true,
        duration: 2000,
        marge: 0
    },
	direction: 1,	// Or -1
    initialize: function (c) {
        this.setOptions(c);
        this.wscroll = new Fx.Scroll(window);
        if (!$(this.options.container)) {
            return
        }
        if (this.options.layout == "horizontal") {
            this.prop = "width";
            this.moove = "margin-left"
        } else {
            this.prop = "height";
            this.moove = "margin-top"
        }
        this.ulwidth = 0;
        this.items = $$(this.options.items);
        this.container = $(this.options.container);
        this.contentslider = $(this.options.contentslider);
        this.is_under = 0;
        this.ulid = [];
        this.fxlist = new Fx.Morph(this.contentslider, {
            duration: this.options.duration,
            transition: this.options.transition,
            wait: false
        });
        var a = this;
        this.items.each(function (f, e) {
            if (a.options.layout == "horizontal") {
                a.ulwidth = a.ulwidth + f.getWidth() + a.options.marge
            } else {
                a.ulwidth = a.ulwidth + f.getHeight() + a.options.marge
            }
            a.ulid[e] = f.getProperty("id")
        });
        this.itemwidth = (this.ulwidth / this.items.length);
        var b;
        if (this.options.containerwidth) {
            b = this.options.containerwidth
        } else {
            b = this.itemwidth * this.options.perpage
        }
        var d = {};
        d[this.prop] = b;
        d.overflow = "hidden";
        this.container.setStyles(d);
        this.containerwidth = (this.itemwidth * this.options.perpage);
        this.contentslider.setStyle(this.prop, this.containerwidth);
        this.maxpage = Math.ceil(this.items.length / this.options.perpage) - 1;
        this.contentslider.setStyle(this.prop, (this.ulwidth));
        this.initevents();
        this.fireEvent("initialize");
        this.zgoto(0);
        if (this.options.autostart) {
            this.start()
        }
    },
    initevents: function () {
        var a = this;
        this.container.addEvents({
            mouseenter: function () {
                a.is_under = 1;
                a.fireEvent("over")
            },
            mouseleave: function () {
                a.is_under = 0;
                a.fireEvent("leave")
            }
        });
        $$(this.options.btnnext).addEvent("click", function (b) {
            new Event(b).stop();
            a.scrollmenext()
        });
        $$(this.options.btnprev).addEvent("click", function (b) {
            new Event(b).stop();
            a.scrollmeprev()
        })
    },
    scrollmenext: function () {
		if (this.direction > 0) {
			if (this.setpage >= this.maxpage) {
				this.direction = -1;
				this.setpage--
			} else {
				this.setpage = this.setpage + 1
			}
		} else {
			if (this.setpage <= 0) {
				this.direction = 1;
				this.setpage++
			} else {
				this.setpage = this.setpage - 1
			}
		}
        this.zgoto();
        if (this.windowscroll == 1) {
            this.wscroll.toElement(this.container)
        }
    },
    scrollmeprev: function () {
        if (this.setpage <= 0) {
            this.setpage = this.maxpage
        } else {
            this.setpage = this.setpage - 1
        }
        this.zgoto();
        if (this.windowscroll == 1) {
            this.wscroll.toElement(this.container)
        }
    },
    zgoto: function (b) {
        var a = this;
        if ($chk(b)) {
            this.setpage = b
        }
        var c = {};
        c[this.moove] = -(this.setpage * this.containerwidth);
        this.fxlist.start(c).chain(function () {
            a.fireEvent("gotocomplete")
        });
        this.fireEvent("zgoto")
    },
    loadactivepage: function (a) {
        $(a).addClass("current");
        this.setpage = Math.floor(ulid.indexOf(a) / perpage);
        this.zgoto()
    },
    autostart: function () {
        if (!this.is_under) {
            this.scrollmenext()
        }
    },
    start: function () {
        this.autostart.periodical(8000, this)
    }
});
