module.exports = {
	pathOrder: ['/', '/process', '/services', '/markets', '/about', '/contact'],
	notVisibleOn: ['/services/entertainment', '/services/security', '/services/integration'],
	lastPath: '/',
	events:
	{
		"click .next": "next",
		"click .prev": "prev"
	},
	initialize: function(options)
	{
		this.listenTo(this.app.router, 'route', this.onRouteChange);

		//Listen to keys
		var thisView = this;
		$("body").keydown(function(e) {

		  if(e.keyCode == 37 && thisView.notVisibleOn.indexOf(window.location.pathname) == -1) { // left
		    thisView.prev()
		  }
		  else if(e.keyCode == 39 && thisView.notVisibleOn.indexOf(window.location.pathname) == -1) { // right
		    thisView.next()
		  }
		});


	},
	attach: function()
	{
		this.onRouteChange(null, [window.location.pathname.slice(1)])
		$(window).on( 'scroll', function(e)
		{
		    if($(window).scrollTop() > 100)
		    {
		    	$('.prev, .next').addClass('hidden')
		    	$('.up-button').addClass('unhidden')
		    }
		    else
		    {
		    	$('.prev, .next').removeClass('hidden')
		    	$('.up-button').removeClass('unhidden')
		    }
		});
	},
	onRouteChange: function(route, params)
	{
		var path = "/" + (params[0] || "");

		if(this.notVisibleOn.indexOf(path) != -1) //If this is a subpage to services
			this.$el.hide()
		else
			this.$el.show()

		console.log(this.lastPath)

		//Valet shit
		if((this.notVisibleOn.indexOf(path) != -1 || path == '/services') && (this.notVisibleOn.indexOf(this.lastPath) != -1 || this.lastPath == '/services' || this.lastPath == '/'))
		{
			$(document.body).removeClass('anim-fade anim-neg anim-pos')
			$(document.body).addClass('anim-fade')
		}
		else
		{
			if(this.notVisibleOn.indexOf(path) != -1)
			{
				path = '/services'
			}
			else if(this.notVisibleOn.indexOf(this.lastPath) != -1)
			{
				this.lastPath = '/services'
			}

			if(this.pathOrder.indexOf(path) < this.pathOrder.indexOf(this.lastPath))
			{
				$(document.body).removeClass('anim-fade anim-neg anim-pos')
				$(document.body).addClass('anim-neg')
			}
			else
			{
				$(document.body).removeClass('anim-fade anim-neg anim-pos')
				$(document.body).addClass('anim-pos')
			}
		}
		this.lastPath = path;
	},
	prev: function()
	{
		var path = this.pathOrder[(this.pathOrder.indexOf(window.location.pathname) + this.pathOrder.length - 1) % this.pathOrder.length];
		Backbone.history.navigate(path, {trigger: true})
	},
	next: function()
	{
		var path = this.pathOrder[(this.pathOrder.indexOf(window.location.pathname) + 1) % this.pathOrder.length];
		Backbone.history.navigate(path, {trigger: true})
	}
}