//
// Menu functions for Christians at Work Website
//
// © 2005 Flipside Web Design
// Author: Richard Adams
//
// --- Also prints random photo background
// --- Also resizes main content div block

function resize() {
  if (document.getElementById) {
    var element = document.getElementById('pagecontent')
  }
  else if (document.all) {
    var element = document.all['pagecontent']
  }
  else if (document.layers) {
  var element = document.layers['pagecontent']
  }

  if (document.all) {
    var h = document.body.clientHeight;
  }
  else if (document.layers) {
    var h = window.innerHeight;
  }

element.style.height=h-127;
element.focus();

}

var stayopen = '';
var currentmenu = '';
var menuID = '';
var shadow = '';

function showMenu(menuID) {
  if (currentmenu != '') { stayopen = 0; closeMenu(); }
  if (document.getElementById) {
    var element = document.getElementById(menuID).style
  }
  else if (document.all) {
    var element = document.all[menuID].style
  }
  else if (document.layers) {
    var element = document.layers[menuID]
  }

  element.visibility = 'visible';
  stayopen = 1;
  currentmenu = menuID;
}

function hideMenu(menuID) {
  stayopen = 0;
  if (stayopen == 1) { setTimeout("hideMenu()", 1000); return; }
  if (document.getElementById) {
    var element = document.getElementById(menuID).style
  }
  else if (document.all) {
    var element = document.all[menuID].style
  }
  else if (document.layers) {
    var element = document.layers[menuID]
  }

  setTimeout("closeMenu()", 1000);
  element.stayopen = 0;
}

function closeMenu() {
  if (stayopen == 1) { setTimeout("closeMenu()", 1000); return; }
  if (!currentmenu) { return }
  
  if (document.getElementById) {
    var element = document.getElementById(currentmenu).style
  }
  else if (document.all) {
    var element = document.all[currentmenu].style
  }
  else if (document.layers) {
    var element = document.layers[currentmenu]
  }

  element.visibility = 'hidden';
  currentmenu = '';
}

function printMenu(mypage, wideview) {
// --- Print page header
if (!usr) { usr = 0 }
document.write('<div style="position: absolute; top: 19px; left: 10px"><img src="images/logo.png" alt="" width=188 height=90 border=0 class=pngclear></div>');
document.write('<table cellpadding=0 cellspacing=0 border=0 width=100%>');
document.write('<tr height=28 bgcolor=#0000bb><td colspan=2 align=right><img src="images/cawweb.gif" alt="" width=277 height=20 hspace=4 vspace=4></td></tr>');
document.write('<tr height=70><td colspan=2 background="images/topbg1.png" style="background-repeat: no-repeat"><img src="images/mask.gif" alt="" width=500 height=70 border=0></td></tr>');

// --- Print menu

document.write("<tr height=28 bgcolor=#c7ffab><td colspan=2><table cellpadding=0 cellspacing=0 border=0><tr><td width=200><img src=\"images/mask.gif\" alt=\"\" width=200 height=28 border=0></td>");
document.write("<td>");

if (wideview != 2) {

printMenutab('home', 'Home', 'home.html');
printMenutab('news', 'News & Events', 'news.html');
printMenutab('resources', 'Resources', 'resources');
printMenutab('organisation', 'Organisation', 'organisation.html');
printMenutab('groups', 'Groups', 'groups.html');
printMenutab('donate', 'Donate', 'finances.html');
printMenutab('contactus', 'Contact Us', 'contact');
}

document.write("</tr></table>\n\n");

if (wideview != 2) {

// --- Print sub menus

printMenustart('home', 191, 2);
printMenuitem('home.html', 'Home - Welcome');
printMenuitem('sitemap.html', 'Site Map');
printMenuend();

printMenustart('news', 244, 6);
printMenuitem('resources&restype=News and General Information', 'News & General Information');
printMenuitem('resources&restype=CAW Events', 'CAW Events');
printMenuitem('resources&restype=Net.working', 'Net.working');
printMenuitem('resources&restype=Net.working - Live', 'Net.working - Live');
printMenuitem('resources&restype=Conference Information', 'Conference Information');
printMenuitem('noticeboard&section=Events', 'Members\' Events');
printMenuend();

printMenustart('resources', 355, 9);
printMenuitem('resources', 'Available Resources');
printMenuitem('resources&restype=Conference Talks - mp3', 'Conference Talks - mp3');
printMenuitem('resources&restype=Faith Sharing Ideas', 'Faith Sharing Ideas');
printMenuitem('resources&restype=Articles', 'Articles');
printMenuitem('resources&restype=Bible Studies', 'Bible  Studies');
printMenuitem('resources&restype=Books', 'Books');
printMenuitem('resources&restype=Resources', 'Resources');
printMenuitem('forms.html', 'Forms to download');
printMenuitem('links', 'Links to related websites');
printMenuend();

printMenustart('organisation', 436, 8);
printMenuitem('history.html', 'History');
printMenuitem('basisoffaith.html', 'Basis of Faith');
printMenuitem('council.html', 'The Council');
printMenuitem('team.html', 'Meet the Team');
printMenuitem('panel.html', 'Panel of Reference');
printMenuitem('finances.html', 'Finances & Giving');
printMenuitem('individuals.html', 'Individuals');
printMenuitem('membership.html', 'About Membership');
printMenuend();

printMenustart('groups', 531, 5);
printMenuitem('groupvision.html', 'Our Vision for Workplace Groups ');
printMenuitem('groupstarting.html', 'Starting a Workplace Group ');
printMenuitem('groupdirectory', 'Directory of Workplace Groups ');
printMenuitem('noticeboard', 'Groups Notice Board');
printMenuitem('individuals.html', 'Individuals');
printMenuend();

printMenustart('donate', 592, 1);
// printMenuitem('donate.html', 'Donate online');
printMenuitem('finances.html', 'Finances & Giving');
printMenuend();

printMenustart('contactus', 653, 4);
printMenuitem('contact', 'Contact Form');
printMenuitem('contactdetails.html', 'Contact Details');
printMenuitem('viewvisitorsbook', 'View Visitor\'s Book');
printMenuitem('signvisitorsbook', 'Sign Visitor\'s Book');
printMenuend();


}

// --- Print rest of page header
document.write('<div style="position: absolute; top: 126px; left: 0px; width=100%"><img src="images/topshadow.png" alt="" width=100% height=5 border=0 class=pngclear></div>');
document.write('</table><table cellpadding=0 cellspacing=0 border=0 width=100%><tr valign=top>');
if (wideview) { document.write('<td width=85><img src="images/mask.gif" alt="" width=85 height=300 border=0></td>') }
else { document.write('<td width=275><img src="images/mask.gif" alt="" width=275 height=300 border=0></td>') }
document.write('<td width=90%><table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td>');
document.write('<div id="pagecontent" style="width: 100%; height: 400; padding-right: 6px; overflow: auto; border: none; padding-top: 8px">');

var max = 13;
var bg = Math.floor(Math.random() * max) + 1;
if (wideview) { bg = 0 }
document.write('<style type="text/css">');
document.write('body { background: url("images/bg'+bg+'.jpg"); background-repeat: no-repeat; background-position: 0px 126px }');
// background-attachment: fixed
document.write('</style>');
}

function printMenutab(menuname, menutitle, link) {
document.write("<td nowrap onMouseOver=\"showMenu('" + menuname + "')\" onMouseOut=\"hideMenu('" + menuname + "')\" class=menutab><a href=\"cgi-bin/caw.cgi?usr="+usr+"&page="+link+"\" class=menutab>" + menutitle + "</a>&nbsp;&nbsp;&nbsp;</td>");
}

function printMenustart(menuname, xpos, lines) {
xpos-=5;
var shadowheight = 20 * lines;
shadow = '<td rowspan='+lines+'><img src="images/mlshadow.png" alt="" width=5 height='+shadowheight+' border=0 class=pngclear></td>';
document.write('<div id="'+menuname+'" style="position: absolute; top: 126; left: '+xpos+'; visibility: hidden; z-index: 2" onMouseOver="stayopen=1" onMouseOut="stayopen=0">');
document.write('<table cellpadding=0 cellspacing=0 border=0>');
document.write('<tr height=5><td><img src="images/mtl.png" alt="" width=5 height=5 border=0 class=pngclear></td>');
document.write('<td bgcolor=#c7ffab><img src="images/mask.gif" alt="" width=5 height=5 border=0></td>');
document.write('<td bgcolor=#c7ffab colspan=3><img src="images/mask.gif" alt="" width=100 height=5 border=0></td>');
document.write('<td bgcolor=#c7ffab><img src="images/mask.gif" alt="" width=5 height=5 border=0></td>');
document.write('<td><img src="images/mtr.png" alt="" width=5 height=5 border=0 class=pngclear></td></tr>');
}

function printMenuitem(link, item) {
document.write('<tr><td><img src="images/mask.gif" alt="" width=5 height=5 border=0></td>');
document.write('<td bgcolor=#c7ffab><img src="images/mask.gif" alt="" width=5 height=20 border=0></td>');
document.write('<td colspan=3 class=nav nowrap onClick="top.location=\'caw.cgi?usr='+usr+'&page='+link+'\'" onMouseOver="stayopen=1; this.className=\'navOn\'" onMouseOut="this.className=\'nav\'">&nbsp;<a href="cgi-bin/caw.cgi?usr='+usr+'&page='+link+'" class=menu>'+item+'</a></td>');
document.write('<td bgcolor=#c7ffab><img src="images/mask.gif" alt="" width=5 height=20 border=0></td>');
document.write(shadow+'</tr>');
shadow='';
}

function printMenuend() {
document.write('<tr height=5><td width=5><img src="images/mask.gif" alt="" width=5 height=5 border=0></td>');
document.write('<td width=5><img src="images/mbl.png" alt="" width=5 height=5 border=0 class=pngclear></td>');
document.write('<td bgcolor=#c7ffab colspan=3><img src="images/mask.gif" alt="" width=5 height=5 border=0></td>');
document.write('<td colspan=2 rowspan=2 width=10><img src="images/mbr.png" alt="" width=10 height=10 border=0 class=pngclear></td></tr>');
// Shadow line
document.write('<tr height=5><td colspan=2><img src="images/mask.gif" alt="" width=5 height=5 border=0></td>');
// document.write('<td width=5><img src="images/mblshadow.png" alt="" width=5 height=5 border=0 class=pngclear></td>');
document.write('<td colspan=3><img src="images/mbshadow.png" alt="" width=100% height=5 border=0 class=pngclear></td>');
document.write('</tr>');
// End menu
document.write('</table></div>');
}