/* 
category nav script - (c) 2003 ken mccormack

this code renders submenus menus and catgories, plus handles show / hide etc

steps are as follows:
1. categories are defined pageCategory
2. menus are rendered to the target frame by calling showSubMenus()
3. as each subnav is rendered, a tracking object is created in subNavArray and timoutlog.
4. breadcrumbs are worked out by walking backwards recursively along the pageCategory tree.
*/	

/* SETTINGS */

	var siteName ="Winton Photographics"
	var homeLink = ""
	var homePagename = "Home"
	var showBCsOnHomePage = false;

	var subFgColor	= "#404040";	// submenu text colour
	var subBgColor	= "#8BDCF1";	// the normal submenu cell colour
	var subHLColor	= "#F3AD5F";	// the rollover cell colour
	var subWidth	= 140;			// default submenu wudth
	var subHeight	= 20;			// default submenu height		
	var subStyle    = "" 			// additional positioning style (optional)
	
	var bUseParentWidth = true;		//	whether subnav used the width setting of the parent
	// category script settings
	var showDelay = 100;			// delay in mS before the subnav is displayed
	var hideDelay = 1000;			// delay on roll ou before the subnav is hidden

	// framed / unframed menu positioning offset settings 
	var yOffset = 25; 	var xOffset = 0; // offset position of subnavs on flat page
	var frameyOffset = 0; var framexOffset = -8;  // offset position of subnavs on frame page 
	var refreshRate = 100;  // this menu refresh be called every 500 ms

	var pageCategory = new Array();
	pageCategory[pageCategory.length] = new pageCategories("Home","1","home.aspx","");
	pageCategory[pageCategory.length] = new pageCategories("Portfolio","2","gallery4d5e.html","");
	
	pageCategory[pageCategory.length] = new pageCategories("Motorsport","3","gallery.aspx?cat_id=4","");
		//pageCategory[pageCategory.length] = new pageCategories("Rallies","4","gallery.aspx?cat_id=4","3");
	//	pageCategory[pageCategory.length] = new pageCategories("Orders","14","rally_orders.aspx","3");
	
	pageCategory[pageCategory.length] = new pageCategories("Services","5","services.aspx","");
		pageCategory[pageCategory.length] = new pageCategories("Portfolio","9","gallery.aspx?cat_id=17","5");

	pageCategory[pageCategory.length] = new pageCategories("Orders","6","motorsport_photography.aspx","");
		pageCategory[pageCategory.length] = new pageCategories("Pricing","7","pricing.aspx","6");
		pageCategory[pageCategory.length] = new pageCategories("Orderform","8","orderform.aspx","6");

	pageCategory[pageCategory.length] = new pageCategories("Landscape","10","gallery.aspx?cat_id=1","");
		pageCategory[pageCategory.length] = new pageCategories("Panoramic","11","galleryb0f3.html","10");
		pageCategory[pageCategory.length] = new pageCategories("Standard","12","gallerydc5a.html","10");
	//	pageCategory[pageCategory.length] = new pageCategories("Orders","13","landscape_photography_orders.aspx","10");

	pageCategory[pageCategory.length] = new pageCategories("Orders","6","motorsport_photography.aspx","");
		pageCategory[pageCategory.length] = new pageCategories("Pricing","7","pricing.aspx","6");
/*
	Definition of page category object - used to generate heirarchical breadcrumb navigation
*/

var debugMode = false;
onload = initialise;

var subNavArray = new Array();  // this stores the display status of each subnav
var subNavsActive = false; 		// flags whether subnavs active and CSS needs to be rendered to page
var isFramePage = false;		// flags whether this is a frameset page
var subNavsRendered = false;
var subMenuEvents = new Array(); // logs all events for subnav
var timoutlog = new Array();

function initialise()
{
	showBreadCrumbs();
	updateAllNavEvents(); // starts timeout loop
	if (isFramePage) parent.maindoc.goToPage(); // load rhs frame 
}


////////////////////////////////////// browser detect
var agt		= navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_ns  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1));
var is_ie   = (agt.indexOf("msie") != -1);
var is_safari = (agt.indexOf("safari") != -1);
 
var is_nsLegacy = (is_ns && (is_major <= 4));
// this will also exempt Mac IE
var is_ieLegacy  = (is_ie && (is_major <= 4) && (agt.indexOf("msie 5")==-1) && (agt.indexOf("msie 6")==-1)  && (agt.indexOf("msie 7")==-1));

// if browser is legacy  then we dont use dhtml flyout menus etc.
var is_legacy = (is_nsLegacy || is_ieLegacy);

var isMac = false;
var navPlatform = navigator.platform;
if (navPlatform=="MacPPC" || navPlatform=="Mac68K")  isMac = true;
//alert ("Is legacy? " + is_legacy + "\n" + agt + "\n" + " NS legacy: " + is_nsLegacy + " IE legacy:" + is_ieLegacy + ' ismajor=' + is_major);

////////////////////////////////////// intitialise code

var target = document;

// this detects a main frame called 'maindoc'
// if no frameset is detected here, subnav objected are written into the same window

// detect framed page
if (parent) 
	if (parent.frames) 
		if (parent.frames.maindoc)
			if (target = parent.frames["maindoc"].document)
			{
				isFramePage = true;
				yOffset = frameyOffset;
				xOffset = framexOffset;
				debug("maindoc frame detected");				
			}

////////////////////////////////////////////////////////// category objects + methods

function pageCategories(catName,catID,CatURL,parentCat)
{
	this.catName = catName;
	this.catID = catID;
	this.parentCat = parentCat;
	this.CatURL = CatURL // + "&parentcat_id=" + catID;
}

function getCategoryURLbyName(catName)
{
	debug ("Get category by name called for " + catName);
	for (var i=0; i<pageCategory.length; i++)
		if (pageCategory[i].catName.toLowerCase() == catName.toLowerCase())
			return pageCategory[i].CatURL
	return "";
}

function showSubMenus()
{
	//if (isMac) return;	// disable mac?
	if (document.layers) return; // not for NS4

	// frame menus are rendered when the content frame calls renderMenu()
	if (isFramePage && !subNavsRendered) return; 
	
	// show sub navs fot top level categories
	for (var i=0; i<pageCategory.length; i++)
		if (pageCategory[i].parentCat == "")
			showSubCategoryNav(pageCategory[i].catID)
	subNavsRendered = true;
}

function renderMenu()
{	
	// render subnavs when in frame mode - this must be called by the main frame 'maindoc' onload event
	target = parent.frames["maindoc"].document;
	subNavsRendered = true;
	showSubMenus();
}

function showSubCategoryNav(parentCatId)
{
	
	var subWidth	= 140;			// default submenu wudth
	var subHeight	= 20;			// default submenu height		
	var subStyle    = "" 			// additional positioning style (optional)
	
	var bUseParentWidth = true;		//	whether subnav used the width setting of the parent
	
	var templateTop1 	= "<div id=\"submenu[parentCatId]\" style=\"position:absolute; z-index:4; visibility: hidden; " + subStyle + "\" class=\"submenu\">\n";
	var templateTop2 	= "<table width=\"" + subWidth + "\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
	var templateLoop 	= "<tr><td class=\"subtable\" id=\"row[uniqueRowId]\" onClick=\"[target]goLink('[categoryLink]');\"";
		templateLoop 	+= ' onmouseout="[target]showHide(\'[parentCatId]\',\'\',\'hide\',false,true);"'
		//templateLoop 	+= '[target]RestyleElementId(\'row[uniqueRowId]\', \'' + subFgColor + '\', \'' + subBgColor + '\');" '
		templateLoop 	+= ' onmouseOver="[target]showHide(\'[parentCatId]\',\'\',\'show\',false,true);" '
		//templateLoop 	+= '[target]RestyleElementId(\'row[uniqueRowId]\', \'' + subFgColor + '\', \'' + subHLColor + '\');" '
		templateLoop 	+= " onclick=\"[target]goLink('[categoryLink]');\" style=\"cursor:hand;\">\n";
		templateLoop 	+= "<div class=\"submenu-row\">[link]</div>";
		templateLoop 	+= '</td></tr>\n\n'
	var templateFoot 	= '</table></div>\n';	

	// NS4 uses onclick for a link
	var linkString = "<a href=\"javascript:[target]goLink('[categoryLink]');\" class=\"submenu-link\">[CategoryName]</a>";
	if (document.layers) 
		linkString = "<a href=\"#\" class=\"submenu-link\" onClick=\"[target]goLink('[categoryLink]');\">[CategoryName]</a>";

	var concatString 	= ""; 	
	
	for (var i=0; i<pageCategory.length; i++)
		if (pageCategory[i].parentCat == parentCatId)
		{   
			if (concatString == "") concatString = templateTop1 + templateTop2;
			
			var loopString = templateLoop.replace(/\[link\]/gi,linkString);
			loopString = loopString.replace(/\[categoryLink\]/gi,pageCategory[i].CatURL);
			loopString = loopString.replace(/\[CategoryName\]/gi,pageCategory[i].catName);
			loopString = loopString.replace(/\[uniqueRowId\]/gi,parentCatId + "_" + i);
			
			concatString += loopString;
		}
	
	if (concatString != "") 
	{   // new sub nav menu must be registered
	
		concatString += templateFoot;
		concatString = concatString.replace(/\[parentCatId\]/gi,parentCatId);

	var targetString = ((isFramePage) ? "parent.menu." : "");
		
		concatString = concatString.replace(/\[target\]/gi,targetString);
		debug(concatString);
		
		if (isFramePage)
		{ // insert into body
			// alert("ADDING: \n\n" + concatString);
			target = parent.frames["maindoc"].document;
			var x = target.body.innerHTML;
			x = x + concatString;
			target.body.innerHTML = x;
			//window.status = 'code written';
		}
		else
		target.write (concatString); 
		
		subNavArray[subNavArray.length] = new subNavObj(parentCatId);
 
	}
}

////////////////////////////////////// track submenus

function subNavObj(id)
{
	this.id = id;
	this.display = "none";
}

/////////////////////////////////////////////////////// breadcrumbs

var breadCrumbString = ""; // global passed to recursive reverse lookup
var separator = "";
var defaultSeparator = " &gt; ";
var bookMarkTitle = "";

function showBreadCrumbs()
{
	// CHeck for frame page
	if (isFramePage || (!showBCsOnHomePage && pageName =="Home")) return;
	
	// Check for home page 
	if (typeof(categoryLabel) == "undefined") return; 
	
	if (categoryLabel == "") 
	{
		// this is a document
		breadCrumbString = '<span class="breadcrumb-article">' + pageName + '</span>';
		separator = defaultSeparator;
		// use articles own cat to contsruct breadcrumbs, rather than the category qstring 
		categoryId = pageCategory;
		bookMarkTitle = siteName + " - " + pageName; 
	}
	else
	{
		//debug ("This is a category");
		bookMarkTitle = siteName + " - " + categoryLabel; 
	}
	
	// construct cat tree, concatenating breadCrumbString
	if (typeof(categoryId) != "undefined")
		if (categoryId != "") getCategoryTree(categoryId);
		
	breadCrumbString = '<a href="'+ homeLink +'" class="breadcrumb-home-link">' + homePagename + '</a>' + separator + breadCrumbString;

	if (!document.getElementById) return;
	if (!document.getElementById('breadcrumbs')) return;
	x = document.getElementById('breadcrumbs');
	x.innerHTML = breadCrumbString;
}

function getCategoryTree(id)
{ // this function concatenates a breadcrumb tree in the global variable breadCrumbString
	//debug ("Getting cat tree for " + id);
	
	for (var i=0; i<pageCategory.length; i++)
		if (pageCategory[i].catID == id)
		{
			// if parent Category has no parent, use no link (top level cats have no pages) 
			if (pageCategory[i].parentCat == "" && !is_legacy)
			{
				breadCrumbString = pageCategory[i].catName + separator + breadCrumbString;
				separator = defaultSeparator;
			}
			else
			{	// else use a link
				// detect current category - no link is required, we're on the page
				var loc = document.location.href.toString();
				if (loc.indexOf(pageCategory[i].CatURL) == -1)
					breadCrumbString = '<a href="'+ pageCategory[i].CatURL +'" class="breadcrumb-link">' + pageCategory[i].catName + '</a>' + separator + breadCrumbString;
					else
						breadCrumbString = '<span class="breadcrumb-article">' + pageCategory[i].catName + '</span>' + separator + breadCrumbString;
				separator = defaultSeparator;
			}
			
			//debug ("Category tree now " + breadCrumbString);
			
			if (pageCategory[i].parentCat != "")
				getCategoryTree(pageCategory[i].parentCat);  // recursive call
		}
}

function getTopLevelParentId(navCategoryId)
{ // NOT TESTED 
  // This is to display the top level nav rollover 
  // aim is to feed in the current category id and this function will return its top level category 
  
	for (var i=0; i<pageCategory.length; i++)
		if (pageCategory[i].catID == navCategoryId)
			if (pageCategory[i].parentCat == "") return pageCategory[i].catID;
				else
					return getTopLevelParentId(pageCategory[i].catID);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
//
//	fuzzy logic / real time nav model - not dependent on the browser storing multiple timeouts
//	events are logged in the subMenuEvents array
//
//////////////////////////////////////////////////////////////////////////////////////////////////////

// globals
var statusString = "";  // this string used only for debugging
var arrayPointer = 0;


function navEvent(navId,eventType,timeRemaining)
{ // this object stores a show / hide event for a submenu item
	this.navId = navId;			// id of subnav being shown / hidden
	this.eventType = eventType;	// show or hide
	this.timeRemaining = timeRemaining;  // refresh time in ms - see refreshRate
	this.updateEvent = updateNavEvent;	// increment time value and show / hide / delete as applicable
}

function updateAllNavEvents()
{ // loop function to continually update status of all events
	if (is_legacy) return; // not for NS4, IE4 etc

	statusString = ""; arrayPointer = 0; // global
	
	while (arrayPointer < subMenuEvents.length)
	{
		subMenuEvents[arrayPointer].updateEvent(arrayPointer);
	}
		
	// window.status = statusString
	 showNavArray();
	
	window.setTimeout("updateAllNavEvents()",refreshRate);
}

function updateNavEvent(index)
{
	this.timeRemaining = this.timeRemaining - refreshRate;
	if (this.timeRemaining < 1) 
	{
		//statusString +=  "Executing event: " + this.eventType + " " + this.navId + " | ";
		showHideUniqueMenu(this.navId,this.eventType);
		//removeList += index + ","; // remove this event
		removeElement(subMenuEvents,index);
		// array pointer does not move - as we've chopped the array element! 
	}
	else
	{
		arrayPointer++; // show next element
	}
	return true; // event will not be removed
}

function removeElement(array,elementIndex)
{	// this function removes index elementIndex from array - array must be global // ie 6 // ns 4+
	if (!array.length) return false;
	if (array.length <= elementIndex) return;
	var indexCounter = 0;
	for (var i=0; i < array.length; i++)
		if (i != elementIndex) 
		{
			array[indexCounter] =array[i];
			indexCounter++;
		}
	array.length = array.length - 1;
}

function clearSubMenuHideEvents(navId)
{ 	// clear all hide events for navId - when you roll over, you need to kill hide events,
	// as the hide delay is longer than the show delay
	
	var arrayPointer = 0;
	
	// need to use a while loop as size of array is reduced and arrayPointer is not incremented 
	// every time (a for loop will skip an element after deletion)
	while (arrayPointer < subMenuEvents.length)
	{
		if (subMenuEvents[arrayPointer].navId == navId && subMenuEvents[arrayPointer].eventType == "hide")
			removeElement(subMenuEvents,arrayPointer);
			 else
			 	arrayPointer++;
	}
}

function clearAllOtherSubMenuShowEvents(navId)
{ 	// this 'brick wall' is called when the mouse hits a submenu (the showHide function will be called
	// by the subnav with isSubNavLanding set true)
	// before this point the show hide logic is fuzzy, to allows a high degree of show huide hysteresis. 
 	
	// this funcion clear all SHOW events for other navs, 
	// and clears all HIDE events for this NAV 
	
	var removeList = "";
	for (var i=0; i < subMenuEvents.length; i++)
		if ((subMenuEvents[i].navId != navId && subMenuEvents[i].eventType == "show") || (subMenuEvents[i].navId == navId && subMenuEvents[i].eventType == "hide"))
			removeList += i + ","
	
	var removeArray = removeList.split(",");
	for (var i=0; i <= removeArray.length; i++)
	{
		removeElement(subMenuEvents,removeArray[i]);
	}
}

function showNavArray()
{
	// exit gracefully for IE 4 
	if (is_legacy) return; // not for NS4, IE4 etc
	
	logString = "";
	for (var i=0; i < subMenuEvents.length; i++)
		logString += i + "		id:	" + subMenuEvents[i].navId + "		type: " + subMenuEvents[i].eventType + "		time: " + subMenuEvents[i].timeRemaining + "\n";
	
	if (document.getElementById("debug"))
	{
		x = document.getElementById("debug")
		x.value = logString;
	}
}

///////////////////////////////////////////////////////////////////////  DHTML showhide


function showHide(name,n,action,reposition,isSubNavLanding)
{


	// window.status = action + " " + name + " isFrame: " + isFramePage + " GM_PageLoadError:" + GM_PageLoadError + " GM_contentPageLoaded: " + GM_contentPageLoaded;
	if (!subNavsRendered) return;

//alert ("showhide")
	
	if (is_legacy) return; // not for NS4, IE4 etc
	
	if (typeof(reposition) == "undefined") reposition = false;
		else reposition = true;
	
	if (typeof(isSubNavLanding) == "undefined") isSubNavLanding = false;
		else isSubNavLanding = true;

	var positionerImgName = 'menuimg' + name; 
	name = 'submenu' + name;
	
	//var index = getLogID(name);
	//debug ("timeout index is " + index);
	if (action == "show")
	{
		if (reposition) translateDHTMLPositions(name,positionerImgName);
		// set to to pop up
		debug ("call to MM_showHideLayers('"+name+"','','show')");
		subMenuEvents[subMenuEvents.length] = new navEvent(name,"show",showDelay);
		showNavArray();
		
		// if we have hit the target, cancel all other show instructions
		if (isSubNavLanding) 
			clearAllOtherSubMenuShowEvents(name);
			else
				clearSubMenuHideEvents(name);
	}
	else
	{
		// new - all we have to do is log event and let time take care of it
		subMenuEvents[subMenuEvents.length] = new navEvent(name,"hide",hideDelay);
		showNavArray();
	}
	return false; // don't let browser jump to #top
}

// final show hide

function showHideUniqueMenu(menuId, eventType)
{
	//alert ("showHideUniqueMenu for " + 	menuId + " => " + eventType);
	if (eventType == "show")
	{
		MM_showHideLayers(menuId,'','show');
		for (var i=0; i<subNavArray.length; i++)
			if ('submenu' + subNavArray[i].id != menuId)
			{
				MM_showHideLayers('submenu'+ subNavArray[i].id,'','hide');
			}
		
	}
	else
		MM_showHideLayers(menuId,'','hide');
}


/////////// DHTML positioning code /////////////////////////////////////////////
// this code positions the submenu to the right of the trigger image
// this code adapted from (c) http://www.dagblastit.com/
/////////////////////////////////////////////////////////////////////////////////

// overly simplistic test for IE
isIE = (document.all ? true : false);
// both IE5 and NS6 are DOM-compliant
isDOM = (document.getElementById ? true : false);

// get the true offset of anything on NS4, IE4/5 & NS6, even if it's in a table!
function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }
function getAbsPos(elt,which) {
 iPos = 0;
 while (elt != null) {
  iPos += elt["offset" + which];
  elt = elt.offsetParent;
 }
 return iPos;
}

function getDivStyle(divname) {
 var style;
 // handle frame errors and/or missing submenus
 if (!target) return false;
 if (!target.getElementById) return false;
 if (!target.getElementById(divname)) return false;
 
 if (isDOM) { style = target.getElementById(divname).style; }
 else { style = isIE ? target.all[divname].style
                     : target.layers[divname]; } // NS4
 return style;
}


function hideElement(divname) {
 getDivStyle(divname).visibility = 'hidden';
}

// annoying detail: IE and NS6 store elt.top and elt.left as strings.
function moveBy(elt,deltaX,deltaY) {
 elt.left = parseInt(elt.left) + deltaX;
 elt.top = parseInt(elt.top) + deltaY;
}

function toggleVisible(divname,positionerImgName) 
{
	//alert ("command for " + divname + " position to " + positionerImgName);
	// first move DIV to position target
 	// translateDHTMLPositions(divname,positionerImgName);
	 divstyle = getDivStyle(divname);
	 
	 if (divstyle.visibility == 'visible' || divstyle.visibility == 'show') 
	 	divstyle.visibility = 'hidden';
	 		else 
				divstyle.visibility = 'visible';
	 
}

function setPosition(divname,positionername)
{

 var elt = getDivStyle(divname);
 if (!elt) return;
 
 var positioner;
 if (isIE) 
   	positioner = document.all[positionername];
 		else 
  			if (isDOM) 
    			positioner = document.getElementById(positionername);
	 				else 
					positioner = document.images[positionername];
					// not IE, not DOM (probably NS4)
					// if the positioner is inside a netscape4 layer this will *not* find it.
					// I should write a finder function which will recurse through all layers
					// until it finds the named image...

 
 var scrollOffset = ((isFramePage) ? pageScrollTop() : 0);

 elt.left = (getAbsX(positioner) + xOffset) + "px";
 elt.top = (getAbsY(positioner) + yOffset + scrollOffset)  + "px";
 //alert (positionername + " x and y  = " + getAbsX(positioner) + " " + getAbsY(positioner) + "\nmoving to " + (getAbsX(positioner) + xOffset) +" "+ (getAbsY(positioner) + yOffset));

}

function translateDHTMLPositions(divname,positionerImgName)
{ // move subnav layer to (x,y) of positionerImgName image (+ offsets)
	setPosition(divname,positionerImgName); 
}


///////////////////////////////////// restyle table td for subnav rollovers
// (c) GravityMax, others

var DOM    = (document.getElementById ? 1 : 0);
var IE4DOM = (document.all ? 1 : 0);
var NS4    = (document.layers ? 1 : 0);
function GetStyle(id) {
   // var idHandle = (DOM ? document.getElementById(id) : (IE4DOM ? document.all[id] : false));
	var idHandle = (DOM ? target.getElementById(id) : (IE4DOM ? target.all[id] : false));
    return (idHandle ? idHandle.style : false);
}

function RestyleElementId(elementId, color, backgroundColor) {
    styleHandle = GetStyle(elementId);
                if (styleHandle) {
        styleHandle.color = color;
        styleHandle.backgroundColor = backgroundColor;
    }
}


///////////////////////////////////// workhorse functions
// (c) Macromedia, GravityMax, others

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&id.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  {
	  	var findObjValue = args[i];
		if (isFramePage) findObjValue += "?maindoc";
		//alert ("Call to find object " + findObjValue);
		
	  	if ((obj=MM_findObj(findObjValue))!=null) 
		{ 
			v=args[i+2];
			if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
			obj.visibility=v; 
		}
	}
}

function pageScrollTop() {

// alert (parent.maindoc.document.documentElement.scrollTop);

	if (document.layers || navigator.product == 'Gecko')
	{ // the browser is Netscape
		return parent.maindoc.pageYOffset; 
	} 
	else
	{ // ie	
		if (parent.maindoc.document.documentElement && parent.maindoc.document.documentElement.scrollTop)	return parent.maindoc.document.documentElement.scrollTop;
		if (document.body) return parent.maindoc.document.body.scrollTop
	}
}

function goLink(url)
{ 	
// subnavs and main navs use this function to provide link functionality
 	//	this cures the Mac frame link problem
	if (isFramePage)
	{
		if (parent.frames.maindoc)
		{
			parent.location.href = url;
			//return false; // dont jump to top!
		}
	}
	else
	{
		document.location.href = url;
		//return false; // dont jump to top!
	}
}

function debug(debugString)
{
	if (debugMode) alert (debugString);
}

