var title;

$(function() {
	
	// Social Icons - Hover Effect
	$('img.fade').hover(function() {
		$(this).stop().animate({'opacity':'0.5'}, 'medium');
	}, function() {
		$(this).stop().animate({'opacity':'1.0'}, 'medium');
	});
	
	// Get Page & Set Title
	pages = ['home','music','movies','links','contact'];
	page = window.location.pathname.substring(1);
	if (page == '') {page = 'home';}
	if ($.inArray(page, pages) == -1) {
		page = 'home';
	}
	document.title = page.charAt(0).toUpperCase() + page.slice(1);
	
	// Activate Menu
	$('#'+page).addClass('active');
	
	// Menu Handler
	$('#menu li').click(function() {
	
		target = $(this).attr('id');
		
		$('.'+page).slideUp('slow', function() {
			
			// Update Menu
			$('#menu ul li').removeClass('active');
			$('#'+target).addClass('active');
			
			// Update Title
			page = target;
			document.title = page.charAt(0).toUpperCase() + page.slice(1);
			
			$('.content').hide();
			
			$('.'+target).slideDown('slow');
		});
		return false;
	});
});

$(function(){
	var currentTrack = 0;
	var playList = [
		{ title: "Omni", artist: "Carsten Jung", file: "mp3/omni.mp3" },
		{ title: "Carla", artist: "Carsten Jung", file: "mp3/carla.mp3" },
		{ title: "JungFunk", artist: "Carsten Jung", file: "mp3/jungfunk.mp3" },
        { title: "You Are Not Alone", artist: "Carsten Jung", file: "mp3/youarenotalone.mp3"},
        { title: "Exit", artist: "Carsten Jung", file: "mp3/exit.mp3" },
        { title: "The Soul Is Flying High", artist: "Carsten Jung", file: "mp3/thesoulisflyinghigh.mp3"}];
		
		$("#jplayer").jPlayer({
			ready: function() {				
				
				playListChange(0);
				$('#jplayer').jPlayer('stop');
				
				$('#control-play').click(function() {
					$('#jplayer').jPlayer('play');
				});
				$('#control-pause').click(function() {
					$('#jplayer').jPlayer('pause');
				});
				$('#control-stop').click(function() {
					$('#jplayer').jPlayer('stop');
				});
			},
			play: function(event) {
				$('#control-play').removeClass('active');
				$('#control-pause').removeClass('active');
				
				$('#control-play').addClass('active');
				$('#control-pause').removeClass('active');
			},
			pause: function(event) {
				$('#control-play').removeClass('active');
				$('#control-pause').removeClass('active');
				
				$('#control-play').removeClass('active');
				$('#control-pause').addClass('active');
			},
			ended: function(event) {
				$('#control-play').removeClass('active');
				$('#control-pause').removeClass('active');
				
				$('#control-play').removeClass('active');
				$('#control-pause').addClass('active');
			},
			swfPath: '/',
			supplied: 'mp3',
			wmode: 'window'
		})
		.jPlayer('onSoundComplete', playListNext);						
	 
		$(".playSong").click( function() {
			index = parseInt($(this).attr('rel'));
			playListChange(index);
			return false;
		});
		
		function playListChange(index) {
			currentTrack = index;
			$("#jplayer").jPlayer('setMedia', { mp3: playList[currentTrack].file }).jPlayer('play');				
		}
		
		function playListNext() {
			var index = (currentTrack + 1 < playList.length) ? currentTrack + 1 : 0;
			playListChange(index);
		}
		
		function playListPrev() {
			var index = (currentTrack - 1 >= 0) ? currentTrack - 1 : playList.length-1;
			playListChange(index);
		}
});
