
$(function()
	{
	var screen = 1;

	/**
	 * jPlayer events
	 */
	$('#jplayer').on($.jPlayer.event.ended,function(event)
		{
		var src = _.last(event.jPlayer.status.src.split('/'));

		if(src === 'file.mp3')
			{
			setTimeout(function()
				{
				$('#jplayer').jPlayer('setMedia', {mp3: './media/536-1.mp3'}).jPlayer('play');
				$('.next').fadeIn();
				},1000);
			}
		});

	/**
	 * Click
	 */
	$('.browse').click(function(e)
		{
		e.preventDefault();

		if($(this).hasClass('next')) ++screen;
			else --screen;

		if((screen < 1) || (screen > 5)) screen = 1;

		$('main').fadeOut(function()
			{
			$(this).attr('class','main screen'+screen).fadeIn();

			if(screen === 1) $('.prev').hide(); else $('.prev').show();
			if(screen === 5) $('.next').hide(); else $('.next').show();

			setTimeout(function()
				{
				$('#jplayer').jPlayer('setMedia', {mp3: './media/536-'+screen+'.mp3'}).jPlayer('play');
				},2000);
			});
		});
	});
