(function ($) {
    var Stroke = {
        _previous: null,
        _index: null,
        _elements: null,
        _pe: null,
        _init: function () {

            this.element.addClass('ui-stroke');

            this._elements = this.element.children();
            this._elements.each(function (i, el) {
                $(el).css('display', 'none');
            });

            if (this.autoStart() == true) {
                this.start();
            }
        },
        destroy: function () {
            this.element.removeClass();
            this._elements.css('display', 'block');
            $.widget.prototype.destroy.apply(this,arguments);
        },
        autoStart: function (b) {
            if(b===undefined){
			    return this.options.autoStart;
		    }
            if (b != true) {
                b = false;
            }
            this._setData('autoStart', b);
            return this;
        },
        delay: function (b) {
            if(b===undefined){
			    return this.options.delay;
		    }
            this._setData('delay', b);
            return this;
        },
        display: function (index) {
            if (this._previous != null) {
                this._elements.eq(this._previous).css('display', 'none');
            }
            var b = index;
            if (index === undefined) {
                b = this._index;
            }
            this._elements.eq(b).css('display', 'block');
            this._previous = b;
        },
        next: function () {
            if (this._index != null) {
                this._index++;

                if (this._index >= this._elements.length) {
                    this._index = 0;
                }
                return null;
            }
            this._index = 0;
        },
        start: function () {
            var self = this;
            this.display(0);
            this._pe = setInterval(function () { self.next(); self.display() }, this.delay());
        },
        options: {
            delay: 5000,
            autoStart: true
        }
    };

    $.widget('ui.stroke', Stroke);
    $.extend($.ui.stroke,{version:"1.7.2",defaults:{autoStart:true,delay:5000}});

})(jQuery);
