
$(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/756-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 > 6)) screen = 1;

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

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

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