/***********************************************************
** FILE    : ssp.js
** SUMMARY : Menubuilder code and subnav instances;
**			 Quote randomizer; Transparent layer function
**
***********************************************************/

//------------------ global browser detect vars
var isNN = (navigator.appName == "Netscape");
var isIE = (navigator.appName == "Microsoft Internet Explorer");
var isMac = (navigator.userAgent.indexOf("Mac") != -1);

//------------------ getting NN version number
function getNNversion()
{
	if(isNN)
	{	
		var appVer = parseFloat(navigator.appVersion);
		if(appVer < 5)
		{
			return appVer;
		}
		else
		{
			if(typeof navigator.vendorSub != "undefined")
			{
				return parseFloat(navigator.vendorSub);
			}
		}
	}
	return 0;
};

var isNN6 = getNNversion() >= 6;

//------------------------- returning the value of the section name/value pair in URL
function getSectionArg()
{
	var arg = new Object();
	
	var queryStr = location.search.substring(1); // query -> everything in the URL after the '?'
	if(queryStr.indexOf('section') != -1)
	{
		sectionStr = queryStr.substring(queryStr.indexOf('section'));
		sectionValue = sectionStr.substring(sectionStr.indexOf('=')+1);
		arg.value = sectionValue
	}
	
	return arg;
};

//------------------------ rendering opaque layer
function renderOpaque(color, opacity, height)
{
	// THIS LAYER WILL RENDER IN IE5+ NN6+ BROWSERS ONLY
	var str;
	var s = new getSectionArg();
	var lWidth; //585 covers whole content area
	var filterAttr;
	var ieFilterAttr = "filter:alpha(opacity=" + opacity + ")";
	var nnFilterAttr = "-moz-opacity:" + opacity + "%";
	
	if(s.value == null) lWidth = 437; 
	else lWidth = 585; 
	
	if(s.value != null) if(s.value.indexOf("Overview") != -1) lWidth = 437; 
	
	if(isIE) filterAttr = ieFilterAttr;
	else if(isNN6) filterAttr = nnFilterAttr;
	
	str = '<div id="transLayer" style="position:absolute; z-index:15; visibility:hidden; top:201px; left:215px; width:' + lWidth + 'px; height:' + height + 'px; background-color:' + color + '; ' + filterAttr + '"></div>';
	
	document.write(str);
}

//------------------------ menu builder

// setting subnav arrays -> using multi dimensional array to capture the src/name/id for each element
// and the alt text for the image in the menu.
/*
var whySmall_subnav     = new Array(["whyOverview","Overview"],["whatss","What Are Small Schools"],
                                    ["achieve","Student Achievement"],["personal","Personalization"],
									["cost","Cost Effectiveness"],["safety","Safety Benefits"],
									["other","Other Benefits"]);
								
var starting_subnav     = new Array(["startOverview","Overview"],["change","School Change"],
									["large","Large School Conversions"],["newsmall","New Small School Start-Up"],
									["state","State &amp; District Support"],["adult","Adult Learning Communities"],
									["schedule","Schedules &amp; Budgets"],["facilities","Facilities &amp; Physical Space"]);
								
var smallSchools_subnav = new Array(["smallOverview","Overview"],["whatwe","What We Are Learning"],
									["inwa","In Washington State"],["across","Across The Nation"],
									["cando","What Students Can Do"]);
									
var tools_subnav        = new Array(["toolOverview","Overview"],["get","Getting Started"],
							 		["classroom","Classroom Resources"],["look","Looking at Student Work"],
							 		["build","Building Family &amp; Community Connections"],["collect","Collecting &amp; Reporting Data"],
							 		["facil","Facilitating Meetings &amp; Groups"],["protocols","Using Protocols"]);
									
var resources_subnav 	= new Array(["resOverview","Overview"],["public","Our Publications"],
									["articles","Articles &amp; Research by Topic"],["gates","From the Gates Foundation"],
									["otherorgs","Other Organizations"]);
								
var about_subnav   		= new Array(["aboutOverview","Overview"],["who","Who We Are"],
									["coachescol","Coaches Collaborative"],["staff","Staff List"],
									["employ","Employment Opportunities"],["directions","Directions to the Office"]);*/
					
// WITHOUT ALT TAGS
var whySmall_subnav     = new Array(["whyOverview",""],["whatss",""],
									["achieve",""],["personal",""],
									["cost",""],["safety",""],
									["other","Other Benefits"]);
								
var starting_subnav     = new Array(["startOverview",""],["change",""],
									["large",""],["newsmall",""],
									["state",""],["adult",""],
									["schedule",""],["facilities",""]);
								
var teaching_subnav     = new Array(["teachOverview",""],
								//	["personal",""],["pbl",""],["adult",""],
									["stories-adult-learning",""],
									["picturingposs",""]);

var smallSchools_subnav = new Array(["smallOverview",""],["whatwe",""],
									["inwa",""],["across",""],
									["cando",""]);
									
var tools_subnav        = new Array(["toolOverview",""],["get",""],
							 		["classroom",""],["look",""],
							 		["build",""],["collect",""],
							 		["facil",""],["protocols",""]);
									
var resources_subnav 	= new Array(["resOverview",""],["public",""],
									["articles",""],["meetings",""],["otherorgs",""]);
									// gates sub-nav text, removed 29 Jan.07: ["gates",""]
								
var about_subnav   		= new Array(["aboutOverview",""],["who",""],
									// coachescol sub-nav text, removed 29 Jan.07: ["coachescol",""]
									["staff",""], ["employ",""],["directions",""]);

// subnav menu constructor
function subnavMenu(menuId, menuArr, x, y, visible)
{
	this.menuId = menuId;
	this.menuArr = menuArr;
	this.x = x;
	this.y = y;
	this.visible = visible;
	
	this.menuBuilder();
};

subnavMenu.prototype.menuBuilder = function()
{
	var str;
	var s = new getSectionArg();
	
	str =  '<div id="' + this.menuId + '" style="position:absolute; left:' + this.x + 'px; top:' + this.y + 'px;';
	str += ' visibility:' + this.visible + '; z-index:20;">\n';
	
	for(var i = 0; i < this.menuArr.length; i++)
	{
		str += '<a href="index.asp?siteloc=' + this.menuId + '&section=' + this.menuArr[i][0] + '"';
		str += ' onmouseover="keepSubnav()" onmouseout="inactiveSubnav(1000)">';
		str += '<img src="images/subnav_' + this.menuArr[i][0];
		if(s.value == this.menuArr[i][0]) str += '_act.gif " alt="' + this.menuArr[i][1] + '"';
		else str += '.gif " alt="' + this.menuArr[i][1] + '"';
		str += ' name="' + this.menuArr[i][0] + '" id="' + this.menuArr[i][0] + '" width="243" height="19" border="0"';
		if(s.value != this.menuArr[i][0])str += ' onmouseover="return imgSwap(this.name, \'active\')" onmouseout="return imgSwap(this.name, \'inactive\')"';
		str += '>';
		str += '</a>';
		str += '<br>';
	}
	
	str += '</div>';
	document.write(str);
};

// instantiating the subnav menu for each left hand nav selection
var whySmall = new subnavMenu("whysmall", whySmall_subnav, 235, 334, "hidden");
var starting = new subnavMenu("start", starting_subnav, 235, 354, "hidden");
var teaching = new subnavMenu("teaching", teaching_subnav, 235, 354, "hidden");
var smallSchools = new subnavMenu("smallschools", smallSchools_subnav, 235, 374, "hidden");
var tools = new subnavMenu("tool", tools_subnav, 235, 394, "hidden");
var resources = new subnavMenu("resource", resources_subnav, 235, 414, "hidden");
var about = new subnavMenu("aboutus", about_subnav, 235, 434, "hidden");

// using the ttlSubnavArr to hide ALL subnavs
var ttlSubnavArr = new Array(whySmall.menuId, starting.menuId, teaching.menuId, smallSchools.menuId, tools.menuId, resources.menuId, about.menuId);

// init'ing global timer var
var timer;

function inactiveSubnav(msecs)
{
	timer = setTimeout("hideSubnav()",msecs);
};

function keepSubnav()
{
	clearTimeout(timer);
};

function showSubnav(menuId)
{
	hideSubnav();
	var menu = document.getElementById(menuId);
	menu.style.visibility = "visible";
	// showing tranparent layer <-- only if IE
	if(isIE && !isMac) document.getElementById("transLayer").style.visibility = "visible";
	else if(isNN6 && !isMac) document.getElementById("transLayer").style.visibility = "visible";
};

function hideSubnav()
{
	for(var i = 0; i < ttlSubnavArr.length; i++)
	{
		var menu = document.getElementById(ttlSubnavArr[i]);
		menu.style.visibility = "hidden";
	}
	//hiding transparent layer
	if(isIE && !isMac) document.getElementById("transLayer").style.visibility = "hidden";
	else if(isNN6 && !isMac) document.getElementById("transLayer").style.visibility = "hidden";
};

//------------------------------ quote randomizer
// quote image arr
var quoteArr = new 
/* original quotes, changed on 13 Oct. 05 by sbush
Array("baron","eches","fitz","franchini","gering","gregory","har","hartnett","hosford","illg","LEAP","lear","lear1","lear2","lear3","lear4","maynard","mcgean","mcgean1","most1","most2","student","student1","student2","student3","student4","student5","student6","tsa","valentine","vu","wolff");
*/
/* new quotes "installed" on 12 Sept. 06 by sbush */
Array(
		"baron","eches","fitz","franchini","gregory","harwood","hartnett","philbrook","rupprect","tsa","wolff",
		"illg","LEAP","wolfrom","mcfeat","milici",
		"lear","lear1","lear2","lear3","lear4","lear5","lear6","lear7","lear8","lear9","lear10","lear11",
		"mcgean","mcgean1","mcgean2","mcgean3","squires","squires2","karschney","karschney2","jones","hall","hall2",
		"most",
		"P-fir","P-cedar","P-ferrigno","P-morris","A-welch",
		"T-alder1","T-alder2","T-alder3","T-alder4","T-cedar2","T-campbell","T-kristensen","T-silbaugh","T-searle1","T-searle2","T-howell",
		"TL-cedar1","TL-cedar2",
		"student1","student2","student3","student4","student5","S-fir","S-chestnut","S-hemlock","S-rauf","S-williams","S-naylor","S-silva"
	);

function quoteRandomizer() {
	rndQuote = Math.round( Math.random() * quoteArr.length - 1 );
	if( rndQuote == -1 ) rndQuote = 1;
	else rndQuote;
	
	var str;
	str = '<img name="quote" src="images/hdr_quote_';
	str += quoteArr[ rndQuote ];
	str += '.gif" width="397" height="125">';
	document.write(str);
};

function setLoginFormFocus() {
	document.loginForm.Username.focus();
};

function showPageLinks( elementID ) {
	if( document.getElementById || document.all || document.layers ) {
		var hiddenElement = document.getElementById( elementID );
		hiddenElement.style.display = "block";
	}
};
function hidePageLinks( elementID ) {
	if( document.getElementById || document.all || document.layers ) {
		var hiddenElement = document.getElementById( elementID );
		hiddenElement.style.display = "none";
	}
};
