'use strict';

angular
  .module('demoApp', ['ngPhotoswipe'])
  .controller('demoCtrl', demoCtrlFn);

function demoCtrlFn() {
  var vm = this;

  vm.title = 'ngPhotoswipe';

  vm.opts = {
    index: 0
  };

  vm.slides = [{
      src: 'http://lorempixel.com/500/500/nature',
      w: 500, h: 500
    }, {
      src: 'http://lorempixel.com/500/500/abstract',
      w: 500, h: 500
    }, {
      src: 'http://lorempixel.com/500/500/sports',
      w: 500, h: 500
    }, {
      src: 'http://lorempixel.com/500/500/city',
      w: 500, h: 500
    }, {
      src: 'http://lorempixel.com/500/500/food',
      w: 500, h: 500
    }, {
      src: 'http://lorempixel.com/500/500/animals',
      w: 500, h: 500
    }, {
      src: 'http://lorempixel.com/500/500/business',
      w: 500, h: 500
    }, {
      src: 'http://lorempixel.com/500/500/fashion',
      w: 500, h: 500
    }];

  vm.showGallery = function (i) {
    vm.opts.index = i || vm.opts.index;
    vm.open = true;
  };

  vm.closeGallery = function () {
    vm.open = false;
  }
}

angular.element(document).ready(function() {
  angular.bootstrap(document, ['demoApp']);
});

@@ -909,28 +909,40 @@
     
-vm.opts.index = i %7C%7C
+if(angular.isDefined(i)) %7B%0A     
  vm.
@@ -951,17 +951,27 @@
 ts.index
-;
+ = i;%0A    %7D
 %0A    vm.

Fix index opt. closes #4