
// JAVASCRIPT MENU [writes: 1-level vertical menu]
//============================================================
//	TO: Set Navigation Menu Properties - syntax:  
//	M.AddItem('CAPTION','URL');
//	CAPTION: what caption appears in the menu cell
//	URL: url of what document is loaded or empty
//  (MENU SETTINGS FOUND AT THE END OF THE DOCUMENT)  
//============================================================
// New Menu Object: SETTINGS
var M=new Menu();
var CurrentLocation=window.location.href;
var CurrentHost = window.location.host;
var CurrentProtocol = window.location.protocol;

// name of root folder: NOTE: leave empty if root directory = domain name
// path from domain name to root of site otherwise
M.rootDirectory='';        // NULL for production , else /test9
M.SelectedClass='selected';
M.UnselectedClass='unselected';
M.HoverClass='mouseover';
// path of left-end image for unselected menu item:
M.UnselectedImageSRC= CurrentProtocol + '//' + CurrentHost + M.rootDirectory + '/' + 'images/unselected.gif';
// path of left-end image for selected menu item:
M.SelectedImageSRC= CurrentProtocol + '//' + CurrentHost + M.rootDirectory + '/' +'images/selected.gif';
// path of left-end image for mouseover of menu item:
M.HoverImageSRC= CurrentProtocol + '//' + CurrentHost + M.rootDirectory + '/' + 'images/highlight.gif';
// width of left-end image for selected menu item:
M.ImageX=30;
// height of left-end image for mouseover of menu item:
M.ImageY=40;

//============================================================
// Left-side Image Objects (caching):

// create image objects:
function createImageObj(src) {
	if (document.images) {
		img = new Image();
		img.src = src;
		return img;
	}
}

// precache mouseover images:
var preloaded = false;
function preloadImages() {
	if (document.images) {		
    UnselectedImage=createImageObj(M.UnselectedImageSRC);
    SelectedImage=createImageObj(M.SelectedImageSRC);
    HoverImage=createImageObj(M.HoverImageSRC);
    preloaded = true;
	}
}

// Add Object Item:
function AddMenuItem(caption,url) {
	var newItem=new AddProperties(caption,url);
	M.items[M.items.length]=newItem;
}

// function prototype: adds menu items
Menu.prototype.AddItem = AddMenuItem;
// function prototype: adds menu items
Menu.prototype.MakeMenu = MakeNewMenu;

// Add Object Item Properties:
function AddProperties(Caption,URL){
	this.caption=Caption;
	this.url=URL;
	this.selected=CheckURL(URL);
}

// Add Menu Items Array to Object:
function Menu() {
	this.items=new Array();
}

// Write Menu to Browser:
function WriteMenu() {
	document.write(M.MakeMenu());
}

// Write Menu to String:  
function MakeNewMenu(){ 
	var CurrentLocation=window.location.href;
	var CurrentHost = window.location.host;
	var CurrentProtocol = window.location.protocol;
	// create output string:
		var Result='<table width="150" summary="Navigation Menu Table" cellspacing="0" cellpadding="0" border="0" class="menu">';
		for(i=0;i<M.items.length;i++){
				M.ImageId
				Result+='<tr><td width="'+M.ImageX+'"><img name="ImageId_'+i;
				if (M.items[i].selected){Result+='" alt="" src="'+M.SelectedImageSRC;}
				else {Result+='" alt="" src="'+M.UnselectedImageSRC;} 
				Result+='" height="'+M.ImageY; 
				Result+='" width="'+M.ImageX; 
				Result+='" /></td><td width="120" id="Id_'+i;
				Result+='" onclick="document.location=\'' + CurrentProtocol + '//' + CurrentHost + M.rootDirectory + '/' + M.items[i].url; 
				Result+= '\'" onmouseover="MouseHover(this);"';
				if (M.items[i].selected){Result+=' class="'+M.SelectedClass;}
				else {Result+=' class="'+M.UnselectedClass;} 
				Result+= '" onmouseout="MouseHover(this);"><a ';
				Result+=' id="AnchorId_' + i; 
				if (M.items[i].selected){Result+='" class="'+M.SelectedClass;}
				else {Result+='" class="'+M.UnselectedClass;}
				Result+='" href="' + CurrentProtocol + '//' + CurrentHost + M.rootDirectory + '/' + M.items[i].url;
				Result+='">' + this.items[i].caption + '</a></td></tr>';
			}	
			Result+='</table>';
	 		// alertHTML(Result); 
			return Result;
}

// Check Current URL with Menu:
function CheckURL(URL) { 
	// Current Relative URL:
	var CurrentLocation=window.location.href;
	var CurrentHost = window.location.host;
	var CurrentProtocol = window.location.protocol;
	var RelativePath=URL;
	var TestURL = CurrentProtocol + '//' + CurrentHost + M.rootDirectory + '/' + RelativePath;
	//alert(TestURL + ' - ' + CurrentLocation);

	// Test Menu URL with Current Location URL:
	if (TestURL == CurrentLocation){return true;}
	else {return false;}
}

// Menu Mouse Hover:
function MouseHover(MenuItem) {
	var AnchorObject=document.getElementById('Anchor'+MenuItem.id);
	if ((document.images)	&&(preloaded)) {
		if (MenuItem.className==M.UnselectedClass) {
			//alert('image' + ImageObject + ' Anchor' + AnchorObject);
			if (AnchorObject!=null) {
				document.images['Image'+MenuItem.id].src=HoverImage.src;
				AnchorObject.className=M.HoverClass;
				MenuItem.className=M.HoverClass;
			}
			else {
		//		alert('SOURCE: \'image - '+ImageObject.src + 
		//		' Anchor - '+AnchorObject.id+'\' is an Unspecified\n OBJECT.');
			} 
			return;
		}
		if (MenuItem.className==M.HoverClass) {
			if (AnchorObject!=null) {
				document.images['Image'+MenuItem.id].src=UnselectedImage.src;
				AnchorObject.className=M.UnselectedClass;
				MenuItem.className=M.UnselectedClass;
			}
			else {
					//alert('SOURCE: \'image - '+ImageObject.src + 
			//	' Anchor - '+AnchorObject.id+'\' is an Unspecified\n OBJECT.');
			}
			return;
		}
		if (MenuItem.className==M.SelectedClass) {
			document.images['Image'+MenuItem.id].src=SelectedImage.src; return;
		}
		else {
			alert('CLASS: \'' + MenuItem.className + '\' is an Unspecified\n Class Name for the Menu.');
		}
	}
}

// DEBUG - display menu markup
function alertHTML(Output) {
	var formattedHTML=Output.replace(/\x3Ca/g, '\n\t<a');
	formattedHTML=formattedHTML.replace(/\x3E\x3C\/a/g, '>\n\t</a');
	alert(formattedHTML);
}

//============================================================
// * ENTER MENU SETTINGS HERE: *
// SYNTAX: M.AddItem([CAPTION],[RELATIVE URL]);
// NOTE: leave index.htm(l) relative url empty { i.e. M.AddItem('Index Page', ''); }
// ------------------------------------------------
M.AddItem('Welcome','welcome.html');
// M.AddItem('About the Schools Institute','about_si.html');
M.AddItem('Products','products/index.html');
M.AddItem('Services','services/index.html');
M.AddItem('Schools Toolkit','toolkit/index.html');
M.AddItem('Effective Schooling','effective/index.html');
M.AddItem('File Exchange','fileexchange/index.html');
M.AddItem('Contact','contact.html');
//============================================================
