$(document).ready(function()
{
	//menu
	slide("#sliding-navigation", 15, 0, 200, 200, .8, 300);
	

	//slideshow
	$('.slideshow').cycle({ 
	    fx:     'scrollDown', 
	    easing: 'swing',
	    speed:  1200,
	    timeout:  8000
	});

	/* Select gear */
	$(".subNavGearMicrophones").hover(function() {
		//hide
		$('#outboard, #intruments').fadeOut('fast');
		
		//show
		$('#microphones').fadeIn('fast');
		
		//remove class
		$(".subNavGearOutboard, .subNavGearInstruments").removeClass("over");
		//add class
		$(".subNavGearMicrophones").addClass("over");
	});
	$(".subNavGearOutboard").hover(function() {
		//fadeOut
		$('#microphones, #intruments').fadeOut('fast');
		
		//show
		$('#outboard').fadeIn('fast');
		
		//remove class
		$(".subNavGearMicrophones").removeClass("over");
		$(".subNavGearInstruments").removeClass("over");
		//add class
		$(".subNavGearOutboard").addClass("over");
	});
	$(".subNavGearInstruments").hover(function() {
		//fadeOut
		$('#outboard, #microphones').fadeOut('fast');
		
		//fadeIn
		$('#intruments').fadeIn('fast');
		
		
		//remove class
		$(".subNavGearOutboard").removeClass("over");
		$(".subNavGearMicrophones").removeClass("over");
		//add class
		$(".subNavGearInstruments").addClass("over");
	});
	
	//gear sidebar
	var scrollSidebar = ".gearList";
	if ($(scrollSidebar)){
		var offset = $(scrollSidebar).offset();
		var topPadding = 15;
		$(window).scroll(function() {
				if ($(window).scrollTop() > offset.top) {
					$(scrollSidebar).stop().animate({
						marginTop: $(window).scrollTop() - offset.top + topPadding
					});
				} else {
					$(scrollSidebar).stop().animate({
					marginTop: 0
				});
			};
		});
	}
	
	//music player
	/*
		<li>Love in October - Soft Errors</li>
		<li>The Yearbooks - Stranger of the Night</li>
		<li>Love in October - Dance Johannes Kepler</li>
		<li>Love in October - Like Nothing Ever Happened</li>
		<li>Calvin Marty - Without You (unmastered)</li>
		<li>Enlou - Nineteen ninety-five (unmastered)</li>
	*/
	if ($("#jquery_jplayer").length != 0){
		
		var playItem = 0;
		
		var myPlayList = [
		{name:"Love in October - Don't Forget",mp3:"mp3/Don't Forget Sample.mp3"},
		{name:"Love in October - The Night",mp3:"mp3/The Night Sample.mp3"},
		{name:"Love in October - Paper Heart",mp3:"mp3/Paper Heart Sample.mp3"},
		{name:"The Yearbooks - Stranger of the Night",mp3:"mp3/Stranger of the Night.mp3"},
		{name:"Calvin Marty - Without You (unmastered)",mp3:"mp3/Without You.mp3"},
		//{name:"Enlou - Nineteen ninety-five (unmastered)",mp3:"mp3/1995 - Mix 2.mp3"},
		];
		
		// Local copy of jQuery selectors, for performance.
		var jpPlayTime = $("#jplayer_play_time");
		var jpTotalTime = $("#jplayer_total_time");
		var jpStatus = $("#demo_status"); // For displaying information about jPlayer's status in the demo page
		
		
		$("#jquery_jplayer").jPlayer({
			ready: function() {
				displayPlayList();
				playListInit(true); // Parameter is a boolean for autoplay.
			},
			oggSupport: false
		})
		.jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
			jpPlayTime.text($.jPlayer.convertTime(playedTime));
			jpTotalTime.text($.jPlayer.convertTime(totalTime));
		
		})
		.jPlayer("onSoundComplete", function() {
			playListNext();
		});
		
		$("#jplayer_previous").click( function() {
			playListPrev();
			$(this).blur();
			return false;
		});
		
		$("#jplayer_next").click( function() {
			playListNext();
			$(this).blur();
			return false;
		});
		
		function displayPlayList() {
			$("#jplayer_playlist ul").empty();
			for (i=0; i < myPlayList.length; i++) {
				var listItem = (i == myPlayList.length-1) ? "<li class='jplayer_playlist_item_last'>" : "<li>";
				listItem += "<a href='#' id='jplayer_playlist_item_"+i+"' tabindex='1'>"+ myPlayList[i].name +"</a></li>";
				$("#jplayer_playlist ul").append(listItem);
				$("#jplayer_playlist_item_"+i).data( "index", i ).click( function() {
					var index = $(this).data("index");
					if (playItem != index) {
						playListChange( index );
					} else {
						$("#jquery_jplayer").jPlayer("play");
					}
					$(this).blur();
					return false;
				});
			}
		}
		
		function playListInit(autoplay) {
			if(autoplay) {
				playListChange( playItem );
			} else {
				playListConfig( playItem );
			}
		}
		
		function playListConfig( index ) {
			$("#jplayer_playlist_item_"+playItem).removeClass("jplayer_playlist_current").parent().removeClass("jplayer_playlist_current");
			$("#jplayer_playlist_item_"+index).addClass("jplayer_playlist_current").parent().addClass("jplayer_playlist_current");
			playItem = index;
			$("#jquery_jplayer").jPlayer("setFile", myPlayList[playItem].mp3, myPlayList[playItem].ogg);
		}
		
		function playListChange( index ) {
			playListConfig( index );
			$("#jquery_jplayer").jPlayer("play");
		}
		
		function playListNext() {
			var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
			playListChange( index );
		}
		
		function playListPrev() {
			var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1;
			playListChange( index );
		}
	}
	
});
