// HilderBuild global Javascript functions v 4.1.7
function xDef() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}
function xGetElementById(e) {
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else e=null;
  return e;
}
function hfAddEventListener(e,eventType,eventListener,useCapture)
{
  if(!(e=xGetElementById(e))) return;
  eventType=eventType.toLowerCase();
  var eh='e.on'+eventType+'=eventListener';
  if(e.addEventListener) e.addEventListener(eventType,eventListener,useCapture);
  else if(e.attachEvent) e.attachEvent('on'+eventType,eventListener);
  else eval(eh);
}
function togglebuiltbyhilderbuild()
  {
    var x = xGetElementById('builtbyhilderbuild');
    if 	(xDef(x.className)) if (x.className=="active") x.className=""; else x.className="active";
  }
function hilderbuildEdit()
{
	if (UserDivs.length==0) alert('There are no user-editable sections on this page.');
	else document.location.href='hbedit/hb_edit_frameset.html?'+document.location.href;
}
function admin_login()
{
	document.location.href='http://hilderbuild.com/cpanel';
}
function validate_HTML_CSS()
{
	document.location.href='http://validator.w3.org/check?uri='+document.location.href;
}
// decode obscured email addresses
function hb_mailDecode(s)
{
    s=s.replace(new RegExp("-at-","g"), "@");
    s=s.replace(new RegExp("&ndash;at&ndash;","g"), "-at-");
    return(s);
}
function hb_DecodeAll()
{
    for (var i=0; i<document.links.length; i++)
    {
        if (document.links[i].href.substring(0,7).toLowerCase() == "mailto:")
        {
            document.links[i].href=hb_mailDecode(document.links[i].href);
            document.links[i].innerHTML=hb_mailDecode(document.links[i].innerHTML);
        }
    }
}
function hb_engageWithEditor()
{
if(parent&&parent.HBeditContext&&(parent.HBeditContext=='hilderbuild'))parent.hb_initialise()
}
hfAddEventListener(window,'load',hb_DecodeAll,false);
hfAddEventListener(window,'load',hb_engageWithEditor,false);

//HilderBuild HilderFish menu system Javascript files v 4.1.6

// scroll control variables
var hfScrollTimer=null; // INTERNAL, not user settable.
var hfLickOn=false; // INTERNAL, not user settable. 
					// Keeps menu on after auto-scrolling off bottom, top etc, but still
                    // turn it off after normal mouseout event.
var hfScrollLimit=20;   //pixels distance from the edge to activate scrolling
var hfScrollDistance=4; //pixels distance to scroll every interval milliseconds
var hfScrollInterval=50;//number of milliseconds betwen scroll events

// mouseover control variables
var hfTimer=null; // INTERNAL, not user settable.
var hfOverCount=0;// INTERNAL, not user settable.
var hfRolledOffList=new Array();// INTERNAL, not user settable.
var hfRolledOnList=new Array(); // INTERNAL, not user settable.
var hfStickOn=false; // INTERNAL, not user settable. Keeps menu on until next click
var hfHideDelay=1250;
	
// appearance control
var hfPopleftThreshold=0.8; //fraction of menu width required to be available on right

// this software uses parts of X, a Cross-Browser.com Javascript Library
// those parts of X that are used here are 
// Copyright (C) 2001,2002,2003,2004,2005 Michael Foster - Distributed under the terms of the GNU LGPL - OSI Certified
// File Rev: 5

var xVersion='3.15.4',xNN4,xOp7,xOp5or6,xIE4Up,xIE4,xIE5,xUA=navigator.userAgent.toLowerCase();
if (window.opera){
  xOp7=(xUA.indexOf('opera 7')!=-1 || xUA.indexOf('opera/7')!=-1);
  if (!xOp7) xOp5or6=(xUA.indexOf('opera 5')!=-1 || xUA.indexOf('opera/5')!=-1 || xUA.indexOf('opera 6')!=-1 || xUA.indexOf('opera/6')!=-1);
}
else if (document.all && xUA.indexOf('msie')!=-1) {
  xIE4Up=parseInt(navigator.appVersion)>=4;
  xIE4=xUA.indexOf('msie 4')!=-1;
  xIE5=xUA.indexOf('msie 5')!=-1;
}
else if (document.layers) {xNN4=true;}
xMoz=xUA.indexOf('gecko')!=-1;
xMac=xUA.indexOf('mac')!=-1;

function xStr() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}
  return true;
}
/*
function xClientWidth() {
	// modified by CJH to *always* use innerWidth if it is available
  var w=0;
  if(xOp5or6) w=window.innerWidth;
  else if(xDef(window.innerWidth,window.innerHeight,document.height)) {
    w=window.innerWidth;
    if(document.height>window.innerHeight) w-=16;
  } else if(document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientWidth)
    w=document.documentElement.clientWidth;
  else if(document.body && document.body.clientWidth)
    w=document.body.clientWidth;
  return w;
}
function xClientHeight() {
	// modified by CJH to *always* use innerHeight if it is available
  var h=0;
  if(xOp5or6) h=window.innerHeight;
  else if(xDef(window.innerWidth,window.innerHeight,document.width)) {
    h=window.innerHeight;
    if(document.width>window.innerWidth) h-=16;
  } else if(document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientHeight)
    h=document.documentElement.clientHeight;
  else if(document.body && document.body.clientHeight)
    h=document.body.clientHeight;
  return h;
}
*/
function xClientWidth() {
  var w=0;
  if(xOp5or6) w=window.innerWidth;
  else if(document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientWidth)
    w=document.documentElement.clientWidth;
  else if(document.body && document.body.clientWidth)
    w=document.body.clientWidth;
  else if(xDef(window.innerWidth,window.innerHeight,document.height)) {
    w=window.innerWidth;
    if(document.height>window.innerHeight) w-=16;
  }
  return w;
}
function xClientHeight() {
  var h=0;
  if(xOp5or6) h=window.innerHeight;
  else if(document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientHeight)
    h=document.documentElement.clientHeight;
  else if(document.body && document.body.clientHeight)
    h=document.body.clientHeight;
  else if(xDef(window.innerWidth,window.innerHeight,document.width)) {
    h=window.innerHeight;
    if(document.width>window.innerWidth) h-=16;
  }
  return h;
}
function xPageX(e) {
  if (!(e=xGetElementById(e))) return 0;
  var x = 0;
  while (e) {
    if (xDef(e.offsetLeft)) x += e.offsetLeft;
    e = xDef(e.offsetParent) ? e.offsetParent : null;
  }
  return x;
}

// HilderFish DHTML menu system - Copyright C J Hilder, 2005
// The following javascript functions are based on similar functions from 
// Michael Foster's X library - Distributed under the terms of the GNU LGPL.

function hfWidth(e) 
{
  if(!(e=xGetElementById(e))) return 0;
  var css=xDef(e.style);
  if(css && xDef(e.offsetWidth) && xStr(e.style.width)) return e.offsetWidth
  else if(css && xDef(e.style.pixelWidth)) return e.style.pixelWidth
  else return 0;
}

function hfHeight(e) 
{
  if(!(e=xGetElementById(e))) return 0;
  var css=xDef(e.style);
  if(css && xDef(e.offsetHeight) && xStr(e.style.height)) return e.offsetHeight
  else if(css && xDef(e.style.pixelHeight)) return e.style.pixelHeight
  else return 0;
}

function hfFirstChildTag(ele, tagName)
// Returns first child (or first child's sibling) with nodeName == tagName
{
  tagName=tagName.toLowerCase();
  var c = null;
  if (ele.firstChild)
  {
    c = ele.firstChild;
  	if (c.nodeName && c.nextSibling) while (c && c.nodeName.toLowerCase() != tagName) c = c.nextSibling;
  };
  return c;
}

function hfScrollLeft() 
{
  var w = window;
  if(w.document.documentElement && w.document.documentElement.scrollLeft) return w.document.documentElement.scrollLeft
  else if(w.document.body && xDef(w.document.body.scrollLeft)) return w.document.body.scrollLeft
  else if(xDef(w.pageXOffset)) return w.pageXOffset;
  return 0;
}

function hfScrollTop() 
{
  var w = window;
  if(w.document.documentElement && w.document.documentElement.scrollTop) return w.document.documentElement.scrollTop
  else if(w.document.body && xDef(w.document.body.scrollTop)) return w.document.body.scrollTop
  else if(xDef(w.pageYOffset)) return w.pageYOffset;
  return 0;
}

function hfEvent(evt) // object prototype
{
  this.target = null; 
  this.windowX = 0; 
  this.windowY = 0; 
  var e = evt || window.event;
  if(!e) return;
  if(e.target) this.target = e.target;
  else if(e.srcElement) this.target = e.srcElement;
  if(xOp5or6) { this.windowX = e.clientX-hfScrollLeft(); this.windowY = e.clientY-hfScrollTop(); }
  else if(xDef(e.pageX,e.pageY)) { this.windowX = e.pageX-hfScrollLeft(); this.windowY = e.pageY-hfScrollTop(); }
  else if(xDef(e.clientX,e.clientY)) { this.windowX = e.clientX; this.windowY = e.clientY; }
}
// HilderFish DHTML menu system - Copyright C J Hilder, 2005
// Distributed under the terms of the GNU LGPL.
// This menu system is inspired by the 
// SuckerFish CSS written by Patrick Griffiths and Dan Webb
// see http://www.htmldog.com/articles/suckerfish/dropdowns/

//--------------- mouse scroller ------------------------

function hfStartScrolling(command)
{
    if (hfScrolling) return;
    hfLickOn=true;
    hfScrolling=true;
    hfScrollTimer=setInterval("window.scrollBy("+command+")",hfScrollInterval);
}
function hfStopScrolling()
{
    hfScrolling=false;
    clearInterval(hfScrollTimer);
}

function scrollAtEdges(evt)
{
    var e = new hfEvent(evt);
    if (hfOverCount<=0) {hfStopScrolling(); return};
    
//-------- get mouse position
  var x = e.windowX;
  var y = e.windowY;
  
//-------- scroll in the appropriate direction
  if (window.scrollBy && xClientHeight() && xClientWidth())
  {
    if ((y>xClientHeight()-hfScrollLimit)&&(y<=xClientHeight())) {hfStartScrolling("0,hfScrollDistance")}
    else if ((x>xClientWidth()-hfScrollLimit)&&(x<=xClientWidth())) {hfStartScrolling("hfScrollDistance,0")}
    else if ((y<(hfScrollLimit))&&(y>=0)) {hfStartScrolling("0,-hfScrollDistance")}
    else if ((x<(hfScrollLimit))&&(x>=0)) {hfStartScrolling("-hfScrollDistance,0")}
    else hfStopScrolling()
  }
}

function hfCheckRollOns()
{
    for (var i=0; i<hfRolledOnList.length; i++)
    {
    	var x= hfFirstChildTag(hfRolledOnList[i],"UL");
        if (x && x.className) x.className=
                x.className.replace(new RegExp("popleft\\b"), "");
    	if( x && ((xPageX(x)-hfScrollLeft()+(hfWidth(x)*hfPopleftThreshold))>xClientWidth()) &&
    	((xPageX(hfRolledOnList[i])-hfScrollLeft()-(hfWidth(x)*hfPopleftThreshold))>0) &&
    	xDef(x.className) && (x.className.indexOf("popleft")==-1)) x.className+="popleft";
    };
}

function hfRemove(item)
{
	var result = new Array();
	var x = null;
    for (var i=0; i<hfRolledOnList.length; i++)
    {
    	x= hfRolledOnList[i];
        if (x!=item) result[result.length]=x;//result.push(x);
    };
    hfRolledOnList=result;
}
//--------------- menu system ---------------------------
function hfMouseOver(e)
{
    hfOverCount++;
    hfRolledOnList[hfRolledOnList.length]=e;//hfRolledOnList.push(e);
    hfCancelPending();
    if(xDef(e.className) && (e.className.indexOf("showing")==-1)) e.className+="showing";
    hfCheckRollOns();
    hfLickOn=false;
}
function hfMouseOut(e)
{
    hfOverCount--;
	hfRemove(e);
	hfRolledOffList[hfRolledOffList.length]=e;//hfRolledOffList.push(e);
	clearTimeout(hfTimer);
	if (!(hfStickOn||hfLickOn)) hfTimer=setTimeout("hfHideAll()", hfHideDelay);
	if (hfOverCount<=0) hfStopScrolling();
}

function hfGetElementsByTagName(parentEle, tagName)
{
  var list = null;
  if (parentEle && parentEle.getElementsByTagName) list = parentEle.getElementsByTagName(tagName)
  else if (parentEle && parentEle.all && parentEle.all.tags) list = parentEle.all.tags(tagName);
  return list || new Array();
}

function hfCancelPending()
{
    clearTimeout(hfTimer);
    hfHideAll();
}

function hfHideAll ()
{
    for (var i=0; i<hfRolledOffList.length; i++)
    {
        if (hfRolledOffList[i].className) hfRolledOffList[i].className=
                hfRolledOffList[i].className.replace(new RegExp("showing\\b"), "");
    };
    hfRolledOffList=new Array();
}
function hfKill()
{
	setTimeout("hfKiller()", 200);
}
function hfKiller()
{
	hfStickOn=false;
	for (var i=0; i<hfRolledOnList.length; i++)
		{hfRolledOffList[hfRolledOffList.length]=hfRolledOnList[i]; hfOverCount--;}
		//{hfRolledOffList.push(hfRolledOnList[i]); hfOverCount--;}
	hfCancelPending();
	hfRolledOnList=new Array();
	hfRolledOffList=new Array();
	hfOverCount=0;
	hfStopScrolling();
}

function hfClickHandler(evt) 
{
    hfLickOn=false;
    if (hfOverCount>0)
    {
        hfStickOn=true;
    }
    else
    {
        hfStickOn=false;
        hfCancelPending();
    }
}

function menu(){}//does nothing, but shows in status when href="javascript:menu()"

hfAddEventListener(document,'click',hfClickHandler,false);
hfAddEventListener(document,'mousemove',scrollAtEdges,false)

