var playing = false;
var playIndex = 1;
var firstPlay = false;
function doPlay(playIndex){
	soundManager.play('song' + playIndex,{
  		onfinish: function() {
    		doNext();
  		}
	}); 					
	$("#playButton").css("background-image","url('images/btn_pause.png')");
	theTitle = "";
	switch(playIndex)
	{
		case 1:
			theTitle = song1Title;
			break;
		case 2:
			theTitle = song2Title;
			break;
		case 3:
			theTitle = song3Title;
			break;
		case 4:
			theTitle = song4Title;
			break;
		case 5:
			theTitle = song5Title;
			break;
			
	}
	$("#nowPlaying").html("Now playing: " + theTitle);
	playing = true;
}
function doNext(){
	if (playIndex == numberOfSongs){
		playIndex = 1;
	}else{
		playIndex = playIndex + 1;
	}
	doPlay(playIndex);
}
$(document).ready(function() {
	var subNav = self.document.location.hash;
	if(subNav=="#Bio"){
		$("#news").hide();
		$("#bio").show();
		$("#contact").hide();
		$("#shop").hide();					
	}
	if(subNav=="#Shop"){
		$("#news").hide();
		$("#bio").hide();
		$("#contact").hide();
		$("#shop").show();			
	}
	if(subNav=="#Contact"){
		$("#news").hide();
		$("#bio").hide();
		$("#contact").show();
		$("#shop").hide();			
	}
	$("p").each(function() {
		holder = $(this).html().replace(/ and /g, " & ");
		$(this).html(holder);
	});
	$(".logo").click(function() {
		$("#news").show();
		$("#bio").hide();
		$("#contact").hide();
		$("#shop").hide();
	});
 	$("#navBio").click(function() {
		$("#news").hide();
		$("#bio").show();
		$("#contact").hide();
		$("#shop").hide();
	});
	$("#navContact").click(function() {
		$("#news").hide();
		$("#bio").hide();
		$("#contact").show();
		$("#shop").hide();
	});
	$("#banner").click(function() {
		window.open('http://www.starz.bz/tallyhall/','ORDER','');
	});

	$("#playButton").click(function() {
			if(playing==false){
			  	if(firstPlay == false){
					firstPlay = true;
			}
				doPlay(playIndex);
			}else{
			  	soundManager.pause('song' + playIndex);	
			  	$("#playButton").css("background-image","url('images/btn_play.png')");

			  	playing = false;	
				$("#playButton").html("|| Paused.");		
			}
	});
	$("#fwdButton").click(function() {
			if(playing==false){
				if(firstPlay == false){
					firstPlay = true;
					doPlay(playIndex);
				}else{
					if (playIndex == numberOfSongs){
						playIndex = 1;
					}else{
						playIndex = playIndex + 1;
					}
					doPlay(playIndex);
				}
			}else{
			  	soundManager.stopAll();	
	  			if (playIndex == numberOfSongs){
					playIndex = 1;
				}else{
					playIndex = playIndex + 1;
				}
				doPlay(playIndex);
			}
	});
	$("#backButton").click(function() {
			if(playing==false){
				if(firstPlay == false){
					firstPlay = true;
					doPlay(playIndex);
			}else{
				if (playIndex == 1){
					playIndex = numberOfSongs;
				}else{
						playIndex = playIndex - 1;
					}
					doPlay(playIndex);
				}
			}else{
			  	soundManager.stopAll();	
			if (playIndex == 1){
				playIndex = numberOfSongs;
			}else{
					playIndex = playIndex - 1;
				}
				doPlay(playIndex);
			}
	});	
});

