/* Efecto "panel con Slide" es original de Apple.com, modificado y adaptado por Fabbianz.com */

if (typeof(AC) == "undefined") {
    AC = {}
}
AC.Bureau = Class.create();
Object.extend(AC.Bureau.prototype, Event.Listener);
Object.extend(AC.Bureau.prototype, {
    Panels: null,
    container: null,
    triggerTimeout: null,
    initialize: function(A) {
        this.Panels = [];
        this.container = $(A)
    },
    addPanel: function(A) {},
    getPanelCount: function() {
        return this.Panels.length
    },
    hasPanels: function() {
        return (this.Panels.length > 0)
    },
    getFirstPanel: function() {
        return this.Panels[0] || null
    },
    getLastPanel: function() {
        return this.Panels[this.Panels.length - 1] || null
    },
    scheduleTrigger: function(B, A) {
        this.triggerTimeout = setTimeout(B, A)
    },
    clearTrigger: function() {
        clearTimeout(this.triggerTimeout)
    }
});
AC.Panel = Class.create();
Object.extend(AC.Panel.prototype, Event.Publisher);
Object.extend(AC.Panel.prototype, {
    bureau: null,
    contentElement: null,
    manejo: null,
    indicator: null,
    isOpen: true,
    beforeOpen: null,
    afterOpen: null,
    beforeClose: null,
    afterClose: null,
    transitionDuration: 0.3,
    triggerDelay: 0,
    initialize: function(F, D, B, C) {
        this.contentElement = $(F);
        this.manejo = $(D);
        this.bureau = B;
        var E = "click";
        if (C !== null && typeof(C) != "undefined") {
            this.beforeOpen = C.beforeOpen;
            this.afterOpen = C.afterOpen;
            this.beforeClose = C.beforeClose;
            this.afterClose = C.afterClose;
            if (typeof(C.triggerEvent) != "undefined") {
                E = C.triggerEvent
            }
            if (typeof(C.triggerDelay) != "undefined") {
                this.triggerDelay = C.triggerDelay
            }
            if (typeof(C.transitionDuration) != "undefined") {
                this.transitionDuration = C.transitionDuration
            }
        }

        Element.addClassName(this.contentElement, "last");
        var A = function(G) {

            Event.stop(G);
            if (this.triggerDelay > 0) {
                var H = this.trigger.bind(this);
                B.scheduleTrigger(H, this.triggerDelay)
            } else {
                this.trigger()
            }
        };
        Event.observe(this.manejo, E, A.bind(this), false);
        Event.observe(this.manejo, "mouseout", B.clearTrigger.bind(B), false)
    },
    toggle: function() {},
    open: function() {},
    close: function() {}
});


AC.ShingleBureau = Class.create();
Object.extend(Object.extend(AC.ShingleBureau.prototype, AC.Bureau.prototype), {
    PanelDuration: 0.5,
    addPanel: function(B) {
        if (this.hasPanels()) {
            var A = this.getLastPanel();
            A.setNextPanel(B);
            B.setPreviousPanel(A);
            B.closedOffset = A.closedOffset + A.getmanejoHeight() - 10
        } else {
            Element.addClassName(B.contentElement, "first");
            B.closedOffset = 0 - B.getHeight() + B.getmanejoHeight() - 10;
            B.indicateVisible()
        }
        this.Panels.push(B)
    },
    getWidth: function() {
        return Element.getWidth(this.container)
    },
    getHeight: function() {
        return Element.getHeight(this.container)
    },
    movePanel: function(C, A, D) {
        var B = new Effect.Move(C, {
            x: A,
            y: D,
            mode: "absolute",
            transition: Effect.Transitions.sinoidal,
            duration: this.PanelDuration
        })
    }
});
AC.ShinglePanel = Class.create();
Object.extend(Object.extend(AC.ShinglePanel.prototype, AC.Panel.prototype), {
    openedOffset: 0,
    closedOffset: 0,
    previousPanel: null,
    nextPanel: null,
    isVisible: false,
    trigger: function() {
        if (!this.isVisible) {
            this.open(true);
            this.indicateVisible()
        }
    },
    toggle: function() {
        if (!this.isOpen) {
            this.open();
            this.indicateVisible()
        } else {
            this.close()
        }
    },
    open: function(A) {
        if (this.isOpen && !A) {
            return
        }
        if (this.previousPanel !== null) {
            this.previousPanel.close();
            this.previousPanel.indicateoscuro()
        }
        if (this.nextPanel !== null) {
            this.nextPanel.open();
            this.nextPanel.indicateoscuro()
        }
        this.indicateVisible();
        this.isOpen = true;
        this.bureau.movePanel(this.contentElement, 0, this.openedOffset)
    },
    close: function(A) {
        if (!this.isOpen) {
            return
        }
        if (this == this.bureau.getLastPanel()) {
            return
        }
        if (this.previousPanel !== null) {
            this.previousPanel.close()
        }
        this.bureau.movePanel(this.contentElement, 0, this.closedOffset);
        this.indicateoscuro();
        this.isOpen = false
    },
    setPreviousPanel: function(A) {
        this.previousPanel = A;
        this.indicateoscuro();
        this.openedOffset = this.previousPanel.openedOffset + this.previousPanel.getmanejoHeight() - 10;
        Element.setStyle(this.contentElement, {
            top: this.openedOffset + "px"
        })
    },
    setNextPanel: function(A) {
        this.nextPanel = A;
        Element.removeClassName(this.contentElement, "last");
        if (this.previousPanel !== null) {
            this.previousPanel.setNextPanel(this)
        }
        zIndex = parseInt(Element.getStyle(this.contentElement, "zIndex"), 10);
        Element.setStyle(this.contentElement, {
            "zIndex": zIndex + 1
        })
    },
    indicateoscuro: function() {
        Element.addClassName(this.contentElement, "oscuro");
        this.isVisible = false
    },
    indicateVisible: function() {
        this.isVisible = true;
        Element.removeClassName(this.contentElement, "oscuro")
    },
    getmanejoWidth: function() {
        return Element.getWidth(this.manejo)
    },
    getmanejoHeight: function() {
        return Element.getHeight(this.manejo)
    },
    getWidth: function() {
        return Element.getWidth(this.contentElement)
    },
    getHeight: function() {
        return Element.getHeight(this.contentElement)
    }
})

		var fabbianzbarra = null;
		Event.observe(window, 'load', function() {
			fabbianzbarra = new AC.ShingleBureau('fabbianz-barra');
			var challenges = $('fabbianz-barra').getElementsByTagName('li');
			for (var i = 0; i < challenges.length; i++) {
				var manejo = Element.getElementsByClassName(challenges[i], 'manejo')[0];
				var Panel = new AC.ShinglePanel(challenges[i], manejo, fabbianzbarra, {
					triggerEvent: 'mouseover',
					triggerDelay: 50});
				fabbianzbarra.addPanel(Panel);
			}
		}, false);
