$(function(){
		
/* TABS ======================================= */

		//Init
		var roster = $('#roster');
		var exchords = $('#exchords');
		var info = $('#about_info');
		var rosterTab = $('#roster_tab');
		var infoTab = $('#about_info_tab');
		var exchordsTab = $('#exchords_tab');
		$(info).hide();
		$(roster).hide();
		$(exchords).hide();
		
		$(rosterTab).click(function(e){
			e.preventDefault();
			$(info).hide();
			$(exchords).hide();
			$(roster).show();
			$(this).removeClass('aboutnav_off');
			$(infoTab).addClass('aboutnav_off');
			$(exchordsTab).addClass('aboutnav_off');
		});
		
		$(infoTab).click(function(e){
			e.preventDefault();
			$(info).show();
			$(roster).hide();
			$(exchords).hide();
			$(this).removeClass('aboutnav_off');
			$(rosterTab).addClass('aboutnav_off');
			$(exchordsTab).addClass('aboutnav_off');
		});
		
		$(exchordsTab).click(function(e){
			e.preventDefault();
			$(info).hide();
			$(roster).hide();
			$(exchords).show();
			$(this).removeClass('aboutnav_off');
			$(infoTab).addClass('aboutnav_off');
			$(rosterTab).addClass('aboutnav_off');
		});

// [NAVIGATION ENHANCEMENTS] ============================================================ [NAVIGATION ENHANCEMENTS]

	//BOX 1
	$('#box1').click(function(){
			window.location = './listen/';
		});
	
	//BOX 3
	$('#box3').css('cursor', 'pointer')
		.click(function(){
			window.location = './events/';
		});
		
	//Featured Fans
	$('#featured_fans').css('cursor', 'pointer').click(function(){
		window.location = './fan-page/';
	});
	
	
	
});//READY

//ONLOAD ======================================================================================================================

//Load slideshow and listen now widget images LAST to increase page content upload speed
window.onload = function(){
	
	var slidePaths = $('#slideshow span'); //read hidden, embeded image paths
	var path;
	var slideHTML;

	for (var i=0; i < slidePaths.length; i++){
		path = slidePaths.eq(i).text();
		slideHTML += '<img src="' + path + '" alt=""/>';
	}
	
	//Add Images
	$('#slideshow').html(slideHTML);
	
	/* SLIDE SHOW FUNCTIONALITY ============================= */	
	var index = 0;
	var slides = $('#slideshow img');
	
	//Instantiate
	setInterval(sift, 8000);
		
		
	//Controler
		function sift(x)
			{
				if(index<(slides.length-1)){index+=1;}
				else {index=0;}
				show(index);
			}
		
	//CORE
		function show(num)
			{
				$(slides).fadeOut(600);
				$(slides[num]).stop().fadeIn(600);
			}
	
	//Instantiate
		$(slides).hide();
		show(index);
		
/* LISTEN NOW WIDGET ==========================*/
		
		//Setup and Vars
		$('#box1').css({'cursor':'pointer', 'overflow':'hidden'});
		var albumImages = $('#box1 .boxbody img');
		var albumSpeed = 400;
		var albumShowPos = '50%';
		var albumOutPos = '-122px';
		var albumReadyPos = '275px';
		
		
		//Set default hidden right position
		albumImages.css('left', albumReadyPos);
		albumImages.eq(0).removeAttr('style');
		
		
		
		var albumIndex=0;
		var resetIndex = 0;
		
		function listenNowWidget(){

			//Remove current album
			albumImages.eq(albumIndex).animate({'left': albumOutPos}, albumSpeed);
			
			//determine next index
			if(albumIndex == (albumImages.length - 1)){ albumIndex = 0; resetIndex = albumImages.length-1;}
			else{ albumIndex += 1; resetIndex = albumIndex-1;}
			
			//animate incoming album
			albumImages.eq(albumIndex).animate({'left': albumShowPos}, albumSpeed, function(){
				
				//Reset to Ready Position after animation
				albumImages.eq(resetIndex)
				.removeAttr('style')
				.css('left', albumReadyPos);
			});

		}
		setInterval(listenNowWidget, 8000); //instantiate widget to match slideshow
		
		//Preload side2 "roadsign" image
		if(document.images){
			var preload = new Image(25,25);
			preload.src="http://xtensionchords.com/wp-content/themes/xtensionchords/images/checkussign.png";
		}
		
}; //onload


