/**
 * jquery.siv.js 0.0.1
 * Simple image viewer jQuery plugin.
 *
 * alexandre.kirillov@gmail.com
 * MIT license. http://opensource.org/licenses/MIT
 */
;(function ( $, window, document, undefined ) {
    "use strict";

    /**
     *
     * PLUGIN CORE
     *
     */
    var pluginName = "siv",
        defaults = {
            width: 0,
            height: 0,
            fadeInSpeed: 600
        };

    // constructor
    function Plugin ( element, options ) {
        this.element   = element;
        this.$element  = $(this.element);
        this.settings  = $.extend( {}, defaults, this.$element.data(), options );
        this._defaults = defaults;
        this._name     = pluginName;
        // siv
        this.zIndex = 1;
        this.imgCount = 0;
        this.currentIndex = 0;
        this.$currentElement = null;
        this.$imageList = this.$element.find('.image-list');
        this.$images  = this.$imageList.find('li');
        this.$iconNav = this.$element.find('.icon-nav');
        this.$nextBtn = this.$element.find('.next-btn');
        this.$prevBtn = this.$element.find('.prev-btn');

        this.init();
    }

    Plugin.prototype = {
        init: function() {

            var _this = this,
                $imageList = this.$imageList,
                $images  = this.$images,
                $iconNav = this.$iconNav,
                $nextBtn = this.$nextBtn,
                $prevBtn = this.$prevBtn;

            this.imgCount = $images.length;

            // Set image list width & height
            $imageList.css({
                width : this.settings.width,
                height: this.settings.height
            });

            // create icon nav
            var tmpIconsList = [];
            for (var i = 0; i < this.imgCount; i++) {
                tmpIconsList.push( "<a href='#' class='icon-btn'></a>" );
            }
            var $iconBtn = null;
            $iconNav
                .width($images.length * 20)
                .append("<div>"+ tmpIconsList.join('') +"</div>")
                .on('click', 'a', function(e){
                    e.preventDefault();
                    // update selected button
                    $iconNav.find('.selected').removeClass('selected');
                    $(this).addClass('selected');
                    // update image
                    _this.updateView( $iconBtn.index( $(this) ) );
                });
            $iconBtn = $iconNav.find('a');

            _this.$currentElement = $(_this.$images[_this.currentIndex]);
            $iconNav.find('a').eq(0).addClass('selected');
        },
        next: function(){
            this.currentIndex++;
            if (this.imgCount < this.currentIndex) {
                this.currentIndex = 0;
            }
            this.updateView( this.currentIndex );
        },
        prev: function(){
            this.currentIndex--;
            if (this.currentIndex < 0) {
                this.currentIndex = this.imgCount;
            }
            this.updateView( this.currentIndex );
        },
        updateView: function( index ){
            var _this = this;
            _this.zIndex++;

            $(this.$images[index])
                .css({
                    'z-index': _this.zIndex,
                    'opacity': 0
                })
                .stop(true,true)
                .show()
                .animate({
                    'opacity': 1
                    },
                    _this.settings.fadeInSpeed,
                    function(){
                        _this.$currentElement.hide().css('z-index', '');
                        _this.$currentElement = $(_this.$images[index]).css({'opacity': ''});
                    }
                );
        }
    };

    // A really lightweight plugin wrapper around the constructor,
    // preventing against multiple instantiations
    $.fn[ pluginName ] = function ( options ) {
        return this.each(function(i) {
            if ( ! $.data( this, "plugin_" + pluginName ) ) {
                $.data( this, "plugin_" + pluginName, new Plugin( this, options ) );
            }
        });
    };

})( jQuery, window, document );
@@ -3401,32 +3401,36 @@
                 
+    
 'opacity': 1%0A   
@@ -3426,16 +3426,16 @@
 ity': 1%0A
-
         
@@ -3521,32 +3521,74 @@
     function()%7B%0A
+                        _this.zIndex = 1;%0A
                 
@@ -3640,24 +3640,24 @@
 ndex', '');%0A
-
             
@@ -3734,16 +3734,29 @@
 ity': ''
+, 'zIndex': 1
 %7D);%0A    

refactor fadeIn z-index