var SIS8 = {};

SIS8.Sister = function(config){
	this.name = config.name;
	this.born = config.born;
	this.height = config.height;
	this.likes = config.likes;
	this.dislikes = config.dislikes;
	this.strengths = config.strengths;
	this.image = config.image;
}
	
var sis_annie = new SIS8.Sister({
	name : "Annie",
	born : "August 8, 2000 (8:00 am)",
	height : "4'8\"",
	likes : "Cats, Will Simms, Pete the mechanic, the Hair-Cutting Room (she&rsquo;s the only one who does), driving, being in charge.",
	dislikes : "The Wicket (all of the time), the McG (most of the time), Mandy Stenko (some of the time), having anyone disagree with her.",
	strengths : "Always good in a pinch, Annie is a quick thinker and ready to take action on a moment&rsquo;s notice. With their parents missing, Annie becomes the Huit sisters&rsquo; Daddy, so to speak."
});

var sis_durinda = new SIS8.Sister({
	name : "Durinda",
	born : "August 8, 2000 (8:01 am)",
	height : "4'7\"",
	likes : "Cats, Will Simms, Pete the mechanic, the kitchen, cooking, having people say nice things about her cooking.",
	dislikes : "Having people say nasty things about her cooking.",
	strengths : "Likes to take care of other people, particularly if the people remember to say thank you. With their parents missing, Durinda becomes the Huit sisters&rsquo; Mommy, so to speak."
});

var sis_georgia = new SIS8.Sister({
	name : "Georgia",
	born : "August 8, 2000 (8:02 am)",
	height : "4'6\"",
	likes : "Cats, Will Simms, Pete the mechanic, complaining.",
	dislikes : "Things happening when they&rsquo;re not supposed to, doing chores around the house.",
	strengths : "Willingness to get the spear whenever she thinks Annie might need it."
});

var sis_jackie = new SIS8.Sister({
	name : "Jackie",
	born : "August 8, 2000 (8:03 am)",
	height : "4'5\"",
	likes : "Cats, Will Simms, Pete the mechanic, reading, helping anyone who needs it.",
	dislikes : "When Georgia and Rebecca complain too much or when they pick on Petal and Zinnia.",
	strengths : "A peace-keeper by nature, Jackie is always happy to step in to help the others whenever Annie and Durinda are otherwise occupied."
});

var sis_marcia = new SIS8.Sister({
	name : "Marcia",
	born : "August 8, 2000 (8:04 am)",
	height : "4'4\"",
	likes : "Cats, Will Simms, Pete the mechanic, math, science, figuring things out.",
	dislikes : "Being told what to do, particularly by Annie.",
	strengths : "Because she likes figuring things out and is very observant, Marcia often sees things the others miss."
});

var sis_petal = new SIS8.Sister({
	name : "Petal",
	born : "August 8, 2000 (8:05 am)",
	height : "4'3\"",
	likes : "Cats, Will Simms, Pete the mechanic, fluffy pillows, furry blankets, riding the little pink car, sunny days where nothing scary happens.",
	dislikes : "Thunderstorms, danger, basements, spiders, shadows, Bad People.",
	strengths : "When she&rsquo;s not annoying the others by being scared of everything, Petal can be quite sweet."
});

var sis_rebecca = new SIS8.Sister({
	name : "Rebecca",
	born : "August 8, 2000 (8:06 am)",
	height : "4'2\"",
	likes : "Cats, Will Simms, Pete the mechanic, pink frosting straight from the can, annoying other people, saying that their parents have died.",
	dislikes : "<em>(Too many to mention.)</em>",
	strengths : "This remains unclear. "
});

var sis_zinnia = new SIS8.Sister({
	name : "Zinnia",
	born : "August 8, 2000 (8:07 am)",
	height : "4'1\"",
	likes : "Cats, Will Simms, Pete the mechanic, talking to animals, having animals talk to her, presents.",
	dislikes : "Being younger than everyone else, being shorter than everyone else, being smaller than everyone else, holidays with no presents, having to wait her turn for everything.",
	strengths : "If it turns out that Zinnia really can talk to the animals, that&rsquo;ll be a real doozy of a strength, won&rsquo;t it?"
});

SIS8.initModalWindow = function(sister){
	YAHOO.namespace("sisters.container");
	YAHOO.sisters.container.stats = 
			new YAHOO.widget.Panel("stats",  
				{
					width:"800px", 
					fixedcenter:true, 
					close:false, 
					draggable:false, 
					zindex:45,
					modal:true,
					//effect: {effect: YAHOO.widget.ContainerEffect.FADE, duration: 1},
					visible:false
				} 
			);
	var picSource = "images\/sisters\/" + sister.name.toLowerCase() + ".gif";
	var windowHeight = document.viewport.getHeight();
	var closeLink = '<tr><td colspan="2" class="close"><div class="merchLink"><a href="#" onclick="YAHOO.sisters.container.stats.hide();">Close Window<\/a><\/div><\/td><\/tr>';
	if (windowHeight < 500) {
		var reducedHeight = windowHeight - 40;
		var shellStyles = ' style="height: ' + reducedHeight + 'px; overflow: auto;"';
		var imgHeight = 350;
		var imgWidth = 208;
		var closeLinkTop = closeLink;
	} else {
		var shellStyles = "";
		var imgHeight = 450;
		var imgWidth = 267;
		var closeLinkTop = "";
	}
	YAHOO.sisters.container.stats.setBody('<div id="tableShell""' + shellStyles + '"><table border="0" cellspacing="0" cellpadding="0" class="sisBox">' + closeLinkTop + '<tr><td><h2>Meet ' + sister.name + ' Huit!<\/h2><p><span>Born:<\/span> ' + sister.born + '<\/p><p><span>Height:<\/span>' + sister.height + '<\/p><p><span>Likes:<\/span>' + sister.likes + '<\/p><p><span>Dislikes:<\/span>' + sister.dislikes + '<\/p><p><span>Strengths:<\/span>' + sister.strengths + '<\/p><\/td><td class=\"sisPic\"><img src="' + picSource + '" alt="' + sister.name + '" height="' + imgHeight + '" width="' + imgWidth + '" /><\/td><\/tr>' + closeLink + '<\/table><\/div>');
	YAHOO.sisters.container.stats.render(document.body);
	YAHOO.sisters.container.stats.show();
}

SIS8._getPodcast = function() {
	// random url reset solves an IE7 bug that prevents podcast from loading if it was previously played
	var fileToLoad = "podcast.m4a?r=" + Math.random(); 
	var myQTObject = new QTObject(fileToLoad, "Podcast", "250", "16");
	myQTObject.addParam("autostart", "true");
	myQTObject.write("podcastPlayer");
	$("podcastLoader").hide();
}

SIS8.loadPodcast = function() {
	$("podcastLoader").show();
	setTimeout("SIS8._getPodcast();", 1000);
}

SIS8.reloadPage = function() {
	location.reload(true);	
}

Array.prototype.max = function() {
	var max = this[0];
	var len = this.length;
	for (var i = 1; i < len; i++) if (this[i] > max) max = this[i];
	return max;
}

SIS8.getQuizResults = function() {
	var Annie = 0;	
	var Durinda = 0;
	var Georgia = 0;
	var Jackie = 0;
	var Marcia = 0;
	var Petal = 0;
	var Rebecca = 0;
	var Zinnia = 0;
	
	var letters = ["a", "b", "c", "d", "e", "f", "g", "h"];
	
	var sisters = ["Annie", "Durinda", "Georgia", "Jackie", "Marcia", "Petal", "Rebecca", "Zinnia"];
	
	for (i=0; i<8; i++) {
		letters.each(function(j){
			var questionNumber = i + 1;
			var answerId = j + "_" + questionNumber;
			if ($(answerId).checked) {
				switch (j) {
					case "a":
						Annie++;
						break;
					case "b":
						Durinda++;
						break;
					case "c":
						Georgia++;
						break;
					case "d":
						Jackie++;
						break;
					case "e":
						Marcia++;
						break;
					case "f":
						Petal++;
						break;
					case "g":
						Rebecca++;
						break;
					case "h":
						Zinnia++;
						break;
					default:
						
				} // end switch
			} // end if
		}); // end letters loop
	} // end questions loop
	
	var scores = [Annie, Durinda, Georgia, Jackie, Marcia, Petal, Rebecca, Zinnia];
	
	var highScore = scores.max();
	var mostAnswered = "You answered mostly";
	var youAre = "You are"
	var winners = 0;

	scores.each(function(i, index) {
		if (i == highScore) {
			winners++;
			if (winners > 1) {
				mostAnswered += " and";
				youAre += " and";
			}
			mostAnswered += " ";
			mostAnswered += "<strong>&ldquo;";
			mostAnswered += letters[index];
			mostAnswered += "&rdquo;</strong>";
			youAre += " ";
			youAre += "<strong>";
			youAre += sisters[index];
			youAre += "</strong>";
		}
	});
	
	mostAnswered += ".";
	youAre += "!";
	
	var fullReply = mostAnswered + "<br />" + youAre;
	$("top").scrollTo();
	var resultsContainer = $("results");
	if (highScore > 0) {
		var resultsText = "<h2>Your Results:</h2><p>" + fullReply + "</p><p><input type=\"button\" value=\"Start Over\" onclick=\"SIS8.clearQuiz();\" /></p>";
	} else {
		var resultsText = "<h2>You didn&rsquo;t answer any questions!</h2><p><input type=\"button\" value=\"Try Again\" onclick=\"SIS8.clearQuiz();\" /></p>";
	}
	resultsContainer.update(resultsText);
	resultsContainer.style.display = "block";
}

SIS8.clearQuiz = function() {
	var letters = ["a", "b", "c", "d", "e", "f", "g", "h"];
	for (i=0; i<8; i++) {
		letters.each(function(j){
			var questionNumber = i + 1;
			var answerId = j + "_" + questionNumber;
			$(answerId).checked = false;
		}); // end letters loop
	} // end questions loop
	$("top").scrollTo();
	$("results").update();
	$("results").style.display = "none";
}

var today = new Date()
var month = today.getMonth() + 1
var day = today.getDate()
var year = today.getFullYear() 
var s = "/"
var yearAddOn = "&ndash;" + year;

Event.observe(window, "load", function() {
	if (year > 2008 && $("copyrightYear")) {
		var elementToUpdate = $("copyrightYear");
		var currentText = elementToUpdate.innerHTML;
		var newText = currentText + "&ndash;" + year;
		elementToUpdate.update(newText);
	}
});