// TODO: need to handle the URL: when people select an actor or section, the URL changes & history updates!
$(document).ready(function() {
	sections.init();
	
	members.init();
	
});

sections = {
	init : function () {
		var i, section;
		
		section = location.hash;
		
		$('#toc li a').click(function (event) {
			return sections.clickSwitcher(event);
		});
		
		sections.sectionSwitcher(section);
	},
	clickSwitcher : function (e) {
		var t = e.target;
		
		var section = '#' + t.href.split('#')[1];
		return	sections.sectionSwitcher(section);
	},
	sectionSwitcher : function (h) {
		switch(h) {
			case '':				
				sections.showHistory();
				break;
			case '#history':
				sections.showHistory();
				break;
			case '#actors':
				sections.showActors();
				break;
			case '#collaborators':
				sections.showCollaborators();
				break;
			case '#former-members':
				sections.showFormerMembers();
				break;
			default:
				sections.showHistory();
				break;
		}
		return false
	},
	showHistory : function () {
		$('#actors').hide();
		$('#collaborators').hide();
		$('#former-members').hide();
		$('#history').show();
	},
	showActors : function () {
		$('#collaborators').hide();
		$('#former-members').hide();
		$('#history').hide();
		$('#actors').show();
	},
	showCollaborators : function () {
		$('#actors').hide();
		$('#former-members').hide();
		$('#history').hide();
		$('#collaborators').show();
	},
	showFormerMembers : function () {
		$('#actors').hide();
		$('#collaborators').hide();
		$('#history').hide();
		$('#former-members').show();
	}	
};

members = {
	init : function () {
		$('.member').hide();
		$('p.back').remove();
		
		$('#actors-list li a').bind('click', function (event) {
			return members.showMember(event);
		});
		$('#collaborators-list li a').bind('click', function (event) {
			return members.showMember(event);
		});
		$('#former-members-list li a').bind('click', function (event) {
			return members.showMember(event);
		});
	},
	showMember : function (e) {
		var id, t;
		if (e.target.src) {
			t = e.target.parentNode;
		} else {
			t = e.target;
		}
		id = "#" + t.href.split('#')[1];
		if (document.getElementById(id.split('#')[1])) {
			$('ul li').css({ backgroundColor:"transparent" });
			$('ul li a').css({ color:'' });
			$('.member').hide();
			$(id).parent('div').show();
		}
		t.parentNode.style.backgroundColor = '#9f1b14';
		t.parentNode.style.color = '#fff';
		t.style.color = '#fff';
		return false;
	}
};
