function parse() {
	if(document.getElementById) {
		var divToShow = location.hash.substr(1);
		var toScroll = 0;
		if(divToShow != 'intro' && divToShow != 'context' && divToShow != 'press' && divToShow != 'music' && divToShow != 'video' && divToShow != 'map' && divToShow != 'gallery') { divToShow = 'intro'; } //set case in which there's no hash value
		initTabContent(divToShow);
//		document.getElementById("story_" + divToShow).style.display = 'block';
		var tabClass = document.getElementById("tab_" + divToShow).className;
		if(divToShow == 'intro') {
			tabClass = "first on";
		} else {
			tabClass = "on";
			toScroll = 1;
		}
		document.getElementById("tab_" + divToShow).className = tabClass;
	}
	if (toScroll)
		{ window.scrollTo(0,199); }
}

function initStoryNumbers() {
	if (!document.getElementsByTagName || !document.getElementById('story_numbers')) { return; }
	var stories = document.getElementById('story_numbers').getElementsByTagName('a');
	for (var i = 0; i < stories.length; i++) {
		var story = stories[i];
		if (story.getAttribute('id')){
			story.onmouseover = function(){ try{ setStoryString(getStoryString(this.id)); } catch(e) { /*catch exceptions */ } };
			story.onmouseout = function(){ try{ clearStoryString(); } catch(e) { /*catch exceptions */ } };
		}
	}
}

function initTabs() {
	if (!document.getElementsByTagName || !document.getElementById('tabs')) { return; }
	var tabs = document.getElementById('tabs').getElementsByTagName('li');
	for (var i = 0; i < tabs.length; i++) {
		var tab = tabs[i];
		if (tab.getAttribute('id')){
			tab.onclick = function(){ try{ selectTab(this.getAttribute('id').substr(4)); selectTabContent(this.getAttribute('id').substr(4)); } catch(e) { /*catch exceptions */ } };
//			tab.onmouseout = function(){ try{ document.getElementById('story_' + this.getAttribute('id').substr(4)).style.display="none"; } catch(e) { /*catch exceptions */ } };
		}
	}
}

function initTabContent(tabName) {
	if (!document.getElementsByTagName || !document.getElementById('tabs')) { return; }
	var tabs = document.getElementById('story_body').getElementsByTagName('div');
	for (var i = 0; i < tabs.length; i++) {
		var tab = tabs[i];
		if (tab.getAttribute('id')){
			if(tab.getAttribute('id') == ("story_" + tabName)) {
				tab.style.display = 'block';
			} else {
				tab.style.display = 'none';
			}
		}
	}
}


window.onload=function(){
	parse();
	initStoryNumbers();
	initTabs();
};


function getStoryString(storyID){
	var stringText = 'The Story of the Movement ';
	switch(storyID){
		case 'story1':
			stringText += ' &#8212; Emmett Till&apos;s Murder';
			break;
		case 'story2':
			stringText += ' &#8212; The Montgomery Bus Boycott';
			break;
		case 'story3':
			stringText += ' &#8212; Southern School Desegregation';
			break;
		case 'story4':
			stringText += ' &#8212; Non-Violent Protests';
			break;
		case 'story5':
			stringText += ' &#8212; The Freedom Rides';
			break;
		case 'story6':
			stringText += ' &#8212; The Limits of Non-Violence';
			break;
		case 'story7':
			stringText += ' &#8212; Project &quot;C&quot; in Birmingham';
			break;
		case 'story8':
			stringText += ' &#8212; The March on Washington';
			break;
		case 'story9':
			stringText += ' &#8212; Freedom Summer';
			break;
		case 'story10':
			stringText += ' &#8212; The Freedom March from Selma to Montgomery, AL';
			break;
		case 'story11':
			stringText += ' &#8212; The Nation of Islam and Malcolm X';
			break;
		case 'story12':
			stringText += ' &#8212; Chicago Freedom Movement';
			break;
		case 'story13':
			stringText += ' &#8212; Riots in Detroit';
			break;
		case 'story14':
			stringText += ' &#8212; &quot;Power to the People&quot;';
			break;
		case 'story15':
			stringText += ' &#8212; Poor People&apos;s Campaign';
			break;
		case 'story16':
			stringText += ' &#8212; Vietnam and the Civil Rights Movement';
			break;
		case 'story17':
			stringText += ' &#8212; The Black Panther Party';
			break;
		case 'story18':
			stringText += ' &#8212; The Attica Prison Riot';
			break;
		case 'story19':
			stringText += ' &#8212; Blacks Define Themselves';
			break;
		case 'story20':
			stringText += ' &#8212; The First Black Southern Mayor';
			break;
		case 'story21':
			stringText += ' &#8212; School Desegregation in Boston';
			break;
		case 'story22':
			stringText += ' &#8212; The Bakke Case and Affirmative Action';
			break;
		case 'story23':
			stringText += ' &#8212; Riots in Florida';
			break;
		case 'story24':
			stringText += ' &#8212; Conflict in Chicago';
			break;
		case 'story25':
			stringText += ' &#8212; Operation PUSH';
			break;
		case 'story26':
			stringText += ' &#8212; Civil Rights Today';
			break;
	}
	return stringText;
}



function setStoryString(storyStr) {
	if(document.getElementById('story_title')){
		document.getElementById('story_title').innerHTML = storyStr;
	}
}


function clearStoryString() {
	if(document.getElementById('story_title')){
		document.getElementById('story_title').innerHTML = 'The Story of the Movement &#8212; 26 Events';
	}
}


function selectTabContent(arg) {
	var tabs = document.getElementById('story_body').getElementsByTagName('div');
	for(var j=0; j<tabs.length; j++) {
		var tab = tabs[j];
		if (tab.getAttribute('id') == ('story_' + arg)) {
			tab.style.display="block";
		} else {
			tab.style.display="none";
		}
	}
}

function selectTab(arg) {
	var tabs = document.getElementById('tabs').getElementsByTagName('li');
	for(var j=0; j<tabs.length; j++) {
		var tab = tabs[j];
		if (tab.getAttribute('id') == ('tab_' + arg)) {
			tab.className = 'on';
		} else {
			tab.className = '';
		}
	}
//	var introClass = document.getElementById('tab_intro').getAttribute('class');
//	alert (introClass);
//	introClass = "first " + introClass;
//	document.getElementById('tab_intro').className = introClass;
	if (arg == 'intro') {
		document.getElementById('tab_intro').className = "first on";
	} else {
		document.getElementById('tab_intro').className = "first";
	}
}