jQuery(document).ready(function($){

//	jQuery("#q").liveSearch({ajaxURL: "/?q="});

	//References
	var sections = $("#v02_eyedees li:not(:contains('2.0'))");
	var content = $("#sections");
	var main = $("#main");
	var credits = $("#credits-main");
	var feature = $("#feature");
	var old_url = window.location.href;
	var new_url = old_url.substring(0,old_url.length-4)		   
	var hash = window.location.hash.substr(1);
	var loading = $("#load");
	
	//Manage click events
	sections.click(function(){
	
		showLoading();
		feature.hide(1);
		window.location.hash = this.className; //Set the url
		tellFlash("v02-fava").showBackground(this.className); // Change flash backround
		document.getElementById("article-body").className = this.className; 
		main.hide(1);
		credits.hide(1);
		//load selected section
		switch(this.className){
			case "v02-intro":
				content.hide(1);
				content.load("/v02-intro #content", hideLoading);
				content.fadeIn(1000);
				
				break;
			case "chris-craddock-improvisation-rules":
		showTitle();
				content.hide(1);
				content.load("/archives/347 #content", hideLoading);
				//content.fadeIn(1000);
				break;
			case "sharon-murphy-48hr-film-making":
		showTitle();
				content.hide(1);
				content.load("/archives/364 #content", hideLoading);
				//content.fadeIn(1000);
				break;
			case "colette-slevinsky-improv-jazz-celluloid":
		showTitle();
				content.hide(1);
				content.load("/archives/449 #content", hideLoading);
				//content.fadeIn(1000);
				break;
			case "adolfo-film":
				content.hide(1);
				//content.load("/credits-favascope-2 #content", hideLoading);
				feature.fadeIn(1000);
				break;
			case "v02-credits":
				content.hide(1, showCredits);
				
				credits.load("/v02-credits #content", hideLoading);
				credits.fadeIn(1000);
				break;
			default:
				//hide loading bar if there is no selected section
				hideLoading();
				break;
		}
	}); 
	
	$("#v02_eyedees li.adolfo-film").mouseover(function(){
		$("#img-links li.adolfo-film").fadeIn(200);
	}); 
	$("#v02_eyedees li.chris-craddock-improvisation-rules").mouseover(function(){
		$("#img-links li.chris-craddock-improvisation-rules").fadeIn(200);
	}); 
	$("#v02_eyedees li.sharon-murphy-48hr-film-making").mouseover(function(){
		$("#img-links li.sharon-murphy-48hr-film-making").fadeIn(200);
	}); 
	$("#v02_eyedees li.colette-slevinsky-improv-jazz-celluloid").mouseover(function(){
		$("#img-links li.colette-slevinsky-improv-jazz-celluloid").fadeIn(200);
	}); 
	$("#v02_eyedees li.adolfo-film").mouseout(function(){
		$("#img-links li.adolfo-film").fadeOut(100);
	}); 
	$("#v02_eyedees li.chris-craddock-improvisation-rules").mouseout(function(){
		$("#img-links li.chris-craddock-improvisation-rules").fadeOut(100);
	}); 
	$("#v02_eyedees li.sharon-murphy-48hr-film-making").mouseout(function(){
		$("#img-links li.sharon-murphy-48hr-film-making").fadeOut(100);
	}); 
	$("#v02_eyedees li.colette-slevinsky-improv-jazz-celluloid").mouseout(function(){
		$("#img-links li.colette-slevinsky-improv-jazz-celluloid").fadeOut(100);
	}); 
 
 
	//show loading bar
	function showLoading(){
		$('#load').fadeIn('normal');
	}
	//hide loading bar
	function hideLoading(){
		$('#load').fadeOut(750);
	}
	
	function showTitle(){
	//alert("show title");
		$("#flashback").animate({ 
        top: "0"
      }, 700 );
		$("#main").animate({ 
        top: "740px"
      }, 700 );
	}
	
	function showCredits(){
	//alert("show title");
		$("#flashback").animate({ 
        top: "0"
      }, 700 );
	}
	
	window.onload = function () {
		
		//alert(hash);
		// On load, find out what section is in the url and get the content
		feature.hide(1);
		document.getElementById("article-body").className = hash; 
		
		switch(hash){
			case "v02-intro":
				content.hide(1);
				content.load("/v02-intro #content", hideLoading);
				content.fadeIn(1000);
				main.fadeIn(1000);
				break;
			case "chris-craddock-improvisation-rules":
				content.hide(1);
				content.load("/archives/347 #content", hideLoading);
				//content.fadeIn(1000);
				break;
			case "sharon-murphy-48hr-film-making":
				content.hide(1);
				content.load("/archives/364 #content", hideLoading);
				//content.fadeIn(1000);
				break;
			case "colette-slevinsky-improv-jazz-celluloid":
				content.hide(1);
				content.load("/archives/449 #content", hideLoading);
				//content.fadeIn(1000);
				break;
			case "adolfo-film":
				content.hide(1);
				//content.load("/credits-favascope-2 #content", hideLoading);
				feature.fadeIn(1000);
				break;
			case "v02-credits":
				content.hide(1);
				credits.load("/v02-credits #content", hideLoading);
				credits.fadeIn(1000);
				break;
			default:
				//hide loading bar if there is no selected section
				hideLoading();
				break;
		}
		tellFlash("v02-fava").showBackground(hash); // Change flash backround
		
		
	}
	
});
