jQuery(function( $ ){

	duration = 500;
	
	$content = $('#content');
	$slider = $content.find('.slider');
	$sections = $slider.find('> div');
	
	$content.css({height:$content.find('.section:first').outerHeight()});
	$slider.css({width:$sections.length * $sections.outerWidth()});
	
	
	$('ul.side-nav a').click(function() {
		$('ul.side-nav a').removeClass('selected');
		$(this).addClass('selected');
		$('#content').animate({height:$(this.hash).outerHeight()},{duration:duration,queue:false, easing:'swing'});
	});
	$('ul.side-nav a:first').click();

	
	$.localScroll.defaults.axis = 'xy';
	

	$.localScroll({
		target: '#content', // could be a selector or a jQuery object too.
		duration:duration,
		//hash:true,
		stop:false,
		easing:'swing',
		onBefore:function( e, anchor, $target ){
			// The 'this' is the settings object, can be modified
		},
		onAfter:function( anchor, settings ){
			// The 'this' contains the scrolled element (#content)
		}
	});
	
	
	$('ul.side-nav li')
	        .hover(function() {
	            $(this).stop().animate({ letterSpacing: '3px' }, 'fast');
	        }, function() {
	            $(this).stop().animate({ letterSpacing: '0px' }, 'fast');
	        });
	        
	        
	// Mp3 Player        
	$jPlayer = $('#jplayer');
	
	$jPlayer.jPlayer();
	
	$jPlayer.onProgressChange(function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
		var myPlayedTime = new Date(playedTime);
		var ptMin = myPlayedTime.getMinutes();
		var ptSec = (myPlayedTime.getSeconds() < 10) ? "0" + myPlayedTime.getSeconds() : myPlayedTime.getSeconds();
		$("#playedTime").text(ptMin + ":" + ptSec);		
	});
	
	isPlaying = false;
	
	$('.toggle-play').click(function() {
		if (isPlaying) {
			$jPlayer.pause();
			isPlaying = false;
			return false;
		}
		$jPlayer.play();
		isPlaying = true;
		return false;
	});

	$('.play-song').click(function() {
		$('.player').animate({opacity:1},'slow');
		isPlaying = true;
		
		test = ($(this).attr('title') != '') ? $('#title').text($(this).attr('title')) : $('#title').text($(this).text());
		
		//$('#title').text($(this).attr('title'));
		$jPlayer.setFile($(this).attr('href')).play();
		return false;
	});  
	 
	$jPlayer.onSoundComplete(function() {
		$('.player').animate({opacity:0},'slow');
		isPlaying = false;
	});
	
	
	   
});