$(document).ready(function () {
checkURL();	//check if the URL has a reference to a page and load it
	setInterval("checkURL()",250);	//check for a change in the URL every 250 ms to detect if the history buttons have been used
	var current;
	
		$('a.scroll').click(function(e){
		var title = $(this).attr('title');
		clicker(title);
		});

	function clicker(title){
		//var title = $(this).attr('title');
		if(title == 'photos'){
			setTimeout(function() { 	
				$.get("./flickr/flickr.php", function(data){
 					 $('#photos').html(data);
				});
			 }, 2000);
		}
		if(current == title){
			$("ul li a[title='"+current+"']").removeClass('current');
			$('#'+current).toggle('slow');
			current = "none";
			animate('about');
			return false;
		}
		if(current != title){		
			$('#'+ title).toggle('slow');
			$("ul li a[title='"+title+"']").addClass('current');
			$("ul li a[title='"+current+"']").removeClass('current');
			$('#'+current).toggle('slow');
			current = title;			
		}
		animate(title);
		return false;
	}
	
	function animate(div){
		var aboutX = -10;
		var photosX = 248;
		var videoX = 418;
		var wordsX = 793;
		var showsX = 965;
		var contactX = 1050;
		var downloadsX = 645;
		
		if(div == 'about')
			$('#main').animate({left: aboutX + 'px'}, 1000);
		if(div == 'photos')
			$('#main').animate({left: '-' + photosX + 'px'}, 1000);
		if(div == 'video')
			$('#main').animate({left: '-' + videoX + 'px'}, 1000);
		if(div == 'words')
			$('#main').animate({left: '-' + wordsX + 'px'}, 1000);
		if(div == 'shows')
			$('#main').animate({left: '-' + showsX + 'px'}, 1000);
		if(div == 'contact')
			$('#main').animate({left: '-' + contactX + 'px'}, 1000);
		if(div == 'downloads')
			$('#main').animate({left: '-' + downloadsX + 'px'}, 1000);
	}

/********** LYRICS MANIPULATION! *********/
	
	var currWords = 'none';
	// Tell the first song to be selected when the words div is openenenenened
	$("a[title='words']").click(function(){
		var firstSong = 'Cinders Bare' // Name of the first song to open
		
		if(currWords == "none"){
			
		
		setTimeout(function(){
			$("a[title='"+firstSong+"']").addClass('current');
			$("a[title='"+firstSong+"']").append(' &#187;');
			$("p[title='"+firstSong+"']").fadeIn('slow');
		 }, 1200);
		
		 currWords = firstSong;
		 
		 }
	});

	$('a.words').click(function(){	
		var title = $(this).attr('title');
		if(currWords == title){
			$("a[title='"+currWords+"']").removeClass('current');
			$("a[title='"+currWords+"']").html(''+	title);			
			$("p[title='"+currWords+"']").fadeOut('slow');
			currWords = "none";
			return false;
		}
		if(currWords != title){		
			$("p[title='"+currWords+"']").fadeOut('fast');
			setTimeout(function(){
				$("p[title='"+title+"']").fadeIn('slow');
			 }, 200);
			$("a[title='"+title+"']").addClass('current');
			$("a[title='"+title+"']").append(' &#187;');
			$("a[title='"+currWords+"']").removeClass('current');
			$("a[title='"+currWords+"']").html(''+currWords);
			
			currWords = title;			
		}
	
		return false;	
	});

	var lasturl = "";	//here we store the current URL hash
	function checkURL(){
		hash = window.location.hash;
		if(hash != lasturl){
			lasturl = hash;
			if(hash == ""){
			return;
			}
			else{
				var url = hash.replace('#','');
				clicker(url);
			}
		}
	
	}





	
});


/* Comments and Snippets:
[title='"+title+"']


*/
