class Type {
	constructor(type_params) {
		this.id = type_params.id;
		this.name = type_params.name;
		this.about = type_params.about;
		this.instruction = type_params.instruction;
		this.teas = type_params.teas;
	}
}

$(function() {
	nextTypeListener(); 
	previousTypeListener()
})

function getCurrentTypeId() {
	var path =  window.location.pathname.split('/');
	return parseInt(path[path.length - 1]);
}

//next type listener
function nextTypeListener() {
    $('#js-next-type').click(function(ele) {
    	ele.preventDefault();
    	let id = getCurrentTypeId();
    	let next_id = null;
    	loadType(id, next_id);
    })

}

//previous type listener
function previousTypeListener() {}

//load type
function loadType (id, next_id) {
	$.getJSON('/types', function(data) {
		$.each(data, function( key, val ) { 
			if (val.id === id) {
				next_id = data[key + 1].id;
			}
		})
		$.getJSON('/types/' + next_id).done(function(data) {
			let next_type = new Type(data);
			let next_type_show = $(HandlebarsTemplates['types/show-type'](next_type));
			let next_type_tea = $(HandlebarsTemplates['types/show-type-tea'](next_type));
			$('#clicked-tea').empty();
			$('#js-type').html(next_type_show);
			$('#js-type-tea').html(next_type_tea);
		})
	})
}
@@ -1232,16 +1232,75 @@
 e_tea);%0A
+%09%09%09history.pushState(null, null, '/types/' + next_type.id)%0A
 %09%09%7D)%0A%09%7D)

update url after ajax load