$(function(){

	speed = 350;

	$('#links a').each(function(){
		var id = $('#links a').index(this);
		$(this).attr('href', '#'+ id);
	});

	$('.slider dd').each(function(){
		var name = $('.slider dd').index(this);
		$(this).attr('id', name).prepend('<a name="'+ name +'"></a>');
	});

	$('#links a').each(function(){
		$(this).click(function(){
			$('.slider dd')
				.find('.name')
				.removeClass('opened')
				.next('.more')
				.removeClass('mopened')
				.hide();

			var id = $('#links a').index(this);

			$('html, body').animate({
				scrollTop: $('.slider dd#'+ id).offset().top
			}, speed);

			$('.slider dd#'+ id)
				.find('.name')
				.addClass('opened')
				.next('.more')
				.addClass('mopened')
				.show();
		});
	});

	$('.slider .name').click(function(){
		if ($(this).hasClass('opened')) {
			$(this)
				.removeClass('opened')
				.next('.more')
				.slideUp(speed, function(){
					$(this).removeClass('mopened');
				});
		} else {
			var id = $('.slider .name').index(this);

			$('html, body').animate({
				scrollTop: $('.slider dd#'+ id).offset().top
			}, speed);

			$(this)
				.addClass('opened')
				.next('.more')
				.slideDown(speed, function(){
					$(this).addClass('mopened');
				});
		};
	});

});
