// -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 1 -*-
// site.js must be loaded before this.

// Make the header stick?
FIXEDHEADER=0;

MENUOPTIONS = 
    new Array(
	      "Home",CBCOCSITE+"/index",
	      "What's On?",GLENPRIDEAUX+"/songbook/meetings.php3",
	      "FAQ",CBCOCSITE+"/faq.shtml",
	      "Visit Us",CBCOCSITE+"/visit.shtml",
	      "Studies",CBCOCSITE+"/learn.shtml",
//	      "For kids",CBCOCSITE+"/kids.shtml",
	      "Photos",CBCOCSITE+"/photos.shtml",
	      "Tapes", CBCOCSITE + "/tapes/",
//	      "Songs sung", GLENPRIDEAUX + "/songbook/",
          "Roster", CBCOCSITE+"/roster.php",
          "Newsletters", CBCOCSITE+"/newsletters",
          "Address", CBCOCSITE+"/address",
          "Documents", CBCOCSITE+"/documents",
          "eMail Lists", "http://lists.citybeachchurchofchrist.org.au",
	      "Links",CBCOCSITE+"/links.shtml",
	      "Email us",MAILTO
	      );
MAXMENUITEMSPERLINE=8;
MENUWIDTH=600;

 CB_itemPadding=8;

   CB_DOM = (document.getElementById) ? true : false;
   CB_NS4 = (document.layers) ? true : false;
    CB_IE = (document.all) ? true : false;
   CB_IE4 = CB_IE && !CB_DOM;
   CB_Mac = (navigator.appVersion.indexOf("Mac") != -1);
  CB_IE4M = CB_IE4 && CB_Mac;
 CB_Opera = (navigator.userAgent.indexOf("Opera")!=-1);
 CB_Konqueror = (navigator.userAgent.indexOf("Konqueror")!=-1);

function CB_getElementByID(id)
{
  return CB_DOM ? document.getElementById(id) : CB_IE4 ? document.all(id) 
    : eval("window." + id);
}

function CB_windowHeight()
{
  return CB_IE?document.body.clientHeight: window.innerHeight;
}

function resizeScrollBody()
{
  // Need NS5+ or IE4+ 
  if(!CB_NS4 && !CB_Opera) {
    var sb = CB_getElementByID("scrollbody");
    var ht = CB_windowHeight();

//      var showme = "sb.attributes[\"class\"]"
//      for(var x in eval(showme)) 
//  	document.write("<P>"+showme + "." + x + "= )" + eval("("+showme + ")." + x) + "("); 

    if(FIXEDHEADER) {
	ht += - sb.offsetTop - 1;
	if(!CB_IE) ht += -2*CB_itemPadding;
	sb.style.padding=CB_itemPadding+"px";
	sb.style.margin="0px";
	sb.style.height=ht+"px";
    }
    else {
	sb.style.overflow="visible";
    }
  }
}

function setBullet(id, flag)
{
  var theimg = CB_getElementByID(id);

  if(flag==1) {
    //    theimg.src = "bullet-on.gif";
    theimg.src = "bullet-blink.gif";
  }
  else {
    theimg.src = "bullet.gif";
  }
}
function changeimage(id, imagename)
{
  var theimg = CB_getElementByID(id);

    theimg.src = imagename;
}


function MM_preloadImages() 
{
  if (document.images) {
    var imgFiles = MM_preloadImages.arguments;
    if (document.preloadArray==null) 
      document.preloadArray = new Array();
    var i = document.preloadArray.length;
    with (document) {
      for (var j=0; j<imgFiles.length; j++) {
        preloadArray[i] = new Image;
        preloadArray[i++].src = imgFiles[j];
      }
    }
  }
}


// include this function where the menu is to go
function CB_menu(heretitle)
{
    var items, lines, itemsperline, itemsthisline;
    
    items = Math.round(MENUOPTIONS.length/2-.1);
    //    document.write("<P>items="+items);
    lines = Math.round(items/MAXMENUITEMSPERLINE+.49);
    //    document.write("<P>lines="+lines);
    itemsperline = Math.round(items/lines + .49);
    //    document.write("<P>itemsperline="+itemsperline);

    document.write("<DIV class=\"menu\">");
    for(var line=0; line<lines; line++) {
	document.write("<TABLE class=\"menu\" align=\"center\" width="+MENUWIDTH+"><TR>");
	itemsthisline = Math.min(itemsperline, items-line*itemsperline);
	for(var item=0; item < itemsthisline; item++) {
	    if(MENUOPTIONS[(line*itemsperline+item)*2]!=heretitle) {
		document.write("<TD class=\"menuitem\" " +
		       "width=\"" + 100/itemsthisline + "%\" " +
		       "onclick=\"gotohref('"+ 
		       MENUOPTIONS[(line*itemsperline+item)*2+1]
		       +"')\" " +
		       "onmouseover=\"menuhover('menuactive',event)\" " +
		       "onmouseout=\"menuhover('menuitem',event)\" " +
		       ">" +
		       "<A class=\"menuitem\" " +
		       "href=\""+MENUOPTIONS[(line*itemsperline+item)*2+1] +
		       "\" " +
		       "onmouseover=\"menuAhover('menuactive',event)\" " +
		       "onmouseout=\"menuAhover('menuitem',event)\">" +
		       MENUOPTIONS[(line*itemsperline+item)*2] +
		       "</a>"+
		       "</td>"
		       );
	    }
	    else {
		document.write("<TD class=\"menuhere\" " +
		       "width=\"" + 100/itemsthisline + "%\">" +
		       "<SPAN class=\"menuhere\">" +
		       MENUOPTIONS[(line*itemsperline+item)*2] +
		       "</span>"+
		       "</td>\n"
		       );
	    }
	}
	document.write("</tr></table>");
    }
    document.write("</div>");
}

function changeclass(elt,cls)
{
 elt.className = cls;
}

function menuhover(theclass,event)
{
  if(CB_IE) {
    if(event.srcElement)
      changeclass(event.srcElement, theclass);
  }
  else {
    if(event.target.attributes)
      changeclass(event.target,theclass);
  }
}

function menuAhover(theclass,event)
{
 if(CB_IE) {
  if(event.srcElement)
   changeclass(event.srcElement.parentNode, theclass);
 }
 else {
  if(event.target.attributes)
   changeclass(event.target.parentNode,theclass);
  }
}

function gotohref(href)
{
    location.href=href;
}


// include this function where the WFA menu is to go
function WFA_menu(prev, next, contents)
{
    document.write("<DIV class=\"menu\">");
    document.write("<TABLE class=\"menu\" align=\"center\" width="+MENUWIDTH+"><TR>");
    WFA_menuItem(prev,"Previous lesson");
    WFA_menuItem(contents,"Contents");
    if(prev=="") {
	if(contents=="") {
	    WFA_menuItem(next,"Introduction");
	}
	else {
	    WFA_menuItem(next,"First lesson");
	}
    }
    else {
	WFA_menuItem(next,"Next lesson");
    }
    document.write("</tr></table>");
    document.write("</div>");
}

function WFA_menuItem(href, text)
{
    if(href!="") {
      document.write("<TD class=\"menuitem\" " +
	  "width=\"33.33333%\" " +
	  "onclick=\"gotohref('"+ href + "')\" " +
	  "onmouseover=\"menuhover('menuactive',event)\" " +
	  "onmouseout=\"menuhover('menuitem',event)\" " +
	  ">" +
	  "<A class=\"menuitem\" " +
	  "href=\""+ href + "\" " +
	  "onmouseover=\"menuAhover('menuactive',event)\" " +
	  "onmouseout=\"menuAhover('menuitem',event)\">" +
	  text +
	  "</a>"+
	  "</td>"
	  );
    }
    else {
      document.write("<TD class=\"menu\" " +
	  "width=\"33.33333%\">" +
	  "<SPAN class=\"menu\">&nbsp;</span>" +
	  "</td>\n"
	  );
    }
}

function news_menu(prev, next)
{
    document.write("<DIV class=\"menu\">");
    document.write("<TABLE class=\"menu\" align=\"center\" width="+MENUWIDTH+"><TR>");

    WFA_menuItem(prev,"Previous page");
    WFA_menuItem("/newsletters.shtml","Back to Newsletters");
	WFA_menuItem(next,"Next page");

    document.write("</tr></table>");
    document.write("</div>");
}
