(function () {
    var B = YAHOO.util.Event;
    var D = YAHOO.util.Dom;
    var A = YAHOO.util.CustomEvent;
    var C = function () {
        this.init.apply(this, arguments)
    };
    C.prototype = {
        CSS_MAIN: "slider-show",
        CSS_PAGER: "slider-pager",
        CSS_PAGER_NEXT: "pager-next",
        CSS_PAGER_PREVIOUS: "pager-previous",
        CSS_PAGER_LIST: "pager-list",
        CSS_PAGER_CURRENT: "current",
        CSS_PAGER_OUT: "out",
        STRING_PAGER_NEXT: ">>",
        STRING_PAGER_PREVIOUS: "<<",
        init: function (G, E) {
            this.onItemStart = new A("onitemstart", this);
            this.onStop = new A("onstop", this);
            this.cfg = E;
            this.timer = null;
            this.index = 0;
            this.loop = false;
            this.running = false;
            this.timeStep = 3500;
            this.element = D.get(G);
            D.addClass(this.element, this.CSS_MAIN);
            var F = this.element.getElementsByTagName("ul")[0];
            D.setStyle(F, "display", "none");
            this.dataList = F.getElementsByTagName("li");
            this._genShowZone();
            this._genPager();
            this._eventReg()
        }, begin: function () {
            if (this.running) {
                return
            }
            this.loop = true;
            this.running = true;
            this.showItem()
        }, stop: function () {
            window.clearTimeout(this.timer);
            this.timer = null;
            this.loop = false;
            this.running = false;
            this.onStop.fire()
        }, showItem: function (E) {
            window.clearTimeout(this.timer);
            this.timer = null;
            if (this.anim) {
                this.anim.stop()
            }
            if (arguments.length > 0) {
                this.index = E
            }
            this.onItemStart.fire(this.index);
            D.insertBefore(this._getCurrentData(), D.getLastChild(this.showZone));
            this.anim = new YAHOO.util.Anim(D.getLastChild(this.showZone), {
                opacity: {
                    from: 1,
                    to: 0
                }
            });
            this.anim.animate();
            this.anim.onComplete.subscribe(function () {
                this.showZone.removeChild(D.getLastChild(this.showZone))
            }, null, this);
            if (this.loop) {
                this.switchPage()
            }
            this.showPager()
        }, showPager: function () {
            var E = this.pagerList.getElementsByTagName("a");
            D.removeClass(E, this.CSS_PAGER_CURRENT);
            D.addClass(E[this.index], this.CSS_PAGER_CURRENT);
            if (this.index === 0) {
                D.addClass(this.pagerPrevious, this.CSS_PAGER_OUT)
            } else {
                D.removeClass(this.pagerPrevious, this.CSS_PAGER_OUT)
            }
            if (this.index === (this.dataList.length - 1)) {
                D.addClass(this.pagerNext, this.CSS_PAGER_OUT)
            } else {
                D.removeClass(this.pagerNext, this.CSS_PAGER_OUT)
            }
        }, switchPage: function () {
            (function (E) {
                if (!E.timer) {
                    E.timer = window.setTimeout(function () {
                        E.index = E._getNextIndex();
                        E.showItem();
                        E = null
                    }, E.timeStep)
                }
            })(this)
        }, _eventReg: function () {
            B.on(this.showZone, "mouseover", function () {
                this.stop()
            }, null, this);
            B.on(this.showZone, "mouseout", function () {
                this.begin()
            }, null, this);
            B.on(this.pagerList, "click", function (E) {
                B.stopEvent(E);
                var F = B.getTarget(E);
                if (F.tagName.toLowerCase() == "a") {
                    var G = F.innerHTML;
                    this.showItem(G - 1)
                }
            }, null, this);
            B.on(this.pagerPrevious, "click", function (E) {
                B.stopEvent(E);
                this.showItem(this._getPreviousIndex())
            }, null, this);
            B.on(this.pagerNext, "click", function (E) {
                B.stopEvent(E);
                this.showItem(this._getNextIndex())
            }, null, this)
        }, _genShowZone: function () {
            this.showZone = document.createElement("ul");
            this.element.appendChild(this.showZone);
            D.setStyle(this.showZone, "position", "relative");
            D.setStyle(this.showZone, "height", this.cfg.height + "px");
            var E = this.dataList[this._getPreviousIndex()].cloneNode(true);
            D.setStyle(E, "position", "absolute");
            this.showZone.appendChild(E)
        }, _getCurrentData: function () {
            var E = this.dataList[this.index].cloneNode(true);
            D.setStyle(E, "position", "absolute");
            return E
        }, _getNextIndex: function () {
            var E = (this.index === (this.dataList.length - 1)) ? 0 : (this.index + 1);
            return E
        }, _getPreviousIndex: function () {
            var E = (this.index === 0) ? (this.dataList.length - 1) : (this.index - 1);
            return E
        }, _genPager: function () {
            var F = this.pager || document.createElement("div");
            this.pagerNext = document.createElement("span");
            var E = document.createElement("a");
            E.setAttribute("href", "#");
            E.innerHTML = this.STRING_PAGER_NEXT;
            this.pagerNext.appendChild(E);
            D.addClass(this.pagerNext, this.CSS_PAGER_NEXT);
            this.pagerPrevious = document.createElement("span");
            var J = document.createElement("a");
            J.innerHTML = this.STRING_PAGER_PREVIOUS;
            J.setAttribute("href", "#");
            this.pagerPrevious.appendChild(J);
            D.addClass(this.pagerPrevious, this.CSS_PAGER_PREVIOUS);
            this.pagerList = document.createElement("span");
            D.addClass(this.pagerList, this.CSS_PAGER_LIST);
            for (var H = 0, G = this.dataList.length; H < G; H++) {
                var I = document.createElement("a");
                I.setAttribute("href", "#");
                I.innerHTML = H + 1;
                this.pagerList.appendChild(I)
            }
            F.appendChild(this.pagerPrevious);
            F.appendChild(this.pagerList);
            F.appendChild(this.pagerNext);
            if (!this.pager) {
                this.element.appendChild(F);
                this.pager = F
            }
            D.addClass(this.pager, this.CSS_PAGER)
        }
    };
    YAHOO.namespace("touchChina");
    YAHOO.touchChina.SliderShow = C
})();
