// JS DOCUMENT //

var distanceMoveDown = 0;
var mainRatio = 1200/800;
var otherRatio = 1009/645;
var infoPanelOpen = 0;
var musicPanelOpen = 0;
var slideSpeed = 1500;
var spacer = 2;
var infoOffset = 0;
var coverVerticalOffset = 0;
var coverOffsetTop = 0;
var albumOpen = 0;
var playToggle = 0;

function emailForm() {
	$('input.erase').each(function() {
    $(this)
	  .data('default', $(this).val())
    .addClass('inactive')
    .focus(function() {
	    $(this).removeClass('inactive');
	    if ($(this).val() == $(this).data('default') || '') {
		    $(this).val('');
	    }
    })
    .blur(function() {
	    var default_val = $(this).data('default');
	    if ($(this).val() == '') {
		    $(this).addClass('inactive');
		    $(this).val($(this).data('default'));
	    }
    });
  });
  $('#signup').submit(function() {
    $(this).ajaxSubmit();
    $('#email').val('Thanks, Check Your Inbox!');
    return false;
  });
};

function postDetails() {
	$('#albumSelection .selection').css('text-decoration','none');
	if ($('.active').hasClass('cover01')) {
		$('.album01').css('text-decoration','underline');
		$('#mainPanel .credits01').show();
	} else if ($('.active').hasClass('cover02')) {
		$('.album02').css('text-decoration','underline');
		$('#mainPanel .credits02').show();
	} else if ($('.active').hasClass('cover03')) {
		$('.album03').css('text-decoration','underline');
		$('#mainPanel .credits03').show();
	};
	resize();
};

function coverAnimation() {
	$('#mainPanel .cover').bind({
		click: function(event){
			$('#mainPanel .cover').unbind();
			$('#albumSelection').show();
			coverVerticalOffset = '+=' + (  $(this).children('img').height() / 2  ) + 'px';
			$('#mainPanel .cover').not(this).animate({
					width: 0,
					top: coverVerticalOffset
				}, 1000, "swing",function(){$(this).hide().css('top','0');});
			$('#mainPanel .cover img').animate({
					left: 0
				}, 1000, "swing",function(){
				coverOffsetTop = $(this).offset();
				coverVerticalOffset = '-=' + ( coverOffsetTop.top - 29 ) + 'px';
				$(this).animate({
					top: coverVerticalOffset,
					width: $(window).width() / 2
				}, 1000, "swing",function(){postDetails();});
			});
			$(this).addClass('active');
			albumOpen ++;
			$('#mainPanel .cover img').css('cursor','default')
		}
	});
};

function albumSelector() {
	$('#albumSelection .selection').bind({
		click: function(event){
			$('#mainPanel #credits ul').hide();
			$('.active').removeClass('active').hide();
		
			if ($(this).hasClass('album01')) {
				$('#mainPanel .cover01').addClass('active').show();
			} else if ($(this).hasClass('album02')) {
				$('#mainPanel .cover02').addClass('active').show();
			} else if ($(this).hasClass('album03')) {
				$('#mainPanel .cover03').addClass('active').show();
			};		
			postDetails();
		}
	});
};

function slideCalc() {
	distanceMoveDown = '+=' + (  ($(window).height() - 29) - 29 - spacer  ) + 'px';
	distanceMoveUp = '-=' + (  ($(window).height() - 29) - 29 - spacer  ) + 'px';
}

function toolBarSlider() {
	$('#infoPanel .toolBack, #infoPanel .toolBar .button').bind({
		click: function(event){
			slideCalc()
			if (infoPanelOpen < 1) {
				$('#infoPanel').animate({
					top: distanceMoveDown
				}, slideSpeed, "swing",function(){infoTopAdjust();$('#infoPanel .content').fadeIn(500);});
				$('#infoPanel .switch').text('x');
				infoPanelOpen++;
			} else {			
				$('#infoPanel').animate({
					top: distanceMoveUp
				}, slideSpeed, "swing", function(){$('#infoPanel .content').hide();});
				$('#infoPanel .switch').text('+');
				infoPanelOpen--;
			};
			if (musicPanelOpen > 0) {
				$('#musicPanel').animate({
					top: distanceMoveDown
				}, slideSpeed, "swing");
				$('#musicPanel .switch').text('+');
				musicPanelOpen--;
			};
		}
	});
	$('#musicPanel .toolBack, #musicPanel .button').bind({
		click: function(event){
			slideCalc()
			if (musicPanelOpen < 1) {
				$('#musicPanel').animate({
					top: distanceMoveUp
				}, slideSpeed, "swing");
				$('#musicPanel .switch').text('x');
				musicPanelOpen++;
				
			} else {			
				$('#musicPanel').animate({
					top: distanceMoveDown
				}, slideSpeed, "swing");
				$('#musicPanel .switch').text('+');
				musicPanelOpen--;
			};
			if (infoPanelOpen > 0) {			
				$('#infoPanel').animate({
					top: distanceMoveUp
				}, slideSpeed, "swing",function(){$('#infoPanel .content').hide();});
				$('#infoPanel .switch').text('+');
				infoTopAdjust();
				infoPanelOpen--;
			};
		}
	});
};

function infoTopAdjust() {
	infoOffset = $('#infoPanel').offset();
	$('#infoPanel .content').css({top: -infoOffset.top,height: $(window).height() - 120});
};

function resize() {		

// // //     BACKGROUND SIZES     //	// //
	if(($(window).width()/$(window).height()) >= mainRatio) {
		$('#mainPanel .background .container img').css({width: $(window).width() + 20,height: ($(window).width() + 20) / mainRatio});
	} else {
		$('#mainPanel .background .container img').css({width: $(window).height() * mainRatio,height: $(window).height()});
	};	
	if(($(window).width()/$(window).height()) >= otherRatio) {
		$('#infoPanel .background .container img,#musicPanel .background .container img').css({width: $(window).width() + 20,height: ($(window).width() + 20) / otherRatio});
	} else {
		$('#infoPanel .background .container img,#musicPanel .background .container img').css({width: $(window).height() * otherRatio,height: $(window).height()});
	};
// // //     PANEL PLACEMENT     //	// //	
	if (infoPanelOpen < 1) {
		$('#infoPanel').css({top: - $('#infoPanel .background .container img').height() + 29});
		$('#infoPanel .toolBar').css({top: $('#infoPanel .background .container img').height() - 29});
	} else {
		$('#infoPanel').css({top: (($(window).height()) - ($('#infoPanel .background .container img').height() + 29 + spacer))});
		$('#infoPanel .toolBar').css({top: $('#infoPanel .background .container img').height() - 29});
		infoTopAdjust();
	}	
	$('#infoPanel .background').css({height: $('#infoPanel .background .container img').height()});
	if (musicPanelOpen < 1) {
		$('#musicPanel').css({top: $(window).height() - 29});
	} else {
		$('#musicPanel').css({top:  29 + spacer});
	}
	if (albumOpen < 1) {
		$('#mainPanel .cover img').css({top:($(window).height()-($(window).width()/3*.8))/2});
	} else {
		$('#mainPanel .cover img').css({
			top: 29,
			width:$(window).width() / 2	
		});
	};
	if ($(window).width()>750) {
		$('#playerText span:first').show();
	} else {
		$('#playerText span:first').hide();
	};
};

function playing() {
	if (playToggle > 0) {
		$('#pausePlay').text('[pause]');
		playToggle--;
	};
};

function audioPlayer() {
	$('#audio').jPlayer({
		ready: function(){
			sundayRainReprise();
		},
		swfPath: "/assets/music/player.swf",
		supplied: "mp3, oga",
		solution:"html, flash"
	});
	$('#pausePlay').click(function(){
		if (playToggle < 1) {
			$('#audio').jPlayer('pause');
			$(this).text('[play]');
			playToggle++;
		} else {
			$('#audio').jPlayer('play');
			playing();
		}
	});
// SONG CAMP I // // SONG CAMP I // // SONG CAMP I // // SONG CAMP I //
	$('.devilOnTheStreet').click(function(){devilOnTheStreet();playing();});
	$('.dontPushMeTooFar').click(function(){dontPushMeTooFar();playing();});
	$('.imGone').click(function(){imGone();playing();});
	$('.sundayRain').click(function(){sundayRain();playing();});
	$('.theLightsTurnBlue').click(function(){theLightsTurnBlue();playing();});
	$('.theWar').click(function(){theWar();playing();});
	$('.tooYoungToDie').click(function(){tooYoungToDie();playing();});
	$('.troubleInYourEyes').click(function(){troubleInYourEyes();playing();});
	$('.yesterdaysSong').click(function(){yesterdaysSong();playing();});
// SONG CAMP II // // SONG CAMP II // // SONG CAMP II // // SONG CAMP II //
	$('.anthem').click(function(){anthem();playing();});
	$('.cityLimits').click(function(){cityLimits();playing();});
	$('.lastManAlive').click(function(){lastManAlive();playing();});
	$('.oldCountryBlues').click(function(){oldCountryBlues();playing();});
	$('.starsOverNewYorkCity').click(function(){starsOverNewYorkCity();playing();});
	$('.theStorm').click(function(){theStorm();playing();});
	$('.workingForFree').click(function(){workingForFree();playing();});
	$('.youDontKnowMeAnymore').click(function(){youDontKnowMeAnymore();playing();});	
// SONG CAMP III // // SONG CAMP III // // SONG CAMP III // // SONG CAMP III //
	$('.ridingBlind').click(function(){ridingBlind();playing();});
	$('.sundayRainReprise').click(function(){sundayRainReprise();playing();});
	$('.theUnknowns').click(function(){theUnknowns();playing();});
	$('.whenTheSunsAboutToRise').click(function(){whenTheSunsAboutToRise();playing();});
};

// SONGS // SONGS // SONGS // SONGS // SONGS // SONGS // SONGS // SONGS //
/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/

function sundayRain() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/1/sundayRain.mp3",
			oga: "/assets/music/1/sundayRain.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		dontPushMeTooFar();
	});
	$('#album').text('I.');
	$('#song').text('Sunday Rain');
	$('.current').removeClass('current');
	$('.sundayRain').addClass('current');
};

function dontPushMeTooFar() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/1/dontPushMeTooFar.mp3",
			oga: "/assets/music/1/dontPushMeTooFar.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		troubleInYourEyes();
	});
	$('#album').text('I.');
	$('#song').text("Don't Push Me Too Far");
	$('.current').removeClass('current');
	$('.dontPushMeTooFar').addClass('current');
};

function troubleInYourEyes() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/1/troubleInYourEyes.mp3",
			oga: "/assets/music/1/troubleInYourEyes.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		yesterdaysSong();
	});
	$('#album').text('I.');
	$('#song').text('Trouble In Your Eyes');
	$('.current').removeClass('current');
	$('.troubleInYourEyes').addClass('current');
};

function yesterdaysSong() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/1/yesterdaysSong.mp3",
			oga: "/assets/music/1/yesterdaysSong.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		devilOnTheStreet();
	});
	$('#album').text('I.');
	$('#song').text("Yesterday's Song");
	$('.current').removeClass('current');
	$('.yesterdaysSong').addClass('current');
};

function devilOnTheStreet() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
		mp3: "/assets/music/1/devilOnTheStreet.mp3",
		oga: "/assets/music/1/devilOnTheStreet.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		imGone();
	});
	$('#album').text('I.');
	$('#song').text('Devil On The Street');
	$('.current').removeClass('current');
	$('.devilOnTheStreet').addClass('current');
};

function imGone() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/1/imGone.mp3",
			oga: "/assets/music/1/imGone.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		tooYoungToDie();
	});
	$('#album').text('I.');
	$('#song').text("I'm Gone");
	$('.current').removeClass('current');
	$('.imGone').addClass('current');
};

function tooYoungToDie() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/1/tooYoungToDie.mp3",
			oga: "/assets/music/1/tooYoungToDie.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		theWar();
	});
	$('#album').text('I.');
	$('#song').text('Too Young To Die');
	$('.current').removeClass('current');
	$('.tooYoungToDie').addClass('current');
};

function theWar() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/1/theWar.mp3",
			oga: "/assets/music/1/theWar.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		theLightsTurnBlue();
	});
	$('#album').text('I.');
	$('#song').text('The War');
	$('.current').removeClass('current');
	$('.theWar').addClass('current');
};

function theLightsTurnBlue() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/1/theLightsTurnBlue.mp3",
			oga: "/assets/music/1/theLightsTurnBlue.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		sundayRain();
	});
	$('#album').text('I.');
	$('#song').text("The Lights Turn Blue");
	$('.current').removeClass('current');
	$('.theLightsTurnBlue').addClass('current');
};

function workingForFree() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/2/workingForFree.mp3",
			oga: "/assets/music/2/workingForFree.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		theStorm();
	});
	$('#album').text('II.');
	$('#song').text("Working For Free");
	$('.current').removeClass('current');
	$('.workingForFree').addClass('current');
};

function theStorm() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/2/theStorm.mp3",
			oga: "/assets/music/2/theStorm.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		oldCountryBlues();
	});
	$('#album').text('II.');
	$('#song').text("The Storm");
	$('.current').removeClass('current');
	$('.theStorm').addClass('current');
};

function oldCountryBlues() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/2/oldCountryBlues.mp3",
			oga: "/assets/music/2/oldCountryBlues.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		lastManAlive();
	});
	$('#album').text('II.');
	$('#song').text("Old Country Blues");
	$('.current').removeClass('current');
	$('.oldCountryBlues').addClass('current');
};

function lastManAlive() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/2/lastManAlive.mp3",
			oga: "/assets/music/2/lastManAlive.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		starsOverNewYorkCity();
	});
	$('#album').text('II.');
	$('#song').text("Last Man Alive");
	$('.current').removeClass('current');
	$('.lastManAlive').addClass('current');
};

function starsOverNewYorkCity() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/2/starsOverNewYorkCity.mp3",
			oga: "/assets/music/2/starsOverNewYorkCity.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		youDontKnowMeAnymore();
	});
	$('#album').text('II.');
	$('#song').text("Stars Over New York City");
	$('.current').removeClass('current');
	$('.starsOverNewYorkCity').addClass('current');
};

function youDontKnowMeAnymore() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/2/youDontKnowMeAnymore.mp3",
			oga: "/assets/music/2/youDontKnowMeAnymore.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		cityLimits();
	});
	$('#album').text('II.');
	$('#song').text("You Don't Know Me Anymore");
	$('.current').removeClass('current');
	$('.youDontKnowMeAnymore').addClass('current');
};

function cityLimits() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/2/cityLimits.mp3",
			oga: "/assets/music/2/cityLimits.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		anthem();
	});
	$('#album').text('II.');
	$('#song').text("City Limits");
	$('.current').removeClass('current');
	$('.cityLimits').addClass('current');
};

function anthem() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/2/anthem.mp3",
			oga: "/assets/music/2/anthem.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		workingForFree();
	});
	$('#album').text('II.');
	$('#song').text("Anthem");
	$('.current').removeClass('current');
	$('.anthem').addClass('current');
};

function ridingBlind() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/3/ridingBlind.mp3",
			oga: "/assets/music/3/ridingBlind.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		whenTheSunsAboutToRise();
	});
	$('#album').text('III.');
	$('#song').text("Riding Blind");
	$('.current').removeClass('current');
	$('.ridingBlind').addClass('current');
};

function whenTheSunsAboutToRise() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/3/whenTheSunsAboutToRise.mp3",
			oga: "/assets/music/3/whenTheSunsAboutToRise.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		theUnknowns();
	});
	$('#album').text('III.');
	$('#song').text("When The Sun's About To Rise");
	$('.current').removeClass('current');
	$('.whenTheSunsAboutToRise').addClass('current');
};

function theUnknowns() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/3/theUnknowns.mp3",
			oga: "/assets/music/3/theUnknowns.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		sundayRainReprise();
	});
	$('#album').text('III.');
	$('#song').text("The Unknowns");
	$('.current').removeClass('current');
	$('.theUnknowns').addClass('current');
};

function sundayRainReprise() {
	$('#audio').jPlayer('pause').jPlayer("setMedia", {
			mp3: "/assets/music/3/sundayRainReprise.mp3",
			oga: "/assets/music/3/sundayRainReprise.ogv"
	}).jPlayer('play').unbind($.jPlayer.event.ended + ".cue-next").bind($.jPlayer.event.ended + ".cue-next", function(event) {
		ridingBlind();
	});
	$('#album').text('III.');
	$('#song').text("Sunday Rain Reprise");
	$('.current').removeClass('current');
	$('.sundayRainReprise').addClass('current');
};

/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
// SONGS // SONGS // SONGS // SONGS // SONGS // SONGS // SONGS // SONGS //

$(document).ready(
	function(event) {
		emailForm();
		audioPlayer();
		albumSelector();
		coverAnimation();
		toolBarSlider();
		resize();
		$(window).resize(function(event){resize();});
	}
);
