// javascript Camp Barakel menus & misc.

//  add info for a drop down item
//  'text' displayable text
//  'link' hyperlink relative to top directory
function addMenuInfo(text, link)
{
	if (!this.menu)
		this.menu = new Array();

	this.menu[this.dropCount] = new Array();
	this.menu[this.dropCount].text = text;
	this.menu[this.dropCount].link = link;
	this.dropCount++;
}

var rPre = '';
var cbLinks = new Array();
function cbLink(htm)
{
	this.htm = htm;
	this.menu = false;
	this.dropCount = 0;
	this.addMenuInfo = addMenuInfo;
}

var bSmallScreen = false;
if (document.documentElement) {
	if (screen.width && (screen.width < 700)) {
		bSmallScreen = true;
	}
}

if (bSmallScreen) {
	cbLinks['Home'] = new cbLink('c2.asp');
} else {
	cbLinks['Home'] = new cbLink('camp.asp');
}

//Contents for "Camps & Retreats" menu.
cbLinks['Camps & Retreats'] = new cbLink('cr/sched.asp');
cbLinks['Camps & Retreats'].addMenuInfo('Schedule', 'cr/sched.asp');
cbLinks['Camps & Retreats'].addMenuInfo('Camp Openings', 'cr/sched.asp');
cbLinks['Camps & Retreats'].addMenuInfo('Children', 'cr/kids.asp');
cbLinks['Camps & Retreats'].addMenuInfo('Teens', 'cr/teens.asp');
cbLinks['Camps & Retreats'].addMenuInfo('Adults', 'cr/adults.asp');
cbLinks['Camps & Retreats'].addMenuInfo('Chapel Podcasts', 'audio/audio.asp');

//Contents for the "About Us" menu.
cbLinks['About Us'] = new cbLink('about/about.asp');
cbLinks['About Us'].addMenuInfo('About', 'about/about.asp');
cbLinks['About Us'].addMenuInfo('History', 'heritage.htm');
cbLinks['About Us'].addMenuInfo('Tour', 'tour/tour.asp');
cbLinks['About Us'].addMenuInfo('Directions', 'dir3.htm');
cbLinks['About Us'].addMenuInfo('Contact', 'about/contact.asp');
cbLinks['About Us'].addMenuInfo('News & Events', 'ne/ne.asp');
cbLinks['About Us'].addMenuInfo('Encouragement', 'about/encourage.asp');

//Contents for "Staff" menu.
cbLinks['Staff'] = new cbLink('staff_pages/staff.asp');
cbLinks['Staff'].addMenuInfo('Resident', 'staff_pages/staff.asp');
cbLinks['Staff'].addMenuInfo('High School', 'ststaff/hsstaff.asp');
cbLinks['Staff'].addMenuInfo('College', 'ststaff/college_age_staff.htm');
cbLinks['Staff'].addMenuInfo('Adult', 'ststaff/adult_staff.htm');
cbLinks['Staff'].addMenuInfo('Work Groups', 'ststaff/work_groups.htm');
cbLinks['Staff'].addMenuInfo('Prayer', 'praying.htm');

//Contents for "S'More" menu.
cbLinks["S More"] = new cbLink('smore/pictures.asp');
cbLinks["S More"].addMenuInfo('Pictures','smore/pictures.asp');
cbLinks["S More"].addMenuInfo('Wallpaper','smore/wallpaper.asp');
cbLinks["S More"].addMenuInfo('Song List','smore/music.htm');
cbLinks["S More"].addMenuInfo('Camp Song','smore/song.asp');
cbLinks["S More"].addMenuInfo('Barakel Book','smore/bbook1.htm');
cbLinks["S More"].menuText = "S'More";

// 256 color-safe colors, hiColor versions below
var menuColor = "#336633";
var menuHighlightColor="#000000";

var pgBgColor="#005000";

// mouse goes over TD element
function mover(td, name, e)
{
	if (!document.documentElement)
		return;

	td.style.backgroundColor = menuHighlightColor;
	td.style.border = '2px outset #cccccc';
	td.style.backgroundImage = 'url(\'/pics/mcrv2.png\')';
	td.style.backgroundPosition = 'bottom';
	td.style.backgroundRepeat = 'repeat-x';
	if (cbLinks[name].menu)
	{
		dropdownmenu(td, e, cbLinks[name].menu);
	}
}

// mouse goes out of TD element
function mout(td)
{
	if (!document.documentElement)
		return;

	td.style.backgroundColor = menuColor;
	td.style.border = '2px outset white';
	td.style.backgroundImage = 'url(\'/pics/mcrv.png\')';
	td.style.backgroundPosition = 'top';
	td.style.backgroundRepeat = 'repeat-x';
	delayhidemenu();
}

// mouse click on TD element with name 'name'
function mclick(name)
{
	top.location.href = cbLinks[name].htm;
}

// produce one menu link
function doLink(name)
{
	if (!cbLinks[name])
		return;

	var menuText = name;

	if (cbLinks[name].menuText)
	{
		// a special case where the text we want to display
		// isn't just the name of the cbLink
		menuText = cbLinks[name].menuText;
	}

	document.write(
		'<td align=center id="cbuth"' +
		' onmouseover="mover(this,\'' + name + '\',event)"' +
		' onmouseout="mout(this)"' +
		' onclick="mclick(\'' + name + '\')"' +
		'>' + menuText + '</td>');
	document.write('<TD>' +
				   '<img src="/pics/spacer.gif" width=1></TD>');
}

// produce the whole CB main menu
function doMenu()
{
	// begin the table for the menu, first outer table
	// taking up the whole available width
	document.write('<table' +
				   ' cellspacing=0' +
				   ' id="cbMenuTableId"' +
				   ' cellpadding=0 border=0 width="100%"><TR>' +
				   '<TD align=CENTER>');
	document.write('<table ' +
				   ' bgcolor="' + menuColor + '"' +
				   ' style="background-image:url(\'' +
				   '/pics/mcrv.png\');background-position:top;' +
				   'background-repeat:repeat-x"' +
				   ' border=0' +
				   ' align=center' +
				   ' cellspacing=0' +
				   ' cellpadding=0' +
				   '><TR>');

	doLink('Home');
	doLink('Camps & Retreats');
	doLink('About Us');
	doLink('Staff');
	doLink("S More");
	document.write('</TR></table>');

	document.write('</TD></TR></table>');
}

// if the user is browsing with a high-color monitor,
// give them nicer colors.
function decideColors()
{
	if (lotsaColors() && document.documentElement)
	{
		var b = document.getElementsByTagName('body');
		if (b)
		{
			menuColor = "#2c5329";
			menuHighlightColor="#244222";

			//b[0].style.backgroundColor= pgBgColor;
			if (document.all && b[0].filters && b[0].filters[0])
			{
				b[0].filters[0].Enabled = true;
			}
		}
	}
}

// Adjust the link URL's to take care of where this page is
// in the directory structure.
function adjustLinks(pre)
{
	 if (!pre || (pre == ''))
		  return;

	 rPre = pre;
	 var cbl;
	 for (cbl in cbLinks)
	 {
		  cbLinks[cbl].htm = pre + cbLinks[cbl].htm;
	 }
}

var strFadingImgID = 'lakepic';
var mainLakePic = 'pics/LakeFall.jpg';
var strFadingImgDefault = mainLakePic;

// Generate everything (the header) to start off the page.
//  (this version has no Nav headers)
//
//  rPre1 - relative prefix to home for this page's links
//				(if this page is one level below home, prefix is '../')
//  noMenu - if true, do not display the drop-down nav-menu.
function doHeader2(rPre1, noMenu, bDoBannerPhotoFading, noPicture)
{
	decideColors();

	if (rPre1)
	{
		var cbl;
		rPre = new String(rPre1);
		adjustLinks(rPre);
	}
	else
	{
		rPre = '';
	}

	// This "dropmenudiv" DIV is where the menu will go.
	document.write('<div id="dropmenudiv" style="visibility:hidden;'+
				   'background-color:'+menubgcolor+
				   ';background-image:url(\'/pics/mcrv.png\');' +
				   '" onMouseover="clearhidemenu()"' +
				   ' onMouseout="dynamichide(event)"></div>');

	// begin main body table.  WIDTH=800 pixels
    document.write('<table width=800 id="cbmTbl"' +
				   ' align=center' +
				   ' style="margin-left:auto;margin-right:auto"' +
				   ' cellspacing=0 cellpadding=0 border=0>');

	document.write('<tr><td>' +
				   '<img src="/pics/spacer.gif" height=6 width=1>' +
				   '</td></tr>');

	// put header logo and picture in a table
	var picture = '<tr><td align=center>' +
		'<table border=0' +
		' cellspacing=0 cellpadding=0><TR>' +
		'<td width=280 align=center valign=middle>' +
		'<a href="' + cbLinks['Home'].htm + '" title="Camp Barakel Home">' +
		'<img src="/pics/cblogo.gif" border=0></a>' +
		'</td>' +
		'<td align=center>' +
		'<img src="/' + mainLakePic + '" height=160 width=485' +
		' id="lakepic"' +
		' ></td>' +
		'</tr></table>' +
		'</td></tr>';

	if (!noPicture)
		document.write(picture);

	if (!noMenu)
	{
		// one row of solid border before menu.
		document.write('<tr><td>' +
					   '<img src="/pics/spacer.gif" height=8>' +
					   '</td></tr>');

		document.write('<tr><td align=center>');
		doMenu();
		document.write('</td></tr>'); // end the menu TD cell and row
	}

	// one row of solid border before page content.
	document.write('<tr><td>' +
				   '<img src="/pics/spacer.gif" height=9>' +
				   '</td></tr>');

	// one row of curved corners on the top
	document.write('<tr><td>' +
				   '<table border=0 cellpadding=0 cellspacing=0' +
				   ' width="100%">' +
				   '<TR><TD width=10>' +
				   '<img width=10' +
				   ' src="/pics/ulft_corner.gif"></TD>' +
				   '<td' +
				   ' style="border-top: 1px solid #666;' +
				   'background-color:white;' +
				   'background-image:url(\'/pics/ucrv.png\');' +
				   'background-repeat:repeat-x;background-position:top' +
				   '">' +
				   '<img src="/pics/spacer.gif" height=9></td>' +
				   '<td width=10><img src="/pics/urt_corner.gif" width=10></td>' +
				   '</tr></table>' +
				   '</td></tr>');

	// begin one big row for the main content for the page.
	document.write('<tr' +
				   ' style="background-color:white;' +
				   'background-image:url(\'' +
				   '/pics/lcrv.png\');background-repeat:repeat-y;' +
				   'background-position:left' +
				   '">' +
				   '<td valign=top' +
				   ' style="border-right:1px solid #333;' +
				   'border-left:1px solid #999;">');

	if (document.documentElement && bDoBannerPhotoFading)
	{
		window.onload = barakelPageLoaded;
	}
}

// when page is loaded, this is called.
function barakelPageLoaded()
{
	if (!document.documentElement)
		return;

	if (!document.images)
		return;

	bannerList.allDone = false;
	loadNextBannerPhoto(5000);
}

// Generate everything (the header) to start off the page.
//
//  this is a leftover and can be removed when no
//  pages use it anymore.
function doHeader(sectionName, pageName, rPre1, noMenu)
{
	doHeader2(rPre1, noMenu);
}

// finish off the work begun by 'doHeader()'
function doFooter()
{
	document.write('</td></tr>');

	// this row finishes off the main table with a curved bottom.
	document.write('<tr><td>' +
				   '<table border=0 cellpadding=0 cellspacing=0 width="100%">' +
				   '<TR><TD width=10>' +
				   '<img width=10 src="' +
				   '/pics/blft_corner.gif"></TD>' +
				   '<td style="border-bottom:1px solid #999;' +
				   'background-color:white;' +
				   'background-image:url(\'' +
				   '/pics/bcrv.png\');' +
				   'background-repeat:repeat-x;background-position:top' +
				   '">' +
				   '<img src="/pics/spacer.gif"' +
				   ' height=9></td>' +
				   '<td width=10><img width=10 src="' +
				   '/pics/brt_corner.gif"></td>' +
				   '</tr></table>' +
				   '</td></tr>');

	// copyright
	var tDate = new Date();
	document.write('<tr><td align=center>' +
				   '<table width=650><tr><td>' +
				   '<p style="color:#ccc;margin-top:5;font-size:8pt">' +
				   '&copy; ' + tDate.getFullYear() + ' Camp Barakel</p>' +
				   '</td><td align=right>' +
				   '<p style="margin-top:5;font-size:8pt">' +
				   '<a href="mailto:info@campbarakel.org"' +
				   'style="color:#ccc;font-size:8pt">' +
				   'info@campbarakel.org</a>' +
				   '</p>' +
				   '</td></tr></table>' +
				   '</td></tr>');
	// one row of solid border at the end
	document.write('<tr><td>' +
				   '<img src="/pics/spacer.gif" height=20>' +
				   '</td></tr>');

	document.write('</table>');
}

// return true if the user's display is supporting lots of colors.
// 'Lots' means more than 256.
function lotsaColors()
{
	if (screen.pixelDepth)
		return screen.pixelDepth > 8 ? true : false;

	if (screen.colorDepth)
		return screen.colorDepth > 8 ? true : false;

	return false;
}

// display contact info for Camp
// This used to pop up a window and is obsolete.
function contactCamp()
{
	window.top.location.href = '/about/contact.asp';
}

// This section is for the rotating banners.
var currentBannerPhotoNum = -1; // -1 means we're showing the original one.
var bannerDir = 'pics/homep/banner/fall2006/';

var bannerList = [
	"Archery 2.jpg",
	"Archery 3.jpg",
	"Archery 4.jpg",
	"Archery 5.jpg",
	"Archery 6.jpg",
	"Archery.jpg",
	"Bees.jpg",
	"Biking 1.jpg",
	"Biking 2.jpg",
	"Biking 3.jpg",
	"Biking 4.jpg",
	"Biking 5.jpg",
	"Boating.jpg",
	"Camp fire 1.jpg",
	"Camping 1.jpg",
	"Camping 2.jpg",
	"Camping 3.jpg",
	"Canoeing.jpg",
	"Clouds over the lake.jpg",
	"Couples biking.jpg",
	"Couples camping.jpg",
	"Couples chapel 1.jpg",
	"Couples chapel 2.jpg",
	"Couples chapel 3.jpg",
	"Cove.jpg",
	"Devos.jpg",
	"Dinner in the RV park.jpg",
	"Eating 1.jpg",
	"Family 2.jpg",
	"Family 3.jpg",
	"Family.jpg",
	"Ferns and fence.jpg",
	"Fireplace.jpg",
	"Fishing 2.jpg",
	"Fishing 3.jpg",
	"Fishing.jpg",
	"Football 1.jpg",
	"Frog.jpg",
	"Gabby 1.jpg",
	"Gameroom.jpg",
	"Golden branch.jpg",
	"Grilling.jpg",
	"Handhold.jpg",
	"Hannah G.jpg",
	"Hayride 1.jpg",
	"Hayride 2.jpg",
	"Hayride 3.jpg",
	"Hotdog forks and fire.jpg",
	"Hug.jpg",
	"Jeff Awe.jpg",
	"Just sitting.jpg",
	"Kayaking 2.jpg",
	"Kayaking.jpg",
	"Kids chapel 2.jpg",
	"Kids chapel.jpg",
	"Ladies 1.jpg",
	"Lily pads.jpg",
	"Lunch.jpg",
	"Mens chapel 2.jpg",
	"Mens chapel.jpg",
	"Notes.jpg",
	"Pontoon boat 2.jpg",
	"Pontoon boat.jpg",
	"Puppets 1.jpg",
	"Puppets 2.jpg",
	"Red branch.jpg",
	"Riflery 2.jpg",
	"Riflery 3.jpg",
	"Riflery 4.jpg",
	"Riflery.jpg",
	"Rowing.jpg",
	"Sacked.jpg",
	"Sawing 1.jpg",
	"Sawing 3.jpg",
	"Serving.jpg",
	"Soccer 1.jpg",
	"Spinning.jpg",
	"Swimming 1.jpg",
	"Swimming 2.jpg",
	"Swimming 3.jpg",
	"Swinging.jpg",
	"Taking a picture of dad.jpg",
	"Tetherball 2.jpg",
	"Tetherball.jpg",
	"Toadstools.jpg",
	"Walking 1.jpg",
	"Walking 2.jpg",
	"Wall 2.jpg",
	"Wall 3.jpg",
	"Wall.jpg",
	"Wild flowers.jpg",
	"paddleboat.jpg"
	];


var nextBannerPhotoImg = false;

function printTrack(s)
{
	var p = document.getElementById('ptP');
	if (!p)
		return;

	p.innerHTML += s;
}

// start the process of showing the next banner photo
function loadNextBannerPhoto(delayTime)
{
	if (bannerList.allDone)
		return;

	nextBannerPhotoImg = new Image(485, 160);

	if (bannerList.length == 0)
	{
		// no more photos to display, so go back
		// to the original one.
		nextBannerPhotoImg.src = rPre + strFadingImgDefault;
		bannerList.allDone = true;
	}
	else
	{
		var next = Math.floor(Math.random() * bannerList.length);

		// For the non-splice case, the logic below makes sure we
		// don't display the same photo twice in a row.  (For the
		// splice case it can change which photo comes next but
		// doesn't matter since it's random anyways.)
		if (currentBannerPhotoNum == next)
		{
			next++;
			if (next >= bannerList.length)
				next = 0;
		}

		currentBannerPhotoNum = next;

		nextBannerPhotoImg.src = rPre + bannerDir + bannerList[next];

		// splice to remove this ('next') photo from the list
		if (bannerList.splice)
			bannerList.splice(next, 1);
	}

	if (!delayTime)
	{
		delayTime = 8000;
	}

	window.setTimeout(showNextBannerPhoto, delayTime);
}

function showNextBannerPhoto()
{
	if (!nextBannerPhotoImg.complete)
	{
		window.setTimeout(showNextBannerPhoto, 1000);
		return;
	}

	var banImgObj = document.getElementById(strFadingImgID);
	if (!banImgObj)
		return;

	if (banImgObj.filters)
	{
		// For MSIE, we fade to the next banner photo
		banImgObj.filters[0].Apply();
		banImgObj.src = nextBannerPhotoImg.src;
		banImgObj.filters[0].Play();
		window.setTimeout(loadNextBannerPhoto, 3000);
		return;
	}

	banImgObj.src = nextBannerPhotoImg.src;
	loadNextBannerPhoto();
}

/***********************************************
* AnyLink Drop Down Menu- ? Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
var menubgcolor='#2c5329';  //menu bgcolor
var disappeardelay=250;  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes"; //hide menu when user clicks within menu?

/////No further editing needed

var ie4=document.all;
var ns6=document.getElementById&&!document.all;

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}


function showhide(obj, e, visible, hidden){
	if (ie4||ns6)
		dropmenuobj.style.left=dropmenuobj.style.top=-500;
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
		obj.visibility=visible;
	else if (e.type=="click")
		obj.visibility=hidden;
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? 
		document.documentElement : document.body;
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=0;
	if (whichedge=="rightedge"){
		var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15;
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth;
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth;
	}
	else{
		var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight;
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight;
	}
	return edgeoffset;
}

// create the contents of the menu from the 'what'
// menu that was passed to us.
function populatemenu(what)
{
	var i;
	var s = new Array();
	var thelink;
	for (i in what)
	{
		thelink = rPre + what[i].link;
		if (what[i].link.match(/^javascript:/i))
		{
			// no path info needed for javascript links.
			thelink = what[i].link;
		}

		s.push('<a target="_top" href="' + thelink + '">' +
			   what[i].text + '</a>');
	}
	dropmenuobj.innerHTML = s.join('');
}


// this gets things started off.  It's called
// from the onMouseover event of the reference.
function dropdownmenu(obj, e, menucontents)
{
	if (!ie4 && !ns6)
		return;

	if (window.event)
		event.cancelBubble=true;
	else if (e.stopPropagation)
		e.stopPropagation();

	clearhidemenu();
	dropmenuobj= document.getElementById("dropmenudiv");
	populatemenu(menucontents);

	showhide(dropmenuobj.style, e, "visible", "hidden");
	dropmenuobj.x=getposOffset(obj, "left");
	dropmenuobj.y=getposOffset(obj, "top");
	dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px";
	dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px";

	return clickreturnvalue();
}

function clickreturnvalue(){
	if (ie4||ns6)
		return false;
	else
		return true;
}

function contains_ns6(a, b) {
	while (b.parentNode)
		if ((b = b.parentNode) == a)
			return true;
	return false;
}

function dynamichide(e){
	if (ie4&&!dropmenuobj.contains(e.toElement))
		delayhidemenu();
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
		delayhidemenu();
}

function hidemenu(e){
	if (typeof dropmenuobj!="undefined"){
		if (ie4||ns6)
			dropmenuobj.style.visibility="hidden";
	}
}

function delayhidemenu(){
	if (ie4||ns6)
		delayhide=setTimeout("hidemenu()",disappeardelay);
}

function clearhidemenu(){
	if (typeof delayhide!="undefined")
		clearTimeout(delayhide);
}

if (hidemenu_onclick=="yes")
	document.onclick=hidemenu;
