	var jsroot = "/js/";
	var requiredModules;
	$requiredModules = ["yahoo", "animation","charts", "dom", "event", "datatable", "datasource", /*"dragdrop", */"fonts", "grids", "layout",
						"container", "resize", /*"tabview",*/ "json"];
	var loader = new YAHOO.util.YUILoader({
		allowRollup: true,
		require: $requiredModules,
		loadOptional: true,
//		base: '/dbook/js/yui/build/',
		base: jsroot + 'yui/build/',
	    skin: {
	        defaultSkin: 'fanhandle',
			base: 'assets/skins/',
		    overrides: { 
				dragdrop: ['sam'],
				logger: ['sam'],
				menu: ['sam'],
				calendar: ['sam'],
				paginator: ['sam'],
				slider: ['sam']
			}
	    },
		// The function to call when all script/css resources have been loaded
		onSuccess: function() {
			YAHOO.util.Event.onAvailable("x", function () {
															generateScript();
															document.getElementById("startbutton").style.display = "block";
															positionStuff();
														}, this);
		},
		
		onFailure: function(msg, xhrobj) { 
			var m = "LOAD FAILED: " + msg; 
			// if the failure was from the Connection Manager, the object 
			// returned by that utility will be provided. 
			if (xhrobj) 
			{ 
				m += ", " + YAHOO.lang.dump(xhrobj); 
			} 
			alert(m);     
		}
	});
	loader.insert();
	
var scrn;
	
function positionStuff()
{
	scrn = getScreen();
	var el;
	el = getEl("bigdiv");
	el.style.width = Math.max(scrn.width, 902) + "px";
	el = getEl("titlepart");
	el.style.left = (scrn.width/2 - 150) + "px";	
	el = getEl("homepagetool");
	var toolpos = scrn.width/2 - 250;
	el.style.left = toolpos + "px";
	el = getEl("demotext");
	var demotextpos = scrn.width/2 - 350;
	el.style.left = demotextpos + "px";
	var tocleft = (toolpos + 520);
	el = getEl("toc");
	el.style.left = tocleft + "px";
}

var highlighted = false;
// box is [left, top, width, height]
function highlight(box, dontStep)
{
	//setBox(1, makeBox(0, 0, scrn.width, box.top));
	//setBox(2, makeBox(0, box.top, box.left, box.height));
	//setBox(3, makeBox(box.left+box.width, box.top, scrn.width - box.left - box.width, box.height));
	//setBox(4, makeBox(0, box.top+box.height, scrn.width, screen.height - box.height - box.top));
	if(highlighted) {
		rehighlight(box, dontStep);
		return;
	}
	highlighted = true;
	setBox(1, makeBox(0, 0, 500, box.top));
	setBox(2, makeBox(0, box.top, box.left, box.height));
	setBox(3, makeBox(box.left+box.width, box.top, 500 - box.left - box.width, box.height));
	setBox(4, makeBox(0, box.top+box.height, 500, 500 - box.height - box.top));
	var stuff = { opacity: { to: 0.85 }};
	var anim = Array();
	for(var idx = 1; idx <= 4; idx++) {
		var el = getIframeEl("box" + idx);
		anim[idx] = new YAHOO.util.Anim(el, stuff, 1);
	}
	if(!dontStep)
		anim[4].onComplete.subscribe(nextStep);
	for(var idx = 1; idx <= 4; idx++) {
		anim[idx].animate();
	}
	//nextStep();
}

// box is [left, top, width, height]
function rehighlight(box, dontStep)
{
	//setBox(1, makeBox(0, 0, scrn.width, box.top));
	//setBox(2, makeBox(0, box.top, box.left, box.height));
	//setBox(3, makeBox(box.left+box.width, box.top, scrn.width - box.left - box.width, box.height));
	//setBox(4, makeBox(0, box.top+box.height, scrn.width, screen.height - box.height - box.top));
	resetBox(1, makeBox(0, 0, 500, box.top), null);
	resetBox(2, makeBox(0, box.top, box.left, box.height), null);
	resetBox(3, makeBox(box.left+box.width, box.top, 500 - box.left - box.width, box.height), null);
	resetBox(4, makeBox(0, box.top+box.height, 500, 500 - box.height - box.top), (dontStep?null:nextStep));
}

function unhighlight()
{
	highlighted = false;
	var stuff = { opacity: { to: 0 }};
	var anim = Array();
	for(var idx = 1; idx <= 4; idx++) {
		var el = getIframeEl("box" + idx);
		anim[idx] = new YAHOO.util.Anim(el, stuff, 1);
	}
	anim[4].onComplete.subscribe(uncover);
	for(var idx = 1; idx <= 4; idx++) {
		anim[idx].animate();
	}
}

function uncover()
{
	for(var idx = 1; idx <= 4; idx++) {
		var el = getIframeEl("box" + idx);
		el.style.display = "none";
	}
	nextStep();
}

function getScreen() {
	return makeBox(0, 0, YAHOO.util.Dom.getViewportWidth(), YAHOO.util.Dom.getViewportHeight());
}

function printBox(box)
{
	alert("Corner: (" + box.left + ", " + box.top + "); " + box.width + " x " + box.height);
}

function getEl(name)
{
	return document.getElementById(name);
}

function getIframeEl(name)
{
	//var ifr = getEl("homepagetool");
	//return ifr.document.getElementById(name);
	return window.frames[0].document.getElementById(name);
}

function makeBox(l, t, w, h)
{
	return { left: l, top: t, width: w, height: h };
}

function makeIframeBox(l, t, w, h)
{
	var iframeCorner = { x: scrn.width/2 - 250, y: 60 };
	return makeBox(l + iframeCorner.x, t, w + iframeCorner.y, h);
}

function setBox(whichBox, box)
{
	var el = getIframeEl("box" + whichBox);
	el.style.left = box.left + "px";
	el.style.top = box.top + "px";
	el.style.width = box.width + "px";
	el.style.height = box.height + "px";
	el.style.opacity = 0.0;
	el.style.display = "block";
	//alert(whichBox + ": " + el.style.left + "; " + el.style.top + "; " + el.style.width + "; " + el.style.height + "; ");
}

function resetBox(whichBox, box, animationCompletionFunc)
{
	var el = getIframeEl("box" + whichBox);
	var stuff = {
					left: { to: box.left },
					top: { to: box.top },
					width: { to: box.width },
					height: { to: box.height }
				};
	var anim = new YAHOO.util.Anim(el, stuff, 1);
	if(animationCompletionFunc)
		anim.onComplete.subscribe(animationCompletionFunc);
	anim.animate();
}

/////////////////////////////////////////////////////////////

var globalHighlightBox;
function makeGlobalHighlightBoxStep(l, t, w, h)
{
	globalHighlightBox = makeBox(parseInt(l), parseInt(t), parseInt(w), parseInt(h));
	nextStep();
}

function globalHighlight()
{
	highlight(globalHighlightBox);
}

function pause(ms)
{
	setTimeout("nextStep()", shortPause ? 250 : parseInt(ms));
}

var sceneName;
var scenes = Array();

var shortPause = false;
function linkToScene(sceneIdx)
{
	if(buttonsAlive || currentScene == -1) {
		currentScene = sceneIdx - 2;
		startScene(true);
	}
}

var sceneToChapter = Array();
var chapterCount = 0;
function generateScript()
{
	var raw = window.frames[1].document.body.innerHTML;
	var idx;
	raw = raw + "\n";
	var line = '';
	var expectingName = false;
	var skippingScene = false;
	var skipTo = '';
	chapterCount = 0;
	while((line = getLine(raw)) != -1) {
		raw = raw.slice(line.length);
		var idx;
		var re = new RegExp(/[ ;\n\r\t]*$/);
		line = line.replace(re, '');
		if(line == "")
			continue;
		if(line.substr(0,1) == "#")
			continue;
		if(expectingName) {
			sceneName = line;
			expectingName = false;
			if(sceneName == skipTo) {
				skippingScene = false;
				skipTo = '';
			}
			if(!skippingScene) {
				startSceneEncode();
			}
		}
		else if(line.length > 7 && line.substr(0, 7) == "skipto ") {
			skippingScene = true;
			skipTo = line.slice(7);
		}
		else if(line == "scene") {
			//finishScene();
			if(skipTo == '')
				skippingScene = false;
			expectingName = true;
			sceneToChapter[scenes.length] = chapterCount;
		}
		else if(line.length >= 6 && line.substr(0,6) == "scene ") {
			skippingScene = false;
			expectingName = true;
			var args = line.substr(6);
			if(args == 'skip') {
				skippingScene = true;
			}
			sceneToChapter[scenes.length] = chapterCount;
		}
		else if(line.length >= 7 && line.substr(0,7) == "chapter") {
			var args = line.substr(8);
			if(!skippingScene) {
				chapterCount++;
				var el = getEl("toc");
				var newlink = '<a id="chapterLabel' + chapterCount + '" href="javascript:linkToScene(' + (scenes.length + 1) + ')" style="text-decoration:none" ';
				newlink += 'onmouseover="this.style.color=\'#a7e5fe\';" ';
				newlink += 'onmouseout="this.style.color=\'#ffffff\';" >';
				newlink += chapterCount + ". " + args;
				newlink += '</a><br>';
				el.innerHTML = el.innerHTML + newlink;
			}
		}
		else if(line == "shortpause") {
			shortPause = true;
		}
		else if(!skippingScene)
			addStep(line);
	}
/*
for(scIdx in scenes) {
	alert("scene: " + scIdx + " " + scenes[scIdx].name);
	for(stIdx in scenes[scIdx].steps) {
		alert("func: " + stIdx + ": " + scenes[scIdx].steps[stIdx].func);
		for(argIdx in scenes[scIdx].steps[stIdx].args) {
			alert("arg: " + argIdx + ": " + scenes[scIdx].steps[stIdx].args[argIdx]);
		}
	}
}
*/
}

function startSceneEncode()
{
	var idx = scenes.length;
	scenes[idx] = Array();
	var cur = scenes[idx];
	cur.name = sceneName;
	cur.steps = Array();
}

function addStep(line) {
	var scnidx = scenes.length - 1;
	var stpidx = scenes[scnidx].steps.length;
	scenes[scnidx].steps[stpidx] = Array();
	var cur = scenes[scnidx].steps[stpidx];
	var idx = line.indexOf(" ");
	cur.args = Array();
	if(idx == -1) {
		cur.func = window[line];
	} else {
		cur.func = window[line.slice(0,idx)];
		
		var argpart = line.slice(idx + 1);
		argpart = argpart.replace(/^ */, '');
		if(argpart.substr(0,1) == '"' || argpart.substr(0,1) == "'") {			
			re = new RegExp(/\&gt;/);
			argpart = argpart.replace(/\&gt;/g, '>');
			re = new RegExp(/\&lt;/);
			argpart = argpart.replace(/\&lt;/g, '<');
			cur.args[cur.args.length] = argpart.slice(1, argpart.length - 1);
		} else {
			var re = new RegExp(/[ ,]+/);
			var parts = argpart.split(re);
			for(var i in parts) {
				if(parts[i] == '')
					continue;
				cur.args[cur.args.length] = parts[i];
			}
		}
	}
}

function getLine(big)
{
	var idxs = big.indexOf(";");
	if(idxs == -1)
		return -1;
	var count = 0;
	while(big.substr(idxs+count,1) == "\n" || big.substr(idxs+count,1) == "\r" || big.substr(idxs+count,1) == ";" || big.substr(idxs+count,1) == " " || big.substr(idxs+count,1) == "\t")
		count++;
	var retval = big.slice(0, idxs + count);
	return retval.replace(/^[ \t]*/,'');
	var idxn = big.indexOf("\n");
	var idxr = big.indexOf("\r");
	var count = 0;
	if(idxn != -1)
		count++;
	if(idxr != -1)
		count++;
	if(count == 0)
		return -1;
	if(count == 1) {
		if(idxn != -1) {
			retval = big.slice(0, idxn + 1);
		} else {
			retval = big.slice(0, idxr + 1);
		}
	} else {
		if(idxn < idxr) {
			retval = big.slice(0, idxr + 1);
		} else {
			retval = big.slice(0, idxn + 1);
		}
	}
	return retval.replace(/^[ \t]*/,'');
}

/*
var showSliderScene = {
	name: "showSlider",
	steps: [
				{ func: selectPlayer, args: [100216] },
				{ func: showText, args: ["Welcome to the FanHandle Tutorial"] },
				{ func: pause, args: [2000] },
				{ func: showText, args: ["FanHandle is the Web's FIRST <i>fully interactive</i> fantasy football prediction builder."] },
				{ func: pause, args: [2000] },
				{ func: showText, args: ["Look! Look! Look! This is what we call a slider..."] },
				{ func: makeGlobalHighlightBoxStep, args: [450, 307, 35, 168] }, //osSliderBox
				{ func: globalHighlight, args: [] },
				{ func: pause, args: [3000] },
				{ func: unhighlight, args: [] },
				{ func: showText, args: ["Sliders are pretty doggone cool, eh?"] },
				{ func: pause, args: [3000] }
		]
};

var anotherScene = {
	name: "another",
	steps: [
				{ func: showText, args: ["Here is some more cool stuff to know."] },
				{ func: pause, args: [2000] },
				{ func: showText, args: ["Stuff a player's name in here."] },
				{ func: makeGlobalHighlightBoxStep, args: [151, 390, 180, 43] }, //osSliderBox
				{ func: globalHighlight, args: [] },
				{ func: showText, args: ["For example, Joseph Addai..."] },
				{ func: pause, args: [1000] },
				{ func: stuffPlayerName, args: ["Joseph Addai"] },
				{ func: pause, args: [2000] },
				{ func: showText, args: ["And hit enter..."] },
				{ func: selectPlayer, args: [100004] },
				{ func: pause, args: [2000] },
				{ func: unhighlight, args: [] },
				{ func: showText, args: ["Easy?"] },
				{ func: pause, args: [3000] }
		]
};
*/

//var scenes = [
	//showSliderScene,
	//anotherScene
//];

function unhighlightTOC()
{
	for(var idx = 1; idx <= chapterCount; idx++) {
		var el = getEl("chapterLabel" + idx);
		el.style.fontWeight = 'normal';
		//el.style.fontSize = '100%';
	}
}

function highlightTOC(sceneIdx)
{
	var el = getEl("chapterLabel" + sceneToChapter[sceneIdx]);
	el.style.fontWeight = 'bold';
	//el.style.fontSize = '140%';
}

var currentScene = -1;
var currentStep = -1;
var buttonsAlive = false;
function startScene(needInit)
{
	var stuff;
	var el;
	buttonsAlive = false;
	if(currentScene == -1 || needInit) {
		el = getEl("maintext2");
		el.innerHTML = '';
		el = getEl("maintext3");
		el.innerHTML = '';
		el = getEl("maintext1");
		el.style.zIndex = 1;
		el = getEl("startbutton");
		stuff = { opacity: { to: 0 }};
		var anim = new YAHOO.util.Anim(el, stuff, 0.3);
		anim.animate();
		anim.onComplete.subscribe(function(){ getEl("startButton").style.display="none";});
	}
	if(currentScene > -1) {
		stuff = { opacity: { to: 0.15 }};
		el = getEl("leftbutton");
		var anim1 = new YAHOO.util.Anim(el, stuff, 0.3);
		anim1.animate();
		el = getEl("rightbutton");
		var anim2 = new YAHOO.util.Anim(el, stuff, 0.3);
		anim2.animate();
	}
	unhighlightTOC();
	if(++currentScene < scenes.length) {
		highlightTOC(currentScene);
		currentStep = -1;
		nextStep();
	}
}

function nextScene()
{
	var stuff;
	var el;
	if(currentScene == scenes.length - 1) {
		el = getEl("leftbutton");
		el.style.display = "none";
		el = getEl("rightbutton");
		el.style.display = "none";
		currentScene = -1;
		currentStep = -1;
		el = getEl("maintext2");
		el.style.opacity = 0;
		el.innerHTML = '';
		el = getEl("maintext3");
		el.style.opacity = 0;
		el.innerHTML = '';
		el = getEl("maintext1");
		el.style.zIndex = 4;
		el = getEl("startbutton");
		stuff = { opacity: { to: 1 }};
		el.style.display = "block";
		var anim = new YAHOO.util.Anim(el, stuff, 0.3);
		anim.animate();
		unhighlightTOC();
	} else {
		buttonsAlive = true;
		stuff = { opacity: { to: 1.0 }};
		el = getEl("leftbutton");
		el.style.opacity = 0.15;
		el.style.display = "block";
		var anim1 = new YAHOO.util.Anim(el, stuff, 0.3);
		anim1.animate();
		el = getEl("rightbutton");
		el.style.opacity = 0.15;
		el.style.display = "block";
		var anim2 = new YAHOO.util.Anim(el, stuff, 0.3);
		anim2.animate();
	}
}

function nextStep()
{
	if(++currentStep < scenes[currentScene].steps.length) {
		scenes[currentScene].steps[currentStep].func.apply(this, scenes[currentScene].steps[currentStep].args);
	} else {
		nextScene();
	}
}

function nextClick()
{
	if(buttonsAlive)
		startScene();
}

function previousClick()
{
	if(buttonsAlive) {
		currentScene--;
		startScene();
	}
		//alert('Not Implemented, John.\n\nClick the "Next" button...it works!');
}

function alerter(mess)
{
	alert(mess);
	nextStep();
}

function showText(text)
{
	// Put new text in  zindex 2
	var el2 = getEl("maintext2");
	var el3 = getEl("maintext3");
	el3.style.opacity = 1;
	el2.style.opacity = 0;
	el2.innerHTML = text;
	//Animate zindex 2 => opaque; zindex 3 => transparent
	var stuff2 = { opacity: { to: 1.0 }};
	var stuff3 = { opacity: { to: 0.0 }};
	var anim2 = new YAHOO.util.Anim(el2, stuff2, 1);
	var anim3 = new YAHOO.util.Anim(el3, stuff3, 1);
	anim2.animate();
	anim3.animate();
	anim3.onComplete.subscribe(showText2);
}

function showText2()
{
	// Copy new text to zindex 3
	var el2 = getEl("maintext2");
	var el3 = getEl("maintext3");
	el3.innerHTML = el2.innerHTML;
	// Set zindex 3 to opaque
	el3.style.opacity = 1;
	nextStep();
}

function stuffPlayerName(name)
{
	el = getIframeEl("playerinput");
	//el.click();
	el.value = name;
	nextStep();
}

function selectPlayer(playerid)
{
	window.frames[0].selectPlayer(playerid);
	nextStep();
}

function clickPPT()
{
	el = getIframeEl("pptradio");
	el.click();
	nextStep();
}

function clickTouches()
{
	el = getIframeEl("touchesradio");
	el.click();
	nextStep();
}

function clickPoints()
{
	el = getIframeEl("ptsradio");
	el.click();
	nextStep();
}

function setLookback(weeks)
{
	weeks = parseInt(weeks);
	window.frames[0].setLookbackMenuLabel(weeks);
	window.frames[0].targetLookback[window.frames[0].currentStat] = weeks;
	window.frames[0].resetData(window.frames[0].playerId, true, true);
	nextStep();
}

function setScoringType(name)
{
	var ss = [ 
		"YAHOO.com",
		"ESPN.com",
		"CBS.com",
		"NFL.com"
	];
	for(idx = 0; idx < ss.length; idx++) {
		if(name == ss[idx]) {
			break;
		}
	}
	if(idx != ss.length) {
		window.frames[0].setSSMenuInfo(name, idx);
		window.frames[0].selectPlayer('current', true);
	}
	nextStep();
}

function moveSlider(name, pos)
{
	pos = parseInt(pos);
	var sn = [
				"playerAvg",
				"homeFieldAdv",
				"grassArtAdv",
				"oppStrength"
	];
	for(idx = 0; idx < sn.length; idx++) {
		if(name == sn[idx]) {
			break;
		}
	}
	if(idx != sn.length) {
		var sldr = window.frames[0].mySlider.retrieveSliderForTutorial(name);
		sldr.slider.animate = true;
		sldr.slider.animationDuration   = 1;
		// args for setValue are (newOffset, skipAnimation, force, silent)
		sldr.slider.setValue(-pos, false, true, false);
		sldr.slider.animate = false;
		//window.frames[0].computeChartValues();
	}
	nextStep();
}

function devBox()
{
	var el = getEl("devleft");
	var l = parseInt(el.value);
	var el = getEl("devtop");
	var t = parseInt(el.value);
	var el = getEl("devwidth");
	var w = parseInt(el.value);
	var el = getEl("devheight");
	var h = parseInt(el.value);
//alert(l + ", " + t + ", " + w + ", " + h);
	var globalHighlightBox = makeBox(l, t, w, h);
	highlight(globalHighlightBox, true);
	el = getEl("devresult");
	el.innerHTML = l + ", " + t + ", " + w + ", " + h;
}








