function activateMenu(mainMenu) {

    /* currentStyle restricts the Javascript to IE only */
    if (document.getElementById(mainMenu)) {  
        var navroot = document.getElementById(mainMenu);
        
        /* Get all the list items within the menu */
        var lis=navroot.getElementsByTagName("LI");

        for (i=0; i<lis.length; i++) {
           /* If the LI has another menu level */
            if(lis[i].lastChild.tagName=="UL"){
            
                /* assign the function to the LI */
             	lis[i].onmouseover=function() {	

                   this.lastChild.style.display="block";

                   //alert(this.lastChild.tagName);
                   var subList = this.lastChild.getElementsByTagName("LI");
                   for (n = 0; n < subList.length; n++) {
   //                    alert(subList[n].tagName);
   //                    subList[n].style.background-color = "#000000";
                   }

                
                   /* display the inner menu */
                   
                }
                lis[i].onmouseout=function() {                       
                   this.lastChild.style.display="none";
                }
            }
        }
    }
}

function init(){
    activateMenu('mainMenu'); 
    activateMenu('vertnav'); 
}

function registerOnloadFunction(func) {
    if (window.addEventListener)
        window.addEventListener("load", func, false);
    else
        window.attachEvent("onload", func);
}

// ----------------------------------------------
// StyleSwitcher functions written by Paul Sowden
// http://www.idontsmoke.co.uk/ss/
// - - - - - - - - - - - - - - - - - - - - - - -
// For the details, visit ALA:
// http://www.alistapart.com/stories/alternate/
// ----------------------------------------------
  
function setActiveStyleSheet(title, reset) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  if (reset == 1) {
  createCookie("wstyle", title, 365);
  }
}

function setStyle() {
var style = readCookie("wstyle");
if (style != null) {
setActiveStyleSheet(style, 0);
}
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+escape(value)+expires+"; path=/;";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
  }
  return null;
}

//function to open meditation experience popups
function windowPopup(s)
{
  window.open('movie_popup?key='+s, '_blank', 'fullscreen=yes, resizable=no, scrollbars=no, status=no, toolbar=no');
}

function windowPopupDirect(s)
{
  window.open('/media/'+s, '_blank', 'fullscreen=yes, resizable=no, scrollbars=no, status=no, toolbar=no');
}

function MM_preloadImages() { //v3.0
  var d=document;

 if(d.images){
 if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;

 for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
registerOnloadFunction(setStyle);
/*
function correctPNG() 
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "float:right; width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }
   */
//window.attachEvent("onload", correctPNG) - make this validate
//if (window.attachEvent) window.attachEvent("onload", correctPNG);

/**
 * Contains the id of the tab and the currently selected item.
 */
var tabsMap = {};

/**
 * The name of the cookie with the selected identifier. 
 */
var COOKIE_SELECTED_BOOK_TAB_ID_NAME = "bkSelectedBookTabId";



/**
 * Used to hide and show layers and to highlight the currently selected button.
 */
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; }
    obj.display=v; }
  return false;
}

/**
 * Changes the class of an object putting it to 'selected'
 * and unselects another object.
 * @param obj The id of the element that has been selected.
 * @param idSelectedFirst The identifier of the first selected element.
 * @param tabName The name of the group of the tab.
 * @param tabViewName The name of the tab.
 */
function CngClass(obj, idSelectedFirst, tabName, tabViewName){
  if (typeof(obj)=='string') obj=document.getElementById(obj);
  var Lst = tabsMap[tabName]
  if (Lst) {
    Lst.className='';
  }
  else {
    $("#" + idSelectedFirst).removeClass()
  }
  obj.className='selected';
  tabsMap[tabName] = obj;
  if(tabViewName && tabName == "booksTab") {
    createCookie(COOKIE_SELECTED_BOOK_TAB_ID_NAME, tabViewName, 60)
  }
  return false;
}

/**
 * Initializes the left tab in case there is a cookie with state information.
 */
function initLeftTab() {
  var leftTabCookieValue = readCookie(COOKIE_SELECTED_BOOK_TAB_ID_NAME)
  if(leftTabCookieValue) {
    switch(leftTabCookieValue) {
      case "books":
        MM_showHideLayers('books','','show','articles','','hide')
        CngClass(document.getElementById("bookTabsFirst"), 'bookTabsFirst', 'booksTab')
        break;
      case "articles":
        MM_showHideLayers('books','','hide','articles','','show')
        CngClass(document.getElementById("bookTabsSecond"), 'bookTabsFirst', 'booksTab')
        break;
    }
  }
}