/* 
The navigation system.  There are 4 different navigation areas on a page:
primary, secondary, auxilary, and footer.  Each is defined in an array.

There are also two functions: one to display the page header with primary,
secondary, and aux navigation areas; and one to display the page footer with
its navigation area.

The reason for putting the navigation system into Javascript is so that the
menus can be maintained in one place.  In addition, the menu format, text, and 
links will be consistent on all pages throughout the site.
*/

/* Path to the web site */
var sitepath = "http://www.prison.dhamma.org/en/na/";

/* Constructor for the primary, auxiliary, and footer menus */
function menu_xtr (text, link)
{
  this.ptxt = text;
  this.plnk = link;
  return (this);
}

var aux_menu = [
  new menu_xtr("home", sitepath+"index.html"),
  new menu_xtr("about us", sitepath+"about-us.html"),
  new menu_xtr("site map", sitepath+"sitemap.html"),
  new menu_xtr("old students", sitepath+"os/old-students.html"),
  new menu_xtr("contact", sitepath+"contact.html"),
  new menu_xtr("", "")
];

var pri_menu = [
  new menu_xtr("Overview", sitepath+"project-overview.html"),
  new menu_xtr("Requirements", sitepath+"requirements.html"),
  new menu_xtr("Results", sitepath+"results.html"),
  new menu_xtr("Newsroom", sitepath+"newsroom.html"),
  new menu_xtr("Resources", sitepath+"resources.html"),
  new menu_xtr("Donations", sitepath+"donations.html"), 
  new menu_xtr("", "")
];

var foot_menu = [  
  new menu_xtr("home", sitepath+"index.html"),
  new menu_xtr("overview", sitepath+"project-overview.html"),
  new menu_xtr("requirements", sitepath+"requirements.html"),
  new menu_xtr("results", sitepath+"results.html"),
  new menu_xtr("newsroom", sitepath+"newsroom.html"),
  new menu_xtr("resources", sitepath+"resources.html"),
  new menu_xtr("donations", sitepath+"donations.html"),
  new menu_xtr("contact", sitepath+"contact.html"),
  new menu_xtr("", "")
];

/* Constructor for the secondary menus */
function smenu_xtr (menu, item, text, link)
{
  this.sid = menu;
  this.sitm = item;
  this.stxt = text;
  this.slnk = link;
  return (this);
}

/* IDs for the secondary menus.  These must match up with the
primary menu ie there is a secondary menu for each primary menu item.
*/
var HOME = -1; // Indicates  home page or level 1 page is being displayed
var OVERVIEW = 1;
var REQUIREMENTS = 2;
var RESULTS = 3;
var NEWSROOM = 4;  // Not used currently, this menu is a candidate for deletion
var RESOURCES = 5;
var DONATIONS = 6;

/* IDs for the secondary menu items.  The ID lets us display a distinguishing 
   mark on the current page menu item.  The ID's don't have to be kept in order.
   Each secondary menu can have a title too.
   */
var TITLE = -1;
var VIPASSANA = 1;
var HISTORY = 2;
var INTERVIEW = 3;
var FAQ = 4; 
var BOOKSFILMS = 5;
var FACTS = 6;
var GUIDELINES = 7;
var CODE = 8;
var NRFSTUDYA = 9;
var NRFSTUDYB = 10;
var DSONSTUDY = 19;
var EVENTS = 11;
var RPRESS = 12;
var KPRESS = 13;
var NEWS = 14;
var WWC0NTACTS = 15;
var INTNLVIPSITE = 16;
var BROCHURE = 17;
var SNGTALK = 18;

/* This is kind of a hack for static text to appear in the aux nav area instead of links.  
     The code could probably go inline in the table definition below.  The class txtcenter sets
      text-align to center the top padding to 6px and the margin to 0.
*/
var donationtext = '<p class="secMenuText">According to the tradition of pure Vipassana, courses are run solely on a donation basis.</p>';

var sec_menu = [
 new smenu_xtr(OVERVIEW, TITLE, "Overview", ""),
 new smenu_xtr(OVERVIEW, VIPASSANA, "What is Vipassana?", "vipassana.shtml"),
 new smenu_xtr(OVERVIEW, HISTORY, "History", "history.html"),
 new smenu_xtr(OVERVIEW, INTERVIEW, "Interview with Prison Administrator", "http://www.prison.dhamma.org/lminterview.asx"),
 new smenu_xtr(OVERVIEW, FAQ, "Frequently Asked Questions", "faqs.html"),
 new smenu_xtr(REQUIREMENTS, TITLE, "Requirements", ""),
 new smenu_xtr(REQUIREMENTS, FACTS, "Fact Sheet", "fact-sheet.html"),
 new smenu_xtr(REQUIREMENTS, GUIDELINES, "Prison Course Prerequisites and Guidelines", "prison-course-prerequisites.html"),
 new smenu_xtr(REQUIREMENTS, CODE, "Student Code of Discipline for Prison Courses", "student-code-of-discipline.html"),
 new smenu_xtr(RESULTS, TITLE, "Results", ""),
 new smenu_xtr(RESULTS, NRFSTUDYA, "Recidivism Study (2002)", "NRF Recidivism Study 2002.doc"),
 new smenu_xtr(RESULTS, NRFSTUDYB, "Substance Abuse Study (2006)", "NRF Substance Abuse Study 2006.pdf"),
 new smenu_xtr(RESULTS, DSONSTUDY, "Anger Management Study (2002)", "Donaldson Meditation Treatment Study 2002.doc"),
 new smenu_xtr(NEWSROOM, EVENTS, "Events", "events.html"),
 new smenu_xtr(NEWSROOM, RPRESS, "Press Releases", "press-releases.html"),
 new smenu_xtr(NEWSROOM, KPRESS, "Press Kit", "press-kit.html"),
 new smenu_xtr(NEWSROOM, NEWS, "In the News", "in-the-news.html"),
 new smenu_xtr(RESOURCES, TITLE, "Resources", ""),
 new smenu_xtr(RESOURCES, BOOKSFILMS, "Books, Films & Published Articles", "books-films.html"),
 new smenu_xtr(RESOURCES, WWC0NTACTS, "World-Wide Contacts for Prison Courses", 'http://www.prison.dhamma.org/prisonsworldwide.htm" target="_blank'),
 new smenu_xtr(RESOURCES, INTNLVIPSITE, "International Vipassana Website", 'http://www.dhamma.org" target="_blank'),
 new smenu_xtr(RESOURCES, BROCHURE, "Brochure About Prison Courses", 'http://www.prison.dhamma.org/brochure.pdf" target="_blank'),
 new smenu_xtr(RESOURCES, SNGTALK, "S.N. Goenka Inmate Talk", 'http://www.prison.dhamma.org/sngpintro.asx" target="_blank'),
 new smenu_xtr(DONATIONS, TITLE, "Donations", ""),
 new smenu_xtr(DONATIONS, 0, donationtext, ""),
 new smenu_xtr(0, 0, "","")
];

function do_header(menuID, itemID) {
/**************************************************************************************
/* Call this with HOME, HOME on the home page (or any page really)  to display no secondary nav menu.
/* Use one of the menu IDs, HOME on second level pages to get a fully active secondary nav menu.
 /* Use a menu ID, itemID on third level pages to mark and deactivate the link for the current page.
 /* For static text in the menu area, see the DONATIONS definition above.
**************************************************************************************/

	/* Display the auxilary menu  and page header graphic */
	var outxt = 
	'<div id="container">' +
	'<div id="auxNav">' +
	'<ul>';
	var septxt = ">";
	for (var i=0; aux_menu[i].ptxt != ""; i++)
	{
	  outxt += '<li' + septxt + '<a href="'+aux_menu[i].plnk+'">'+aux_menu[i].ptxt+'</a></li>';
	  septxt = ' class="sep">';	
	}
	outxt += '</ul>' + 
	'</div>'+
	'<div id="imageHeader"><img src="' + sitepath +'images/north-american-vipassana-prison-project-header.jpg" />' +
	'</div>';
	document.write (outxt);

	/* If this is a second or third level page, display the secondary menu.  
	    Second level pages have links for all items in the menu, while third level 
	     pages display a marker image (an arrow) in front of static text
	     for the item for the current page.  Menus can have a title too.
	*/
	if (menuID != HOME)
	{
	  outxt = '<div id="rightColumn">' +
	  '<div id="rightColumnNav">' +
	  '<ul>';
	  for (i=0; sec_menu[i].sid != 0; i++)
	    if (sec_menu[i].sid == menuID)         // This is an item for the current menu
		  if (sec_menu[i].sitm == TITLE)       // The item is the title for the menu
		    outxt += '<p class="secMenuTitle">' + sec_menu[i].stxt + '</p>';
		  else if (sec_menu[i].sitm == itemID) // The item is in fact the current item and needs the marker image and no link
		    outxt += '<li class="current">' + sec_menu[i].stxt + '</li>';
		  else if (sec_menu[i].slnk != "")     // The item is not the current item and needs a link
	        outxt += '<li><a href="' + sec_menu[i].slnk+'">'+ sec_menu[i].stxt + '</a></li>';
		  else                                 // Not a menu item, just static text to display
	        outxt += '<li>' + sec_menu[i].stxt + '</li>';
		  
	  outxt += '</ul>' + '</div>' + '</div>';
	  document.write (outxt);
	}
	
	/* Display the primary menu */
	outxt = '<div id="primaryNav">' + '<ul>';
	for (i=0; pri_menu[i].ptxt != ""; i++)
	  outxt += '<li><a href="'+pri_menu[i].plnk+'">'+pri_menu[i].ptxt+'</a></li>';
	outxt += '</ul>' + '</div>';
	document.write (outxt);
}

function do_footer() {
	/* Display the micro links */
	var outxt =
	'<div id="primaryNavMicro">' + '<ul>';
	var septxt = '>';
	for (var j=0; foot_menu[j].ptxt != ""; j++)
	{
	  outxt += '<li' + septxt + '<a href="'+foot_menu[j].plnk+'">'+foot_menu[j].ptxt+'</a></li>';
	  septxt = ' class="sep">';	
	}
	outxt += '</ul>' + '</div>';
	document.write (outxt);

	/* Display the footer information */
	outxt = 
	'<div id="footer">' +
	'For information on Vipassana prison courses world-wide visit <a href="http://www.prison.dhamma.org" target="_blank">www.prison.dhamma.org</a>' +
	'<span class="copyright"><a href="' + sitepath + 'privacy-policy.shtml">privacy policy</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; copyright 1993 - 2008' +
	'</span></div>';
	document.write (outxt);
}
