﻿YUI.add("gallery-slideshow-base", function (B) {
    function A(C) { A.superclass.constructor.apply(this, arguments); } A.PAUSE_TIME = 5; A.NAME = "slideshow"; A.ATTRS = { pause_time: { value: A.PAUSE_TIME, setter: function (C) { return this._set_pause_time(C); } }, auto_advance: { value: true }, slides: { value: [] }, current_slide: { value: 0, validator: function (C) { return this._validate_current_slide(C); } }, slide_count: { value: 0 }, activate_play_pause_buttons: { value: true }, play_button: { value: null }, pause_button: { value: null }, activate_next_prev_buttons: { value: true }, next_button: { value: null }, prev_button: { value: null }, activate_slide_buttons: { value: true }, slide_buttons: { value: []} }; A.AUTO_SLIDESHOW_SELECTOR = ".slideshow"; A.SLIDE_SELECTOR = ".slide"; A.CURRENT_CLASS = "current"; A.PLAY_BUTTON_SELECTOR = ".play"; A.PAUSE_BUTTON_SELECTOR = ".pause"; A.NEXT_BUTTON_SELECTOR = ".next"; A.PREV_BUTTON_SELECTOR = ".previous"; A.BUTTON_SELECTOR = ".slideSelector"; A.INACTIVE_CLASS = "inactive"; A.HTML_PARSER = { slides: function (C) { var D = C.all(A.SLIDE_SELECTOR); if (D.size() === 0) { D = C.get("children"); } return D; }, play_button: function (C) { return C.all(A.PLAY_BUTTON_SELECTOR); }, pause_button: function (C) { return C.all(A.PAUSE_BUTTON_SELECTOR); }, next_button: function (C) { return C.all(A.NEXT_BUTTON_SELECTOR); }, prev_button: function (C) { return C.all(A.PREV_BUTTON_SELECTOR); }, slide_buttons: function (C) { return C.all(A.BUTTON_SELECTOR); } }; B.extend(A, B.Widget, { initializer: function () { var C = this.get("slides"), E = C.size(), D = B.Array.indexOf(C.hasClass(A.CURRENT_CLASS), true); this.set("slide_count", E); if (D > -1) { this.set("current_slide", D); } else { C.item(0).addClass(A.CURRENT_CLASS); } C.item(this.get("current_slide")).addClass(A.CURRENT_CLASS); this.display_slide = this.get("current_slide"); this._after_display(); if (this.get("activate_play_pause_buttons")) { this._init_play_pause_buttons(); } if (this.get("activate_next_prev_buttons")) { this._init_next_prev_buttons(); } if (this.get("activate_slide_buttons")) { this._init_buttons(); } this.initial_slide = true; }, syncUI: function () { this._update_slide_display(); if (this.get("auto_advance")) { this._pause(); } }, run: function () { this.set("auto_advance", true); this.advance(); }, stop: function () { this.timer.cancel(); this.set("auto_advance", false); }, show_slide: function (C) { this.timer.cancel(); if (C != this.get("current_slide")) { this.set("current_slide", C); this.syncUI(); } }, _display_slide: function (C) { this._before_display(); this.get("slides").item(C).addClass(A.CURRENT_CLASS); this._after_display(); }, _before_display: function () { this.fire("slideshow:before-slide-displayed", { slide: this.get("slides").item(this.display_slide), slide_number: this.display_slide }); }, _after_display: function () { this.fire("slideshow:slide-displayed", { slide: this.get("slides").item(this.display_slide), slide_number: this.display_slide }); }, _hide_slide: function (C) { this._before_hide(); this.get("slides").item(C).removeClass(A.CURRENT_CLASS); this._after_hide(); }, _before_hide: function () { this.fire("slideshow:before-slide-hidden", { slide: this.get("slides").item(this.hide_slide), slide_number: this.hide_slide }); }, _after_hide: function () { this.fire("slideshow:slide-hidden", { slide: this.get("slides").item(this.hide_slide), slide_number: this.hide_slide }); }, advance: function () { this.show_slide(this._get_next_slide()); }, previous: function () { this.show_slide(this._get_previous_slide()); }, _pause: function () { this.timer = B.later(this.get("pause_time"), this, "advance"); }, _get_next_slide: function () { var C = this.get("current_slide") + 1; if (C >= this.get("slide_count")) { return 0; } else { return C; } }, _get_previous_slide: function () { var C = this.get("current_slide") - 1; if (C < 0) { return this.get("slide_count") - 1; } else { return C; } }, _update_slide_display: function () { var F = this.get("current_slide"), E = this.get("slide_count"), D = this.get("slides"), C; for (C = 0; C < E; C++) { if (C == F) { if (!D.item(C).hasClass(A.CURRENT_CLASS)) { this.display_slide = C; } } else { if (D.item(C).hasClass(A.CURRENT_CLASS)) { this.hide_slide = C; } } } if (this.initial_slide) { this.initial_slide = false; } else { if (this.display_slide >= 0) { this._display_slide(this.display_slide); } if (this.hide_slide >= 0) { this._hide_slide(this.hide_slide); } } }, _toggle_play_pause: function () { if (this.get("activate_play_pause_buttons")) { if (this.play_btn) { if (this.get("auto_advance")) { this.play_btn.addClass(A.INACTIVE_CLASS); } else { this.play_btn.removeClass(A.INACTIVE_CLASS); } } if (this.pause_btn) { if (this.get("auto_advance")) { this.pause_btn.removeClass(A.INACTIVE_CLASS); } else { this.pause_btn.addClass(A.INACTIVE_CLASS); } } } }, _init_play_pause_buttons: function () { this.play_btn = this.get("play_button"); this.pause_btn = this.get("pause_button"); this._toggle_play_pause(); if (this.play_btn) { this.play_btn.on("click", function (C) { C.preventDefault(); this.fire("slideshow:play-clicked", { slide: this.get("slides").item(this.get("current_slide")), slide_number: this.get("current_slide") }); this.run(); this._toggle_play_pause(); }, this); } if (this.pause_btn) { this.pause_btn.on("click", function (C) { C.preventDefault(); this.fire("slideshow:pause-clicked", { slide: this.get("slides").item(this.get("current_slide")), slide_number: this.get("current_slide") }); this.stop(); this._toggle_play_pause(); }, this); } }, _init_next_prev_buttons: function () { var C = this.get("next_button"), D = this.get("prev_button"); if (C) { C.on("click", function (E) { E.preventDefault(); this.stop(); this.fire("slideshow:slide-selected", { slide: this.get("slides").item(this._get_next_slide()), slide_number: this._get_next_slide() }); this.advance(); }, this); } if (D) { D.on("click", function (E) { E.preventDefault(); this.stop(); this.fire("slideshow:slide-selected", { slide: this.get("slides").item(this._get_previous_slide()), slide_number: this._get_previous_slide() }); this.previous(); }, this); } }, _init_buttons: function () {
        var E = this.get("slide_buttons"), C = E.size(), F, D; if (C > 0) {
            F = function (G, H) { G.preventDefault(); this.stop(); this.fire("slideshow:slide-selected", { slide: this.get("slides").item(H), slide_number: H }); this.show_slide(H); }; for (D = 0; D < C; D++) { E.item(D).on("click", F, this, D); if (D == this.get("current_slide")) { E.item(D).addClass("current"); } } this.on("slideshow:before-slide-displayed", function (G) {
                E.item(G.slide_number).addClass(A.CURRENT_CLASS);
            }); this.on("slideshow:before-slide-hidden", function (G) { E.item(G.slide_number).removeClass(A.CURRENT_CLASS); });
        } 
    }, _applyParsedConfig: function (E, C, D) { return (D) ? B.mix(C, D, false) : C; }, _set_pause_time: function (C) { return C * 1000; }, _validate_current_slide: function (E) { var D = 0, C = this.get("slide_count"); return (B.Lang.isNumber(E) && E >= D && E <= C); } 
    }); A.auto = function (E) { if (!E) { E = {}; } var C = E.selector || A.AUTO_SLIDESHOW_SELECTOR, D = E.pause_time || A.PAUSE_TIME; B.all(C).each(function () { var F = new A({ contentBox: this, pause_time: D }); F.render(); }); }; B.Slideshow = A;
}, "@VERSION@", { requires: ["node", "event", "widget"] });

