var controller;

$(document).ready(function($) {

  // NAVIGATION ACTIVE CLASSES
  // init controller
  var controller = new ScrollMagic({globalSceneOptions: {duration: 500}});

  // build scenes
  new ScrollScene({triggerElement: "#about"})
          .setClassToggle(".btn--link_about", "active") // add class toggle
          .addTo(controller)
  new ScrollScene({triggerElement: "#shows"})
          .setClassToggle(".btn--link_shows", "active") // add class toggle
          .addTo(controller)
  new ScrollScene({triggerElement: "#videos"})
          .setClassToggle(".btn--link_videos", "active") // add class toggle
          .addTo(controller)
  new ScrollScene({triggerElement: "#photos"})
          .setClassToggle(".btn--link_photos", "active") // add class toggle
          .addTo(controller)



  // NAVIGATION SCROLLING
	// change behaviour of controller to animate scroll instead of jump
	controller.scrollTo(function (newpos) {
		TweenMax.to(window, 0.5, {scrollTo: {y: newpos}});
	});

	//  bind scroll to anchor links
	$(document).on("click", "a[href^=#]", function (e) {
		var id = $(this).attr("href");
		if ($(id).length > 0) {
			e.preventDefault();

			// trigger scroll
			controller.scrollTo(id);

				// if supported by the browser we can even update the URL.
			if (window.history && window.history.pushState) {
				history.pushState("", document.title, id);
			}
		}
	});
});
