'use strict';

module.exports = function (deck/*, options*/) {
	var update, activeIndex, activateSlide, options = Object(arguments[1])
	  , root = options.root || '/';

	activateSlide = function (index) {
		if (index !== activeIndex) deck.slide(index);
	};

	update = function () {
		var id = location.pathname.slice(root.length, -1);

		if (!id) return;
		if (isNaN(id)) {
			deck.slides.forEach(function (slide, i) {
				if (slide.getAttribute('data-bespoke-id') === id) activateSlide(i);
			});
			return;
		}
		activateSlide(Number(id));
	};

	setTimeout(function () {
		update();

		var first = deck.slides[0].getAttribute('data-bespoke-id') || '1';
		deck.on('activate', function (e) {
			var slideName = e.slide.getAttribute('data-bespoke-id') ||
				String(e.index + 1);
			history.pushState({}, '', root +
				((slideName === first) ? '' : (slideName + '/')));
			activeIndex = e.index;
		});

		window.addEventListener('popstate', update);
	}, 0);
};

@@ -72,21 +72,8 @@
 ate,
- activeIndex,
  act
@@ -201,25 +201,36 @@
 dex 
-!== activeIndex) 
+=== deck.slide()) return;%0A%09%09
 deck
@@ -265,24 +265,25 @@
 = function (
+e
 ) %7B%0A%09%09var id
@@ -577,17 +577,16 @@
 date();%0A
-%0A
 %09%09var fi
@@ -865,34 +865,8 @@
 ));%0A
-%09%09%09activeIndex = e.index;%0A
 %09%09%7D)

Do not invoke `slide` if given slide is active