var chapterLengths = new Array(2)
chapterLengths[0]=2;
chapterLengths[1] = 8;
//To add a section
//  Fill in hidden fields on page
//  Add name to chapter
//  Add URL to chapter urls
// include link from contents page
// indicate available modes

var chapterNames = new Array("Home", "Introduction", "Graphing Distributions", "Summarizing Distributions", "Describing Bivariate Data", "Probability", "Normal Distribution", "Sampling Distributions","Estimation","Logic of Hypothesis Testing","Tests of Means", "Power", "Prediction","Analysis of Variance","Chi Square", "Case Studies", "Calculators", "Glossary")
var h = new Array("Title Page","Contents", "Instructions", "Simulations and Demonstrations")
var ch1 = new Array("Contents","What are Statistics?","Importance of Statistics", "Descriptive Statistics", "Inferential Statistics","Sampling Demonstration","Variables","Percentiles","Levels of Measurement","Measurement Demonstration","Basics of Data Collection", "Distributions", "Summation Notation", "Linear Transformations", "Exercises")
var ch2 = new Array("Contents","Introduction","Qualitative Variables", "Quantitative Variables", "Stem and Leaf Displays","Histograms", "Frequency Polygons", "Box Plots", "Box Plot Demo", "Bar Charts", "Line Graphs", "Exercises")
var ch3 = new Array("Contents","Central Tendency", "What is Central Tendency","Measures of Central Tendency","Balance Scale Simulation", "Absolute Differences Simulation", "Squared Differences Simulation","Median and Mean","Mean and Median Demo", "Additional Measures", "Comparing Measures","Variability" ,"Measures of Variability", "Variability Demo", "Estimating Variance Simulation", "Shapes of Distributions","Comparing Distributions Demo", "Effects of Linear Transformations", "Variance Sum Law I","Exercises")
var ch4 = new Array("Contents", "Introduction to Bivariate Data", "Values of the Pearson Correlation", "Guessing Correlations", "Properties of r", "Computing r", "Restriction of Range Demo","Variance Sum Law II", "Exercises")
var ch5 = new Array("Contents","Introduction to Probability", "Basic Concepts", "Conditional p Demo","Gambler's Fallacy", "Birthday Demo","Binomial Distribution", "Binomial Demonstration", "Base Rates","Bayes Demo", "Monty Hall Problem","Exercises")
var ch6 = new Array("Contents","Introduction","History", "Areas of Normal Distributions","Varieties Demonstration","Standard Normal", "Normal Approximation to the Binomial", "Normal Approximation Demo", "Exercises")
var ch7 = new Array("Contents","Introduction", "Basic Demo", "Sample Size Demo", "CLT Demo", "Sampling Distribution of the Mean", "Difference Between Means", "Sampling Distribution of r", "Sampling Distribution of p", "Exercises")
var ch8 = new Array("Contents","Introduction", "Degrees of Freedom", "Characteristics of Estimators", "Bias and Variability Simulation", "Confidence Intervals","Confidence Intervals Intro","Confidence Interval for Mean","t distribution","Confidence Interval Simulation", "Difference between Means","Correlation", "Proportion", "Exercises")
var ch9 = new Array("Contents","Introduction", "Significance Testing", "Type I and II Errors", "One- and Two-Tailed Tests", "Significant Results", "Non-Significant Results", "Steps in Hypothesis Testing","Confidence Intervals","Misconceptions", "Exercises")
var ch10 = new Array("Contents","Single Mean","t Distribution Demo","Difference between 2 Means", "Robustness Simulation","Pairwise Comparisons", "Specific Comparisons", "Correlated Pairs","Correlated t Simulation", "Comparisons (correlated)", "Pairwise (Correlated)", "Exercises")
var ch11 = new Array("Contents","Introduction", "Example Calculations", "Power Demo", "Power Demo 2","Factors Affecting Power", "Exercises")
var ch12 = new Array("Contents","Introduction to Linear Regression","Linear Fit Demo","Partitioning Sums of Squares", "Standard Error of the Estimate", "Prediction Line Demo","Inferential Statistics for b and r", "Exercises")
var ch13 = new Array("Contents","Introduction", "ANOVA Designs", "One-Factor ANOVA","One-Way Demo","Mulit-Factor Between-Subjects", "Unequal n", "Tests Supplementing", "Within-Subjects","Power of Within-Subjects Designs Demo","Exercises")
var ch14 = new Array("Contents","Chi Square Distribution", "One-Way Tables", "Testing Distributions Demo", "Contingency Tables","2 x 2 Simulation", "Exercises")
var case_study = new Array("Contents","Angry Moods", "Flatulence","Physicians Reactions", "Teacher Ratings", "Diet and Health", "Smiles and Leniency", "Animal Research","ADHD Treatment", "Weapons and Aggression", "SAT and College GPA", "Stereograms","Driving","Stroop Interference", "TV Violence", "Obesity and Bias", "Shaking and Stirring Martinis")
var analysis_lab = new Array("Contents", "Analysis Lab", "Binomial Distribution", "Chi Square Distribution", "F Distribution", "Inverse Normal Distribution","Inverse t Distribution", "Normal Distribution", "Power Calculator","r to Fisher z'","Studentized Range Distribution" ,"t Distribution", "Chi Square Distribution")
var glossary = new Array("Glossary")
var sectionNames = new Array(h,ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8,ch9,ch10,ch11,ch12,ch13,ch14,case_study,analysis_lab,glossary)

var homeUrl = new Array("title","map","instructions", "sims_demos")
var ch1Urls = new Array("introduction","what_are","importance","descriptive","inferential","sampling_demo","variables","percentiles","levels_of_measurement","measurement_demo","data_collection", "distributions","summation","linear_transforms", "ch1_exercises")
var ch2Urls = new Array("graphing_distributions","intro_graphing","graphing_qualitative","quantitative","stem","histograms","freq_poly","boxplots", "boxplot_demo","bar_chart", "line_graphs", "ch2_exercises")
var ch3Urls = new Array("summarizing_distributions","central_tendency","what_is_ct","measures","balance","median_sim","mean_sq_sim", "mean_median_def","mean_median_sim", "additional_measures", "comparing_measures","variability_ov", "variability","spread_sim", "variance_est", "shapes","compare_dist_demo", "transformations", "variance_sum_law","ch3_exercises")
var ch4Urls = new Array("bivariate","intro","pearson","pearson_demo", "properties", "calculation", "restriction_demo","variance_sum_law2","ch4_exercises")
var ch5Urls = new Array("probability","probability_intro", "basic","conditional_demo","gambler","birthday_demo","binomial", "binomial_demonstration","base_rates","bayes_demo","monty_hall_demo","ch5_exercises")
var ch6Urls = new Array("normal_distribution","intro", "history_normal","areas_normal","varieties_demo","standard_normal", "normal_approx", "normal_approx_demo","ch6_exercises")
var ch7Urls = new Array("sampling_distributions","intro_samp_dist",  "SampDist_v1","SampDist_v2", "clt_demo", "samp_dist_mean", "samplingdist_diff_means", "samp_dist_r", "samp_dist_p","ch7_exercises")
var ch8Urls = new Array("estimation","intro", "df","characteristics","estimates_sim","confidence_ov","confidence","mean","t_distribution","ci_sim", "difference_means", "correlation_ci", "proportion_ci","ch8_exercises")
var ch9Urls = new Array("logic_hypothesis","intro", "significance","errors", "tails","significant", "nonsignificant", "steps", "sign_conf","misconceptions", "ch9_exercises")
var ch10Urls = new Array("testing_means","single_mean","t_distribution_demo", "difference_means","robust_sim", "pairwise", "specific_comparisons","correlated","correlated_t_sim", "specific_related", "pairwise_correlated","ch10_exercises")
var ch11Urls = new Array("contents","intro_power", "example","power_demo","power_demo2","factors","ch11_exercises" )
var ch12Urls = new Array("prediction","intro","linear_fit_demo","partitioning", "accuracy", "prediction_line_demo","inferential", "ch12_exercises")
var ch13Urls = new Array("ANOVA","intro", "anova_designs", "one-way","one-way_demo", "multiway","unequal","tests_supplementing", "within-subjects","power_within_demo","ch13_exercises")
var ch14Urls = new Array("Chi_Square","distribution", "one-way","theor_sim","contingency","2x2sim", "ch14_exercises")

var caseUrls = new Array("case","angry_moods","flatulence","weight", "ratings", "diet", "leniency", "animal_research","adhd", "guns", "sat","stereograms","driving", "stroop", "tv_violence", "obesity_relation", "bond")
var calcUrls = new Array("calculators", "analysis_lab", "binomial_dist", "chi_square_prob","F_dist", "inverse_normal_dist","inverse_t_dist", "normal_dist","power_calc", "r_to_z", "studentized_range_dist", "t_dist","chi_square_prob")
var glossaryUrls = new Array("index")

var sectionUrls = new Array(homeUrl,ch1Urls,ch2Urls,ch3Urls,ch4Urls,ch5Urls,ch6Urls,ch7Urls,ch8Urls,ch9Urls,ch10Urls,ch11Urls,ch12Urls,ch13Urls,ch14Urls, caseUrls,calcUrls,glossaryUrls)

var homeMM = new Array(0,0,0,0)
var ch1MM = new Array(2,2,2,2,2,2,2,2,2,2,2,2,2)
var ch2MM = new Array(2,2,2,2,2,2,2,2,2,2)
var ch3MM = new Array(2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2)
var ch4MM = new Array(2,2,2,2,2,2,2,2,2,2,2,2)
var ch5MM = new Array(2,2,2,2,2,2,2)
var ch6MM = new Array(2,2,2,2,2,2,2,2)
var ch7MM = new Array(2,2,2,2,2,2,2,2,2)
var ch8MM = new Array(2,2,2,2,2,2,2,2,2,2,2,2)
var ch9MM = new Array(2,2,2,2,2,2,2,2,2,2,2,2)
var ch10MM = new Array(2,2,2,2,2,2,2,2,2,2,2,2)
var ch11MM = new Array(2,2,2,2,2,2,2,2,2,2,2,2)
var ch12MM = new Array(2,2,2,2,2,2,2,2,2,2,2,2)
var ch13MM = new Array(2,2,2,2,2,2,2,2,2,2,2,2)
var ch14MM = new Array(2,2,2,2,2,2,2,2,2,2,2,2)
var caseMM = new Array(0,0,0,0,0,0,0,0,0,0,0,0)
var calcMM = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
var glossaryMM = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)

// 0 : standard
// 1: standard, condensed,
// 2 standard, condensed, mm


var sectionModes = new Array(homeMM,ch1MM,ch2MM,ch3MM,ch4MM, ch5MM,ch6MM,ch7MM, ch8MM, ch9MM, ch10MM,ch11MM,ch12MM,ch13MM,ch14MM,caseMM,calcMM,glossaryMM)

var sectionIndex=0
var chapterIndex=0

var mmOption = 	new Option("Multimedia", "2")
var conOption = 	new Option("Condensed", "2")
var stOption = 	new Option("Standard", "1")
var modeMMOptions = new Array(mmOption, conOption, stOption)
var modeOptions = new Array(mmOption, conOption)


var mode =  new Array("","C", "M")
var modeStatus = 0
var selectedMode = 0



function  explainMode () {
	alert ("Streamlined has fewer examples and is less chatty; multimedia is a lecture presented as a quicktime movie.\nOnly standard is available now.")
}
function changeSection()
{
	//alert("changing section")
	//if((sectionIndex != document.forms[0].section.selectedIndex) || (chapterIndex != document.forms[0].chapter.selectedIndex)) {
	sectionIndex = document.forms[0].section.selectedIndex
	chapterIndex = document.forms[0].chapter.selectedIndex
	upDateMode()
	parent.mainFrame.location = getSectionUrl(chapterIndex,sectionIndex)
	
	//}
	
	
}

function changeChapter(chapterIndex){

upDateMode() 

v = getSectionUrl(chapterIndex,0)
//alert(v)
parent.mainFrame.location = v
chapterIndex = document.forms[0].chapter.selectedIndex
upDateSections(chapterIndex,sectionNames[chapterIndex][0])

}

function getSectionUrl(theChapter, theSection) {
	

	//xx = mode[document.forms[0].mode.selectedIndex]
	xx = mode[selectedMode]
	if(chapterNames[theChapter] == "Case Studies") {
		x = "case_studies/" + sectionUrls[theChapter][theSection] + xx +  ".html"
		
	}
	else if (chapterNames[theChapter] == "Calculators") {
		x = "analysis_lab/" + sectionUrls[theChapter][theSection] + xx +  ".html"
		
	}
	
	else if (chapterNames[theChapter] == "Glossary") {
		x = "glossary/index.html"
		
	}
	
	else 

	x = "chapter" + (theChapter) + "/" + sectionUrls[theChapter][theSection] + xx +  ".html"

return x
}

//var sections = new Array(3)
//var sectionIndex=0;
//sections[0] = "introductiontographingdata.html"
//sections[1] = "graphingcategoricaldata.html"
//var v = new Array(3)

function goNext() {
//alert(document.forms[0].section.length + " "  + (document.forms[0].section.selectedIndex +1))
	if (document.forms[0].section.length == document.forms[0].section.selectedIndex +1) {
	
		if (document.forms[0].chapter.length != document.forms[0].chapter.selectedIndex +1){
			document.forms[0].chapter.selectedIndex++
			changeChapter(document.forms[0].chapter.selectedIndex)
		}
	}
	else {
		document.forms[0].section.selectedIndex++
		changeSection()
	}
	
}
function testing() {
	x =parent.frames[0].document.forms[0]
	alert(x.section.length)
}

function goPrev() {
	if (document.forms[0].section.selectedIndex != 0) {

			document.forms[0].section.selectedIndex--
			changeSection()

		}
	else {
		if (document.forms[0].chapter.selectedIndex != 0) {
			document.forms[0].chapter.selectedIndex--
		
			//changeChapter(document.forms[0].chapter.selectedIndex)
			var L = sectionNames[document.forms[0].chapter.selectedIndex].length
			upDateMode()
			v = getSectionUrl(document.forms[0].chapter.selectedIndex,L-1)
			parent.mainFrame.location = v
			chapterIndex = document.forms[0].chapter.selectedIndex
			upDateSections(chapterIndex,sectionNames[chapterIndex][L-1])
		}
	}
}
function upDateSections(chapterIndex,theSection) 
	{

		var sectionIndex=0
		document.forms[0].chapter.selectedIndex=chapterIndex
		
		var sl = document.forms[0].section.options.length;
		var theseSections = sectionNames[chapterIndex]
		
		for (i=0;i<theseSections.length;i++) {
			
			if(theSection == theseSections[i]) {
		
				sectionIndex = i;
			}
			if (i+1 > sl) {
				document.forms[0].section.options[i] =	new Option(theseSections[i], "i")
				//document.forms[0].section.options[i] =	new Option(i+1 + ". " + theseSections[i], "i")
			}
			else {
				document.forms[0].section.options[i].text = theseSections[i]
				//document.forms[0].section.options[i].text = i+1 + ". " +theseSections[i]
			}
		}
		
		if (sl > theseSections.length) {
			//for (i = theseSections.length;i<sl;i++) {
			for (i = sl-1; i>= theseSections.length;i--) {
				document.forms[0].section.options[i] = null
			}
			
		}
		
		
			
}
function upDateMode() {

//alert("checking if update necessary " + document.forms[0].chapter.selectedIndex + " " + document.forms[0].section.selectedIndex)
	//alert("14 1 " + sectionModes[14][1])
	var newStatus = sectionModes[document.forms[0].chapter.selectedIndex][document.forms[0].section.selectedIndex]
	
	if (newStatus != modeStatus) {
		//alert(" necessary new: " + newStatus + " old:  " +  modeStatus)
		var curSelected = document.forms[0].mode.selectedIndex
		
		if (newStatus == 2) {
				if(modeStatus == 0) document.forms[0].mode.options[1] = new Option("Condensed", "1")			
				document.forms[0].mode.options[2] = new Option("Multimedia", "2")
		}
		else if (newStatus == 1){
				if(modeStatus == 0) document.forms[0].mode.options[1] = new Option("Condensed", "1")
				else {
					document.forms[0].mode.options[2] = null
					if (curSelected == 2) {
						document.forms[0].mode.selectedIndex = 0
						selectedMode = 0
					}
				}
		}
		else if (newStatus == 0) {
			if(modeStatus == 2) document.forms[0].mode.options[2] = null
			document.forms[0].mode.options[1] = null
			document.forms[0].mode.selectedIndex = 0
			selectedMode = 0
			//alert("status set to 0")
		}
		modeStatus = newStatus
		//alert("updated")
	}	
	//else alert("not necesary " + newStatus + " " + modeStatus )	
	
}
function changeMode() {
	selectedMode= document.forms[0].mode.selectedIndex
	parent.mainFrame.location = getSectionUrl(document.forms[0].chapter.selectedIndex,document.forms[0].section.selectedIndex)

}
