//
//	This is the table of contents for the entire site, as it is reflected in the
//	menu on the right-hand side.  The menu will be dynamically written into the pag
//	using scripts.
//

var _tableOfContents = [
	{indent:0, title:"Path to Sustainability", page:"ssp_index.html"},
		{indent:1, title:"Vision", page:"ssp_vision.html"},
		{indent:1, title:"Program Description", page:"ssp_description.html"},
		{indent:1, title:"Participation", page:"ssp_participation.html"},
//			{indent:2, title:"Program Curriculum", page:"ssp_curriculum.html"},
//			{indent:2, title:"Calendar of Events", page:"ssp_calendar.html"},
		{indent:1, title:"Registration", page:"ssp_register.php"},
		{indent:1, title:"Coaches and Volunteers", page:"ssp_coaches.html"},
			{indent:2, title:"Coaching Guidelines", page:"ssp_coaches_guidelines.html"},
			{indent:2, title:"Become a Coach/Volunteer", page:"ssp_coaches_become.html"},
		{indent:1, title:"Contact Information", page:"ssp_contact.html"},
		{indent:1, title:"The Team", page:"ssp_team.html"},
//		{indent:1, title:"Corporate Sponshorship", page:"ssp_sponsorship.html"},
//		{indent:1, title:"Press Releases", page:"ssp_press.html"},
//		{indent:1, title:"Media", page:"ssp_media.html"},
	{indent:0, title:"Power Manifestation", page:"manifestation_rainforest.html"},
//		{indent:1, title:"How To Manifest", page:"manifestation_how_to.html"},
		{indent:1, title:"The Rainforest", page:"manifestation_rainforest.html"},
//			{indent:2, title:"Previous Manifestations", page:"manifestation_rainforest_prev.html"},
//		{indent:1, title:"Research", page:"manifestation_research.html"},
//			{indent:2, title:"Global Conciousness", page:"manifestation_research_global.html"},
//			{indent:2, title:"Prayer", page:"manifestation_research_prayer.html"},
//			{indent:2, title:"Manifestation", page:"manifestation_research_manifestation.html"},
//			{indent:2, title:"Physics", page:"manifestation_research_physics.html"},
//			{indent:2, title:"Internal Emotional Body", page:"manifestation_research_internal.html"},
//			{indent:2, title:"Links", page:"manifestation_research_links.html"},
	{indent:0, title:"Abundance Coaching", page:"abundance_what.html"},
		{indent:1, title:"What is it?", page:"abundance_what.html"},
//		{indent:1, title:"Personal Coaching", page:"abundance_personal.html"},
//		{indent:1, title:"Group Coaching", page:"abundance_group.html"},
		{indent:1, title:"About Zen", page:"abundance_about_zen.html"},
	{indent:0, title:"Workshops &amp; Events", page:"workshop2_index.htm"},
		{indent:1, title:"Power Manifestation Formula", page:"workshop2_index.htm"},
//		{indent:1, title:"Events", page:"workshop_events.html"},
	{indent:0, title:"Travel", page:"travel_damanhur_update.html"},
		{indent:1, title:"Damanhur, Italy", page:"travel_damanhur_update.html"}
//	{indent:0, title:"Support the Vision", page:"support_index.html"},
//		{indent:1, title:"Ways to help", page:"support_to_help.html"},
//		{indent:1, title:"Reach Out", page:"support_reach_out.html"},
//		{indent:1, title:"Projects to Support", page:"support_projects.html"},
//		{indent:1, title:"Donate", page:"support_donate.html"},
//	{indent:0, title:"Recommended", page:"recommended_index.html"},
//		{indent:1, title:"Books", page:"recommended_books.html"},
//		{indent:1, title:"Music", page:"recommended_music.html"},
//		{indent:1, title:"Products", page:"recommended_products.html"},
//		{indent:1, title:"Workbook", page:"recommended_workbook.html"}
]

var _selectedPageName, _selectedPage, _selectedSection;

//
//	Figure out the _selectedPage and _selectedSection based on the URL of this page.
//	This affects how the menu is drawn and the title of the page.
//
//
function getSelectedPage() {
	var url = document.location.href.split("/"),
		page = url[url.length - 1]
	;
	if (page.indexOf("?") > 0) {
		page = page.substring(0, page.indexOf("?"));
	}
	if (page.indexOf("#") > 0) {
		page = page.substring(0, page.indexOf("#"));
	}

	_selectedPageName = page;
	
	_selectedPage = null;
	for (var i = _tableOfContents.length - 1; i >= 0; i--) {
		var item = _tableOfContents[i];
		if (item.page == page) {
			_selectedPage = item;
			break;
		}
	}

	if (_selectedPage && _selectedPage.indent == 0) {
		_selectedSection = _selectedPage;
	} else {
		if (_selectedPage != null) {
			for (i = i-1; i >= 0; i--) {
				var item = _tableOfContents[i];
				if (item.indent == 0) {
					_selectedSection = item;
					break;
				}
			}
		}
	}
}

getSelectedPage();

//
//	routine to output the table of contents, based on the _tableOfContents, above
//	
function outputTableOfContents() {
	var output = [outputTOCGroupStart()],
		skipSection = true
	;
	for (var i = 0; i < _tableOfContents.length; i++) {
		var item = _tableOfContents[i];
		if (item.indent == 0) {
			skipSection = (_selectedSection != item);
			output[output.length] = outputTOCSection(item, i == 0);
		} else {
			if (skipSection != true) {
				output[output.length] = outputTOCSubsection(item, (_selectedPage == item ? "subNavSelected" : "subNav"));
			}
		}
	}
	
	output[output.length] = outputTOCGroupEnd();

	if (window._outputLogin) {
		output[output.length] =  outputLoginBox();
	}

	if (window._outputLeftInset) {
		output[output.length] =  outputLeftInsetBox();
	}

	return output.join("");
}


function outputTOCGroupStart() {
	return "<TABLE WIDTH=184 BORDER=0 CELLSPACING=0 CELLPADDING=0>"
}
function outputTOCGroupEnd() {
	return [
		"<tr>",
			"<td valign='top'><img src='/_media/_nav/corner_bottom_left.gif' width='12' height='8'></td>",
			"<td align='left' valign='top'><img src='/_media/_nav/edge_bottom.gif' width='170' height='8'></td>",
			"<td valign='top'><img src='/_media/_nav/corner_bottom_right.gif' width='12' height='8'></td>",
		"</tr>",
		"</TABLE>"
	].join("");
}

function outputTOCSection(item, topOfSection) {
	var cornerNum = (topOfSection ? 1 : 2),
		height = (item.height != null ? item.height : 26),
		output = [
		"<TR><td rowspan=2><img src='/_media/_nav/corner_left", cornerNum, ".gif' width='12' height='26'>",
			(height > 26 ? "<BR><IMG src='/_media/_nav/edge_left.gif' width='12' height='"+ (height-26)+ "'>" : ""),
			"</td>",
			"<td align='center' valign='top'><img src='/_media/_nav/edge_top.gif' width='170' height=5></td>",
			"<td ALIGN=right rowspan=2><img src='/_media/_nav/corner_right", cornerNum, ".gif' width='12' height='26'>",
				(height > 26 ? "<BR><IMG src='/_media/_nav/edge_right.gif' width='12' height='"+ (height-26)+ "'>" : ""),
			"</td>",
		"</TR>\r",
		"<TR>", 
			"<td align='left' valign='top'>", 
				(item.page ? "<a href='/"+ item.page+ "'>" : ""),
				"<B>", item.title, "</B>",
				(item.page ? "</a>" : ""),
		"</td></TR>\r"
	]
	return output.join("");
}

function outputTOCSubsection(item, cssClass) {
	if (cssClass == null) cssClass = 'normal';
	var height = (item.height != null ? item.height : 20),
		output = [
		"<TR><td><img src='/_media/_nav/edge_left.gif' width='12' height='", height, "'></td>",
			"<td CLASS=", cssClass, ">",(item.indent == 2 ? "&nbsp;&nbsp;&nbsp;&nbsp;" : ""),
				(item.page ? "<a href='/"+ item.page+ "'>" : ""), 
				item.title, 
				(item.page ? "</a>" : ""),
			"</td>",
			"<td><img src='/_media/_nav/edge_right.gif' width='12' height='", height, "'></td>",
		"</TR>"
	]
	return output.join("");
}


function outputLoginBox() {
	var output = [ 
		"<BR>",
		outputTOCGroupStart(),
		outputTOCSection({title:"Log In"}, true),
		outputTOCSubsection({title:"<NOBR><FORM action=\"/community/?q=user/login\" method=\"post\">"
							   +"Username:<BR>&nbsp;<INPUT TYPE='text' NAME='edit[name]' SIZE=23>"
							   +"<BR>Password:<BR>&nbsp;<INPUT TYPE='password' name='edit[pass]' SIZE=23>"
							   +"<BR>&nbsp;<INPUT TYPE=submit Value='Log In'></FORM></NOBR>",
							height:120}),
		outputTOCGroupEnd()	
	];
	return output.join("");
}


function outputLeftInsetBox() {
	var output = [ 
		"<BR>",
		outputTOCGroupStart(),
		outputTOCSection({title:_leftInsetItem.title, height:_leftInsetItem.titleHeight}, true),
		outputTOCSubsection({title:_leftInsetItem.contents,
							height:_leftInsetItem.height}),
		outputTOCGroupEnd()	
	];
	return output.join("");
}

//
//	routine to output the header of the page, including the stylesheet and TOC
//	
function writePageHeader() {
	var title =  (_selectedPage != null ? " :: " + _selectedPage.title : "") 
				+(_selectedSection != null && _selectedSection != _selectedPage ? " :: " + _selectedSection.title : "")  
				+ " :: SmartSoul ::",
		output = [
		"<TITLE>", title, "</TITLE>",
		"<link REL=stylesheet type='text/css' href='/_css/style.css'>",
		"</HEAD>",
		"<body bgcolor='#660000' leftmargin='0' tomanifestation_argin='0' marginwidth='0' marginheight='0'>",
		"<table WIDTH=784 border=0' align='center' cellpadding='0' cellspacing='0'>",
			"<tr> ",
				"<td COLSPAN=7 align='center' valign='top'><A HREF='/index.html'><img src='/_media/header.jpg' width='784' height='185' BORDER=0></A></td>",
			"</tr>",
			"<tr> ",
				"<td WIDTH=24  bgcolor='#660000' ROWSPAN=4><img src='/_media/_spacer.gif' width='24' height='8'></td>",
				"<td WIDTH=5   bgcolor='#FFFFF0'   ROWSPAN=3><img src='/_media/_spacer.gif' width='5' height='8'></td>",
				"<td WIDTH=200 bgcolor='#FFFFF0'><img src='/_media/_spacer.gif' width='200' height='8'></td>",
				"<td WIDTH=10  bgcolor='#FFFFF0'   ROWSPAN=3><img src='/_media/_spacer.gif' width='10' height='8'></td>",
				"<td WIDTH=506 bgcolor='#FFFFF0'><img src='/_media/_spacer.gif' width='506' height='8'></td>",
				"<td WIDTH=10  bgcolor='#FFFFF0'   ROWSPAN=3><img src='/_media/_spacer.gif' width='10' height='8'></td>",
				"<td WIDTH=24  bgcolor='#660000' ROWSPAN=4><img src='/_media/_spacer.gif' width='24' height='8'></td>",
			"</TR>",
			"<tr> ",
				"<td VALIGN=top bgcolor='#FFFFF0'>",
						outputTableOfContents(),
				"</td>",
				"<td VALIGN=top bgcolor='#FFFFF0' align='left' valign='top'>"
	];
	document.write(output.join(""));
}

//
//	routine to output the footer of the page
//	
function writePageFooter() {
	var output = [
				"</td>",
			"</tr>",
			"<TR><TD BGCOLOR=#FFFFF0>&nbsp;</TD><TD BGCOLOR=#FFFFF0>&nbsp;<BR><BR></TD></TR>",
			"<TR><TD COLSPAN=5>",
				"<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><TD WIDTH=50% CLASS=reverse HEIGHT=30 ALIGN=LEFT VALIGN=CENTER>",
					"&nbsp;&nbsp;&nbsp;<A CLASS=reverse HREF='mailto:info@smartsoul.com'>Contact Us</A>&nbsp;&nbsp;&nbsp;",
					"&nbsp;&nbsp;&nbsp;<A CLASS=reverse HREF='mailto:webmaster@smartsoul.com'>Problems with this site?</A>&nbsp;&nbsp;&nbsp;",
					"<TD WIDTH=50% CLASS=reverseDark ALIGN=RIGHT VALIGN=CENTER>Copyright &copy; 2003 SmartSoul LLC,  All Rights Reserved",
				"</TD></TR></TABLE>",
				"</TD></TR>",

		"</table>",
		"<BR><BR><BR>",
		"</body></html>"
	];
	document.write(output.join(""));
}



//
//	routine to write out a page header, like on the home page
//
function outputPageSection(title) {
	var output = [
		"<TABLE WIDTH=500 CELLSPACING=0 CELLPADDING=0>",
		"<TR><TD COLSPAN=4 BGCOLOR=black><IMG SRC='/_media/spacer.gif' WIDTH=2 HEIGHT=1></TD></TR>",
		"<TR>",
		"<TD BACKGROUND='/_media/title_corner_l.gif'><IMG SRC='/_media/_spacer.gif' WIDTH=28 HEIGHT=28></TD>",
		"<TD VALIGN=TOP><DIV CLASS=home_section_head>",
			"<DIV CLASS=home_section_shadow><NOBR>", title, "</NOBR></DIV>",
			"<DIV CLASS=home_section_text><NOBR>", title, "</NOBR></DIV>",
		"</DIV></TD>",
		"<TD BACKGROUND='/_media/title_corner_r.gif'><IMG SRC='/_media/_spacer.gif' WIDTH=28 HEIGHT=28></TD>",
		"<TD WIDTH=100%>&nbsp;</TD>",
		"</TR></TABLE><BR>"
	];
	
	return output.join("");
}

function writePageSection(title) {
	document.write(outputPageSection(title));
}
