/* Copyright � 2006-2009 Nicholas Stimpson. All Rights Reserved */

function Hue()
{
    if (arguments.length >= 3)
    {
        this.red = arguments[0];
        this.green = arguments[1];
        this.blue = arguments[2];
    }
    else
    {
        var colorStr = arguments[0];
        if (colorStr.substring(0, 1) == '#')
        {
            if (colorStr.length > 4)
            {
                this.red = parseInt(colorStr.substring(1, 3), 16);
                this.green = parseInt(colorStr.substring(3, 5), 16);
                this.blue = parseInt(colorStr.substring(5, 7), 16);
            }
            else
            {
                this.red = parseInt(colorStr.substring(1, 2) + colorStr.substring(1, 2), 16);
                this.green = parseInt(colorStr.substring(2, 3) + colorStr.substring(2, 3), 16);
                this.blue = parseInt(colorStr.substring(3, 4) + colorStr.substring(3, 4), 16);
            }  
        }
        else if (colorStr.substring(0, 4) == 'rgb(')
        {
            var primaries = colorStr.substring(4).replace(')','').split(',');
            
            this.red = parseInt(primaries[0]);
            this.green = parseInt(primaries[1]);
            this.blue = parseInt(primaries[2]);
        }
        else
        {
            this.red = this.green = this.blue = 0;
        }
    }
    
    this.primaryFilter = function(primary, fhue)
    {
        return Math.round(255 - ((255 - primary) * (255 - fhue) / 255));
    }
    
    this.filter = function(fhue)
    {
        var red = this.primaryFilter(this.red, fhue.red);
        var green = this.primaryFilter(this.green, fhue.green);
        var blue = this.primaryFilter(this.blue, fhue.blue);
        return new Hue(red, green, blue);
    }
    
    this.asHex = function(cVal)
    {
       return (cVal < 16 ? "0" : "") + cVal.toString(16);
    }
    this.color = '#' + this.asHex(this.red) + this.asHex(this.green) + this.asHex(this.blue);
}

// Colour object constructor
function colour()
{
    var swatch = new Object();
    var swatchDivs = document.getElementById("swatch").childNodes;
    for (var i = 0 ; i < swatchDivs.length ; i++)
    {
        switch (swatchDivs[i].className)
        {
            case "metabase" : swatch.metabase = document.getCssStrValue(swatchDivs[i], "backgroundColor"); break;
            case "remoteNav" : swatch.remoteNav = document.getCssStrValue(swatchDivs[i], "backgroundColor"); break;
            case "localNav" : swatch.localNav = document.getCssStrValue(swatchDivs[i], "backgroundColor"); break;
            case "currentTab" : swatch.currentTab = document.getCssStrValue(swatchDivs[i], "backgroundColor"); break;
            case "shadowTab" : swatch.shadowTab = document.getCssStrValue(swatchDivs[i], "backgroundColor"); break;
            case "content" : swatch.content = document.getCssStrValue(swatchDivs[i], "backgroundColor"); break;
        }
    }

  	this.defaultColor = new Hue(swatch.metabase);
	this.remoteHoverColor = new Hue(swatch.remoteNav);
	this.localHoverColor = new Hue(swatch.localNav);
	this.selectedColor = new Hue(swatch.currentTab);
	this.shadowColor = new Hue(swatch.shadowTab);
	this.defaultCalColor = new Hue(swatch.content);
	
	this.primaryShade = function(primary, i, hgt)
    {
        return Math.floor(primary + 2 * i * i * (255 - primary) / (3 * (hgt - 1) * (hgt - 1)));
    }
	
	this.colorShade = function(hue, i, hgt)
    {
	    var red = this.primaryShade(hue.red, i, hgt);
	    var green = this.primaryShade(hue.green, i, hgt);
	    var blue = this.primaryShade(hue.blue, i, hgt);
	    return new Hue(red, green, blue);
    }
    
    this.setBGColorHi = function()
    {
        this.style.backgroundColor = this.hoverColor.color;
        this.isover = true;
    }

    this.setBGColorLo = function()
    {
        if (this.iscurrent || this.pagecurrent)
        {
	        this.style.backgroundColor = document.colour.selectedColor.color;
        }
        else
        {
	        this.style.backgroundColor = document.colour.defaultColor.color;
        }
        this.isover = false;
    }

    this.setBGColorLoCal = function()
    {
        if (this.iscurrent)
        {
	        this.style.backgroundColor = document.colour.selectedColor.color;
        }
        else
        {
	        this.style.backgroundColor = document.colour.defaultCalColor.color;
        }
        this.isover = false;
    }
}


/* Copyright � 2006-2009 Nicholas Stimpson. All Rights Reserved */

function compatibility()
{
	if (! document.getElementById)
		if (document.all)
		{  
			document.getElementById = function(id) { return document.all[id]; }
		}
		
	if (! document.getElementsByTagName)
		if (document.all)
		{
			document.getElementsByTagName = function(id) { return document.all.tags(id); }
		}
		
	if (! document.getElementsByClassName)
	{
		document.getElementsByClassName = function(className)
        {
            var arrElements = document.all ? document.all : document.getElementsByTagName('*');
            var arrReturnElements = new Array();
            var strClassName = className.replace(/\-/g, "\\-");
            var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
            var oElement;
            for(var i=0; i<arrElements.length; i++)
            {
                oElement = arrElements[i];     
                if (oRegExp.test(oElement.className))
                {
                    arrReturnElements.push(oElement);
                }   
            }
            return (arrReturnElements);
        }
	}		
		
    /* Thanks to Michael Winter at www.thescripts.com for this function */
 	document.getCssValue = (function(v) 
	{
        if (v && v.getComputedStyle)
        {
            return function(e, p, pE)
            {
                var style = v.getComputedStyle(e, pE || null);
                return pixelVal(style[p]);
            };
        }
        else
        {
            v = null;
            return function(e, p) 
            { 
                if (e && e.currentStyle) 
                {
                    return pixelVal(e.currentStyle[p]);
                }
                else
                {
                    return(0);
                }
            };
        }
    })(document.defaultView);
    
    document.getCssStrValue = (function(v) 
	{
        if (v && v.getComputedStyle)
        {
            return function(e, p, pE)
            {
                var style = v.getComputedStyle(e, pE || null);
                return style[p];
            };
        }
        else
        {
            v = null;
            return function(e, p) 
            { 
                if (e && e.currentStyle) 
                {
                    return e.currentStyle[p];
                }
                else
                {
                    return null;
                }
            };
        }
    })(document.defaultView);
    
	window.pixelVal = function(pxStr)
    {
        if (! pxStr)
        {
            return 0;
        }
        else if (pxStr.substring(pxStr.length - 2, pxStr.length) == "px")
        {
            return pxStr.substring(0, pxStr.length - 2) - 0;
        }
        else
        {
            return pxStr - 0;
        }
    }

    window.setChildNodes = function(coll)
    {
	    var i;
    	
	    for (i = 0 ; i < coll.length ; i++)
	    {
		    var elem = coll(i);
		    elem.childNodes = elem.children;
		    if (! elem.parentNode)
		    {
			    elem.parentNode = elem.parentElement;
		    }
	    }
    }
}

// Use IE conditional complilation as the most reliable way of detecting IE version in javascript.
/*@cc_on
    // ms ie data object constructor
    function msie() 
    {
        var ver = typeof document.documentMode != "undefined" ? 8 :      // Both IE7 and IE8beta1 have jscript version of 5.7
                   typeof document.body.style.maxHeight != "undefined" ? 7 : 
                   @_jscript_version >= 5.6 ? 6 : 
                   @_jscript_version >= 4.0 ? 5 :
                   @_jscript_version >= 3.0 ? 4 : 
                   3;
        var domVer = 
                   typeof document.documentMode != "undefined" ? 8 :
                   typeof document.body.style.maxHeight != "undefined" ? 7 : 
                   typeof document.body.style.wordSpacing != "undefined" ? 6 :
                   typeof document.getElementById != "undefined" ? 5 : 
                   typeof document.images != "undefined" ? 4 : 
                   3;
           
        this.mode = function() { return typeof document.documentMode != "undefined" ? 
                                            document.documentMode : 
                                        document.compatMode == 'BackCompat' ? 
                                            5 :
                                            ver; };
        this.version = function() { return ver; };
        this.jversion = function() { return @_jscript_version; };
    }
@*/

// Compat object constructor
function compat() 
{
	// I really hate this, but IE5.0 throws a fault for cursor='pointer' so we must protect against this.
	// Also IE4 doesn't like floated images, so record whether it's OK to float images.
    // Then there's the border box model and padding rendering issues.

	this.pointerCursor = window.msie && (msie.version() == 5) ? 'hand' : 'pointer';
	this.floatImages = !(window.msie && (msie.version() == 4));
	this.quirksMode = window.msie && ((msie.version() == 4) || (msie.version() == 5) || (document.compatMode == 'BackCompat'));
	this.paddingExtendsWidth = (! window.msie) || (msie.mode() >= 6);
	this.positioningFloat = (! window.msie) || (msie.mode() >= 8);
	 
	// Anchors don't work properly with independent scroll areas in Opera 7.
	this.independentScrollAreas = (! (window.opera && (opera.version() < 8)));
	// In Opera 9 the offsetTop values are automatically adjusted by the amount of scroll applied, 
	// so we must compensate for that. Unfortunately, there is no standard for this, so it isn't 
	// wrong, merely different.
	this.scrollRelativeOffsets = (window.opera && (opera.version() >= 9) && (opera.version() < 10));
	// Opera 8 gets offsetTop relative to the entire document, not the containing positioned element,
	// so once again we must compensate.
	this.pageRelativeOffsets = (window.opera && (opera.version() >= 8) && (opera.version() < 9));
}

    
function compatSetup()
{
    if (! document.childNodes)
	{
		if (document.all)	
		{
			setChildNodes(document.all);
		}
	}
    
    // Use IE conditional complilation as the most reliable way of detecting IE version in javascript.
    /*@cc_on
        // ms ie data object constructor
        window.msie = new msie();
        //alert(msie.version());
        //alert(msie.jversion());
    @*/

	navigator.compat = new compat();
}






	

/* Copyright � 2006-2009 Nicholas Stimpson. All Rights Reserved */

function disableInnerAnchor(elem)
{
	// if we put an onclick event on a div that surrounds an anchor, and click on the 
	// anchored text itself, we get two http requests generated. This disables the 
	// request from the anchor, so we only get the request from the div onclick event.

	var anchorColl = elem.childNodes;
	for (var i = 0 ; i < anchorColl.length ; i++)
	{
		var anchor = anchorColl.item(i);
		if (anchor.href)
		{
			anchor.onclick = anchorDisabled;
			return;
		} 
	}
}

function anchorDisabled()
{
	return false;
}
// written by Dean Edwards, 2005
// with input from Tino Zijdel, Matthias Miller, Diego Perini

// http://dean.edwards.name/weblog/2005/10/add-event/

function addEvent(element, type, handler) {
	if (element.addEventListener) {
		element.addEventListener(type, handler, false);
	} else {
		// assign each event handler a unique ID
		if (!handler.$$guid) handler.$$guid = addEvent.guid++;
		// create a hash table of event types for the element
		if (!element.events) element.events = {};
		// create a hash table of event handlers for each element/event pair
		var handlers = element.events[type];
		if (!handlers) {
			handlers = element.events[type] = {};
			// store the existing event handler (if there is one)
			if (element["on" + type]) {
				handlers[0] = element["on" + type];
			}
		}
		// store the event handler in the hash table
		handlers[handler.$$guid] = handler;
		// assign a global event handler to do all the work
		element["on" + type] = handleEvent;
	}
};
// a counter used to create unique IDs
addEvent.guid = 1;

function removeEvent(element, type, handler) {
	if (element.removeEventListener) {
		element.removeEventListener(type, handler, false);
	} else {
		// delete the event handler from the hash table
		if (element.events && element.events[type]) {
			delete element.events[type][handler.$$guid];
		}
	}
};

function handleEvent(event) {
	var returnValue = true;
	// grab the event object (IE uses a global event object)
	event = event || fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
	// get a reference to the hash table of event handlers
	var handlers = this.events[event.type];
	// execute each event handler
	for (var i in handlers) {
		this.$$handleEvent = handlers[i];
		if (this.$$handleEvent(event) === false) {
			returnValue = false;
		}
	}
	return returnValue;
};

function fixEvent(event) {
	// add W3C standard event methods
	event.preventDefault = fixEvent.preventDefault;
	event.stopPropagation = fixEvent.stopPropagation;
	return event;
};
fixEvent.preventDefault = function() {
	this.returnValue = false;
};
fixEvent.stopPropagation = function() {
	this.cancelBubble = true;
};

/* Copyright � 2006-2009 Nicholas Stimpson. All Rights Reserved */

// layout object constructor
function layout() 
{
    // menu layout object constructor
    this.menu = new function() 
    {
	    this.totalWidth = 160;
	    this.leeway = 2;
	    this.useWidth = this.totalWidth - this.leeway;
	    this.vScrollWidth = 17;
	    this.innerWidth = this.totalWidth - this.vScrollWidth - this.leeway;
    };

	this.calendar = new function(){};
	
	// viewport object constructor
	this.viewport = new function()
    {
	    this.bottomMargin = 5;
	    this.rightMargin = 5;
    };
    
    // tabs object constructor
	this.tabs = new function()
    {
	    this.indent = 5;
	    this.overlap = 4;
	    this.gradient = 2.5;
	    this.borderWidth = 1;
	    this.marginBelow = 5;
    };
    
    // realbody layout object constructor
	this.realbody = new function() 
    {
        this.vScrollWidth = 17;
    };
}




	

/* Copyright � 2006-2009 Nicholas Stimpson. All Rights Reserved */

function getDisplayHeight(obj)
{
    if (obj == null)
    {
        return 0;
    }
	if (obj.offsetHeight != 0)
	{
		return obj.offsetHeight;
	}
	else if (obj.clientHeight != 0)
	{
		return obj.clientHeight;
	}
	else if (document.defaultView && document.defaultView.getComputedStyle)
	{
		var h = parseInt(document.defaultView.getComputedStyle(obj, null).getPropertyValue("height"));
		h = h + parseInt(document.defaultView.getComputedStyle(obj, null).getPropertyValue("padding-top"));
		h = h + parseInt(document.defaultView.getComputedStyle(obj, null).getPropertyValue("padding-bottom"));
		return(h);
	}
	else if (obj.currentStyle)
	{
		return parseInt(obj.currentStyle.height);
	}
	else
	{
		return 0;
	}
}

function getDisplayWidth(obj)
{
    if (obj == null)
    {
        return 0;
    }
	if (obj.offsetWidth != 0)
	{
		return obj.offsetWidth;
	}
	else 
	if (obj.clientWidth != 0)
	{
		return obj.clientWidth;
	}
	else if (document.defaultView && document.defaultView.getComputedStyle)
	{
		var h = parseInt(document.defaultView.getComputedStyle(obj, null).getPropertyValue("width"));
		h = h + parseInt(document.defaultView.getComputedStyle(obj, null).getPropertyValue("padding-left"));
		h = h + parseInt(document.defaultView.getComputedStyle(obj, null).getPropertyValue("padding-right"));
		return(h);
	}
	else if (obj.currentStyle)
	{
		return parseInt(obj.currentStyle.width);
	}
	else
	{
		return 0;
	}
}
/* Copyright � 2006-2009 Nicholas Stimpson. All Rights Reserved */

function menu()
{
    this.setup = function()
    {
	    if (! document.getElementById)
		    return;
    		
	    window.layout.menu.originalMenuHeight = document.direct.menu.offsetHeight;
	    window.layout.menu.lastMatched = new Array();
	    window.layout.calendar.lastMatched = new Array();
	    this.setupMenuSection(document.getElementById('accessmenu'));
	    if (document.getElementsByTagName)
	    {
		    var i;
		    var menus = document.getElementsByTagName('ul');
		    for (i = 0 ; i < menus.length ; i++)
		    {
			    var premenu = menus.item(i);
			    if (premenu.className == "premenu")
			    {
				    this.setupMenuSection(premenu);
			    }
		    }
    		
		    spans = document.getElementsByTagName('span');
		    window.layout.realbody.storyAnchors = new Array();
		    window.layout.realbody.calendarAnchors = new Array();
		    var k = 0;
		    var l = 0;
	  	    for (var j = 0; j < spans.length; j++ ) 
  		    {
			    var apd = spans.item(j);
			    if (apd.className == 'storyAnchor')
			    {
				    window.layout.realbody.storyAnchors[k++] = apd;
				    apd.menuItem = this.getMenuItem(apd);
				    window.layout.realbody.calendarAnchors[l++] = apd;
				    apd.calendarItems = this.getCalendarItems(apd);
			    }
			    else if (apd.className == 'eventAnchor')
			    {
				    window.layout.realbody.calendarAnchors[l++] = apd;
				    apd.calendarItems = this.getCalendarItems(apd);
			    }
		    }
	    }	
	    this.setupMenuSection(document.getElementById('innermenu'));
	    this.setupCalendarSection();
	}
	
	this.resetState = function()
	{
	    this.clearMenuState();
        this.setMenuState();
        window.layout.calendar.lastMatched = new Array();
        this.setCalendarState();
	}

    this.getMenuItem = function(apd)
    {
	    if (apd.name)
	    {
		    matched = "mnu" + apd.name.substring(5);
	    }
	    else
	    {
		    matched = "mnu" + apd.id.substring(5);
	    }
	    return document.getElementById(matched);
    }

    this.getCalendarItems = function(apd)
    {
        var items = new Array();
        for (var i = 0 ; i < 31 ; i++)
        {
            var matched;
	        if (apd.name)
	        {
		        matched = "calendar" + apd.name.substring(5) + "-" + i;
	        }
	        else
	        {
		        matched = "calendar" + apd.id.substring(5) + "-" + i;
	        }
	        var calendarItem = document.getElementById(matched);
	        if (calendarItem != null)
	        {
	            items[items.length] = calendarItem;
	        }
	    }
	    return items;
    }

    this.setupCalendarSection = function()
    {
	    var tds;
	    if (document.getElementsByTagName)
	    {
		    tds = document.getElementsByTagName('td');
	    }
  	    for ( j = 0; j < tds.length; j++ ) 
  	    {
		    var td = tds.item(j);
		    if (td.className == 'event')
		    {
			    td.iscurrent = false;
			    td.isover = false;
			    td.hoverColor = document.colour.localHoverColor;
			    td.onmouseover = document.colour.setBGColorHi;
			    td.onmouseout = document.colour.setBGColorLoCal;
			    td.onclick = gotoHref;
			    if (td.style)
				    td.style.cursor = navigator.compat.pointerCursor;
			    disableInnerAnchor(td);
		    }
	    }
    }

    this.setupMenuSection = function(menu)
    {
	    if (menu == null)
	    {
		    return;
	    }
    	
	    var cn = menu.childNodes;
  	    for ( j = 0; j < cn.length; j++ ) 
  	    {
		    var li = cn.item(j);
		    if ((li.nodeName == 'li') || (li.nodeName == 'LI'))
		    {
			    li.iscurrent = false;
			    li.pagecurrent = (li.className == "HeadlineCurrent");
		        li.style.backgroundColor = li.pagecurrent ? document.colour.selectedColor.color : document.colour.defaultColor.color;
			    li.isover = false;
			    li.hoverColor = document.colour.remoteHoverColor;
			    var aChildren = li.childNodes;
  			    for ( k = 0; k < aChildren.length ; k++ ) 
  			    {
				    var anc = aChildren.item(k);
				    if ((anc.nodeName == 'a') || (anc.nodeName == 'A'))
				    {
					    if (anc.getAttribute("href").substring(0, 1) == "#")
					    {
						    li.hoverColor = document.colour.localHoverColor;
						    break;
					    }
				    }
			    }
			    li.onmouseover = document.colour.setBGColorHi;
			    li.onmouseout = document.colour.setBGColorLo;
			    li.onclick = gotoHref;
			    li.style.cursor = navigator.compat.pointerCursor;
			    disableInnerAnchor(li);
		    }
	    }
    }
    
    this.setMenuWidth = function(mnuHeight)
    {
	    this.adjustMenuWidth(mnuHeight, 'accessmenu');
	    if (document.getElementsByTagName)
	    {
	        var m = 0;
		    var menus = document.getElementsByTagName('ul');
		    for (m = 0 ; m < menus.length ; m++)
		    {
			    var premenu = menus.item(m);
			    if (premenu.className == "premenu")
			    {
				    this.adjustMenuWidth(mnuHeight, premenu.id);
			    }
		    }
	    }
	    this.adjustMenuWidth(mnuHeight, 'innermenu');
	    mnuElem = document.getElementById('calendar');
	    if (mnuElem)
	    {
		    var layMenu = window.layout.menu;
		    var calWrapColl = mnuElem.childNodes;
		    var i = 0;
		    for (i = 0 ; i < calWrapColl.length ; i++)
		    {
			    var calWrap = calWrapColl.item(i);
			    if (calWrap.className == "CalendarMenuMap")
			    {
			        var calColl = calWrap.childNodes;
			        for (j = 0 ; j < calColl.length ; j++)
		            {
		                var cal = calColl.item(j);
		                if (cal.className == "calendar")
		                {
        				    var paddingLeft = navigator.compat.paddingExtendsWidth ? document.getCssValue(cal, "paddingLeft") : 0;
	                        cal.style.width = ((mnuHeight < layMenu.originalMenuHeight ? layMenu.innerWidth : layMenu.useWidth) - paddingLeft) + "px";
                        }
                    }
                }
                if (calWrap.className == "OthersDateMenu")
		        {
	                this.adjustMenuWidthByElement(mnuHeight, calWrap);
                }
            }
	    }
	}
	
    this.adjustMenuWidth = function(mnuHeight, menuName)
    {
	    var mnuElem = document.getElementById(menuName);
    	
	    this.adjustMenuWidthByElement(mnuHeight, mnuElem)	
    }

    this.adjustMenuWidthByElement = function(mnuHeight, mnuElem)
    {
	    if (mnuElem)
	    {
		    var liColl = mnuElem.childNodes;
		    for (i = 0 ; i < liColl.length ; i++)
		    {
			    var li = liColl.item(i);
			    if ((li.nodeName == "li") || (li.nodeName == "LI"))
			    {
				    var layMenu = window.layout.menu;
				    var paddingLeft = navigator.compat.paddingExtendsWidth ? document.getCssValue(li, "paddingLeft") : 0;
				    li.style.width = ((mnuHeight < layMenu.originalMenuHeight ? layMenu.innerWidth : layMenu.useWidth) - paddingLeft) + "px";
			    } 
		    }
	    }	
    }
    
    this.clearMenuState = function()
    {
        window.layout.menu.lastMatched = new Array();
        var menus = document.getElementsByTagName('ul');
		for (var i = 0 ; i < menus.length ; i++)
		{
		    var premenu = menus.item(i);
			if (premenu.className == "premenu")
			{
			    this.setupMenuSection(premenu);
			}
		}
        for (var j = 0 ; j < window.layout.realbody.storyAnchors.length ; j++ ) 
  	    {
		    var apd = window.layout.realbody.storyAnchors[j];
		    if (apd.menuItem != null)
		    {
			    apd.menuItem.style.backgroundColor = document.colour.defaultColor.color;
		    }
	    }
	    this.setupMenuSection(document.getElementById('innermenu'));
	    var premenu = document.getElementById("premenuArchive");
	    if (premenu != null)
	    {
    	    this.setupMenuSection(premenu);
	    }
    }
    
    this.setMenuState = function()
    {
	    if (! document.getElementById)
		    return;
		    
	    var lastMnu, matched;
	    var realbody = document.direct.realbody;
	    var currMnu = new Array();

  	    for (var j = 0 ; j < window.layout.realbody.storyAnchors.length ; j++ ) 
  	    {
		    var apd = window.layout.realbody.storyAnchors[j];
		    var offsetTop = window.realbody.getOffsetTop(apd);
		    
		    if (apd.parentNode.parentNode.className == "PersonFrame")
		    {
			    offsetTop = offsetTop + apd.parentNode.parentNode.offsetTop;
		    }
		    if (offsetTop > realbody.scrollTop)
		    {
			    if (lastMnu != null)
			    {
				    currMnu[currMnu.length] = lastMnu;
			    }
		    }
		    lastMnu = apd;
		    if (offsetTop > realbody.scrollTop + realbody.preparedHeight)
		    {
			    if (currMnu.length > 0)
			    {
				    lastMnu = null;
			    }
			    break;
		    }
	    }
	    if (lastMnu != null)
	    {
		    currMnu[currMnu.length] = lastMnu;
	    }
	    var found = new Array();
	    for (var i = 0 ; i < currMnu.length ; i++)
	    {
		    var apd = currMnu[i];
		    if (apd.menuItem != null)
		    {
			    found[found.length] = apd.menuItem;
			    if (! contains(window.layout.menu.lastMatched, apd.menuItem))
			    {
				    apd.menuItem.style.backgroundColor = document.colour.selectedColor.color;
				    apd.menuItem.iscurrent = true;
			    }
		    }
	    }
	    for (var i = 0 ; i < window.layout.menu.lastMatched.length ; i++)
	    {
		    var menuItem = window.layout.menu.lastMatched[i];
		    if (! contains(found, menuItem))
		    {
			    if (menuItem)
			    {
				    if (menuItem.isover)
				    {
					    menuItem.style.backgroundColor = menuItem.hoverColor.color;
				    }
				    else
				    {
					    menuItem.style.backgroundColor = document.colour.defaultColor.color;
				    }
				    menuItem.iscurrent = false;
			    }
		    }
	    }
	    window.layout.menu.lastMatched = found;
    }

    this.setCalendarState = function()
    {
	    if (! document.getElementById)
		    return;

	    var currMnu, lastMnu, matched;
	    var realbody = document.direct.realbody;
    	
	    // get list of events on screen
	    currMnu = new Array();
	    var k = 0;
  	    for (var j = 0 ; j < window.layout.realbody.calendarAnchors.length ; j++ ) 
  	    {
		    var apd = window.layout.realbody.calendarAnchors[j];
		    var offsetTop = window.realbody.getOffsetTop(apd);
    		
		    if (offsetTop > realbody.scrollTop)
		    {
			    if (lastMnu != null)
			    {
				    currMnu[currMnu.length] = lastMnu;
			    }
		    }
		    if (apd.className == 'eventAnchor')
		    {
			    lastMnu = apd;
		    }
		    else
		    {
			    lastMnu = null;
		    }
		    if (offsetTop > realbody.scrollTop + realbody.preparedHeight)
		    {
			    if (currMnu.length > 0)
			    {
				    lastMnu = null;
			    }
			    break;
		    }
	    }
	    if (lastMnu != null)
	    {
		    currMnu[currMnu.length] = lastMnu;
	    }
    	
	    // highlight calendar entries that match the events on screen.
	    var found = new Array();
	    for (var i = 0 ; i < currMnu.length ; i++)
	    {
		    var apd = currMnu[i];
		    if (apd.calendarItems != null)
		    {
		        for (var c = 0 ; c < apd.calendarItems.length ; c++ )
		        { 
		            var calendarItem = apd.calendarItems[c];
			        found[found.length] = calendarItem;
			        // if already highlighted, then nothing to do.
			        if (! contains(window.layout.calendar.lastMatched, calendarItem))
			        {
				        calendarItem.style.backgroundColor = document.colour.selectedColor.color;
				        calendarItem.iscurrent = true;
			        }
			    }
		    }		
	    }
    	
	    // unhighlight all the calendar entries highlighted last time but not this time.
	    for (var i = 0 ; i < window.layout.calendar.lastMatched.length ; i++)
	    {
		    var calendarItem = window.layout.calendar.lastMatched[i];
		    if (! contains(found, calendarItem))
		    {
			    if (calendarItem)
			    {
				    if (calendarItem.isover)
				    {
					    calendarItem.style.backgroundColor = document.colour.localHoverColor.color;
				    }
				    else
				    {
					    calendarItem.style.backgroundColor = document.colour.defaultCalColor.color;
				    }
				    calendarItem.iscurrent = false;
			    }
		    }
	    }
    	
	    // save the list of highlighed calendar entries for next time.
	    window.layout.calendar.lastMatched = found;
    }

    this.hideMenu = function()
    {
	    if (! document.getElementById)
		    return;
	    var menu = document.getElementById('menu');
	    //menu.style.visibility = "hidden";
    }

    this.showMenu = function()
    {
	    if (! document.getElementById)
		    return;
	    var menu = document.getElementById('menu');
	    menu.style.visibility = "inherit";
    }
}

//--------------------------------------------------------------------------------------------------------------------

function auxMenu()
{
    this.setup = function()
    {
	    if (! document.getElementById)
		    return;
	    var premenu = document.getElementById("premenuArchive");
	    if (premenu != null)
	    {
	        premenu.parentNode.removeChild(premenu);
	        premenu.className = "rightMenu";
	        var archiveMenu = document.createElement("div");
	        archiveMenu.id = "archiveMenu";
	        archiveMenu.appendChild(premenu);
	        document.getElementById("body").appendChild(archiveMenu);
	        document.direct.rightMenu = archiveMenu;
        }
    }

    this.place = function(offsetTop)
    {
	    var archiveMenu = document.direct.rightMenu;
	    if (archiveMenu != null)
	    {
	        var realbody = document.direct.realbody;
            archiveMenu.style.top = offsetTop + "px";
            archiveMenu.style.height = realbody.outerHeight + "px";
            var iframe = document.getElementById("geographIFrame");
            if (iframe != null)
            {
                iframe.style.height = realbody.outerHeight + "px";
            }
            
	        var bannerWidth = document.direct.pageBanner.offsetWidth;
            archiveMenu.style.left = (bannerWidth - (archiveMenu.offsetWidth + document.getCssValue(archiveMenu, "marginRight"))) + "px";
            var width = (bannerWidth - (window.layout.menu.totalWidth + archiveMenu.offsetWidth + 7))
            if (navigator.compat.paddingExtendsWidth)
            {
                width = width 
                            - document.getCssValue(realbody, "paddingLeft")
                            - document.getCssValue(realbody, "paddingRight");
            }
            
            realbody.style.width = width + "px";
        }
    }
}

//--------------------------------------------------------------------------------------------------------------------

function geoColumn()
{
    this.setup = function()
    {
	    if (! document.getElementById)
		    return;
	    var premenu = document.getElementById("geoMenu");
	    if (premenu != null)
	    {
	        document.direct.rightMenu = premenu;
        }
    }
}

function geograph()
{
    this.setup = function()
    {
        var iframe = window.frames['geographIFrame'];
        if (iframe != null)
        {
            iframe.window.displayMap();
        }
    }
}

function contains(arr, val)
{
	for (var k = 0 ; k < arr.length ; k++)
	{
		if (arr[k] == val)
		{
			return true;
		}
	}
	return false;
}
/* Copyright © 2006-2009 Nicholas Stimpson. All Rights Reserved */

function realbody()
{
    this.setup = function()
    {
	    if (document.direct)
	    {
		    var realbody = document.direct.realbody;
		    if (realbody != null)
		    {
			    realbody.onscroll = this.setScrollState;
		    }
            this.activateIndirectContent();
            this.resizeIndirectContent();
	    }
	}

    this.activateIndirectContent = function()
    {
        // Work around for the 'click to activate this control' behaviour resulting from the Eolas patent.
        if (window.opera)
        {
            // msie code below doesn't quite work for opera because of entity reference encoding problems.
            var indirectContent = document.direct.indirectContent;
            if (indirectContent != null)
            {
                var newIndirectContent = indirectContent.cloneNode(true);
                var container = indirectContent.parentNode;
                container.replaceChild(newIndirectContent, indirectContent);
                document.direct.indirectContent = newIndirectContent;
           }
        }
        if (window.msie)
        {
            // Adapted from http://www.thefutureoftheweb.com/blog/work-around-click-to-activate-and-use-this-control
            // Thanks to Jesse Skinner.
            
            // MS have now licensed the patent and plan to remove this limitation in April 2008 
            // - so review this code after then.
            
            var indirectContent = document.direct.indirectContent;
            if (indirectContent != null)
            {
                // find param tags within object
                var params = indirectContent.getElementsByTagName('param');
                var inner = '';

                // if there are params, but param tags can't be found within innerHTML
                if (params.length && !/<param/i.test(indirectContent.innerHTML))
                {
                    // add all param tags to 'inner' string
                    for (var x=0;x < params.length;x++)
                    {
                        inner += params.item(x).outerHTML;
                    }
                }

                // put 'inner' string with param tags in the middle of the outerHTML
                var container = indirectContent.parentNode;
                indirectContent.outerHTML = indirectContent.outerHTML.replace('>', '>' + inner);
                document.direct.indirectContent = document.getElementById("indirect-content");
            }
        }
    }

    this.resizeIndirectContent = function()
    {
        var indirectContent = document.direct.indirectContent;
        if (indirectContent != null)
        {
            if (! indirectContent.style)
            {
                indirectContent.style = new Object();
            }
            var realbody = document.direct.realbody;
            if (realbody.preparedHeight)
            {
                var imgHeight = realbody.outerHeight - 6;
                for (var peer = indirectContent.nextSibling ; peer != null ; peer = peer.nextSibling)
                {
                    peer.style.display = "none";
                }
                indirectContent.style.height = imgHeight + "px";
                indirectContent.style.width="100%";
            }
            else
            {
                indirectContent.style.height="98%";
                indirectContent.style.width="100%";
            }
        }
    }

    this.setScrollState = function()
    {
	    window.menu.setMenuState();
	    window.menu.setCalendarState();
    }

    this.getOffsetTop = function(apd)
    {
	    var offsetTop = apd.offsetTop;
	    if (navigator.compat.scrollRelativeOffsets)
	    {
		    var realbody = document.direct.realbody;
		    offsetTop += realbody.scrollTop;
	    }
	    else if (navigator.compat.pageRelativeOffsets)
	    {
		    var bannerHeight = document.getElementById('EmpressBanner').offsetHeight;
		    var fontPosition = 3;	// all positions after the first are this much too low
								    // for a reason I haven't yet discerned.
		    var tabs = document.direct.tabs;
		    offsetTop = offsetTop - (bannerHeight + tabs.totalHeight + fontPosition);
	    }
	    return offsetTop;
    }

    this.positionAnchor = function()
    {
	    if (location.hash.length > 0)
	    {
		    var ancr = document.getElementById(location.hash.substring(1));
		    if (ancr)
		    {
		        var realbody = document.direct.realbody;
		        realbody.scrollTop = ancr.offsetTop;
		    }
	    }
    }
    
    this.spreadQAAnswers = function()
    {
        if (window.opera && (window.opera.version() < 10)) return; // opera 9 layout is incomprehensible.

        var minRightMargin = 20;
        if (document.getElementsByClassName)
        {
            var qas = document.getElementsByClassName("QA");
            for (var i = 0 ; i < qas.length ; i++)
            {
                var answers = qas[i].childNodes;
                for (var j = 0 ; j < answers.length ; j++)
                {
                    if (answers[j].className == 'Answer')
                    {
                        var availableWidth = answers[j].offsetWidth - 1;
                        var results = answers[j].childNodes;
                        var maxlen = 0;
                        for (var k = 0 ; k < results.length ; k++)
                        {
                            results[k].style.borderRightWidth = "0px";
                            maxlen = Math.max(maxlen, results[k].offsetWidth);
                        }
                        var maxResultsPerRow = Math.floor(availableWidth / (maxlen + minRightMargin));
                        var nrows = Math.ceil(results.length / maxResultsPerRow);
                        var ncolumns = Math.ceil(results.length / nrows);
                        var widthPerCell = Math.floor(availableWidth / ncolumns);
                        var remainderWidth = availableWidth - (widthPerCell * ncolumns);
                        for (var k = 0 ; k < results.length ; k++)
                        {
                            results[k].style.borderRightWidth = (widthPerCell + ((k % ncolumns) < remainderWidth ? 1 : 0) - results[k].offsetWidth) + "px";
                        }
                    }
                }
            }
        }
    }
}

function gotoHref()
{
    var cn = this.childNodes;
    for ( j = 0; j < cn.length; j++ ) 
    {
	    var anchor = cn.item(j);
	    if (anchor.href)
	    {
		    location.href = anchor.href;
		    window.realbody.setScrollState();
		    return;
	    }
    }
}

function images()
{
    this.setup = function()
    {
	    if (document.getElementsByTagName)
	    {
		    imgs = document.getElementsByTagName('img');
		    for (j = 0 ; j < imgs.length ; j++)
		    {
			    var im = imgs.item(j);
			    im.tabIndex="0";
			    if (im.className == "Image")
			    {
			        this.fixupClassName(im);
			    } 
		    }
		    imgs = document.getElementsByTagName('iframe');
		    for (j = 0 ; j < imgs.length ; j++)
		    {
			    var im = imgs.item(j);
			    im.tabIndex="0";
			    if (im.className == "Geograph")
			    {
			        this.fixupClassName(im);
			    } 
		    }
	    }
    }

    this.fixupClassName = function(im)
    {
	    var container = im.parentNode;
	    while (container.className == "ImageAnchor")
	    {
	        container = container.parentNode;
	    }
	    if (container.className == "ImageWrap")
	    {
    	    if (this.getAncestorWithClass(container, "BannerImageFrame") != null)
    	    {
		        return;
		    }
		    else (this.getAncestorWithClass(container, "SequenceImageFrame") != null)
		    {
		        container = container.parentNode;
		    }
	    }
	    else if ((container.className == "HeaderImageFrame") || (container.className == "HeaderImageFrameJS"))
		    container.className = navigator.compat.floatImages ? "HeaderImageFrameJS" :"HeaderImageFrame";
	    else if ((container.className == "LogoFrame") || (container.className == "LogoFrameJS"))
		    container.className = navigator.compat.floatImages ? "LogoFrameJS" :"LogoFrame";					
	    else
		    container.className = navigator.compat.floatImages ? "ImageFrameJS" :"ImageFrame";
    	
	    this.setCaptionDimensions(im);
    }

    this.setCaptionDimensions = function(im)
    {
        var container = im.parentNode;
	    var captions = container.childNodes;
	    for (i = 0 ; i < captions.length ; i++)
	    {
		    var caption = captions.item(i);
		    if ((caption.className == "Caption") || 
			    (caption.className == "HeaderCaption") || 
			    (caption.className == "Citation") ||
			    (caption.className == "SizeControl"))
		    {
		        /* IE7 needs a preset of the width to a small value to avoid a horizontal scroll bar! 
		         * It shows up on the "region" page because of the caption on the WA Mensa picture.
		         */
		        caption.style.width = "10px"; 
		        
			    caption.style.width = im.offsetWidth + "px";
			    var sequenceImageFrame = this.getAncestorWithClass(caption, "SequenceImageFrame")
	            if (sequenceImageFrame != null)
	            {
	                if (sequenceImageFrame.maxCaptionHeight)
	                {
	                    sequenceImageFrame.maxCaptionHeight = Math.max(sequenceImageFrame.maxCaptionHeight, caption.offsetHeight);
                    }
                    else
                    {
                        sequenceImageFrame.maxCaptionHeight = caption.offsetHeight;
                    }
	            }
		    } 
	    }
	    for (i = 0 ; i < captions.length ; i++)
	    {
		    var caption = captions.item(i);
		    if ((caption.className == "Caption") || 
			    (caption.className == "HeaderCaption") || 
			    (caption.className == "Citation") ||
			    (caption.className == "SizeControl"))
		    {
			    var sequenceImageFrame = this.getAncestorWithClass(caption, "SequenceImageFrame")
	            if (sequenceImageFrame != null)
	            {
	                if (sequenceImageFrame.maxCaptionHeight)
	                {
	                    caption.style.height = sequenceImageFrame.maxCaptionHeight + "px";
	                }
	            }
		    } 
	    }
    }

    this.getAncestorWithClass = function(elem, className)
    {
        if (elem.parentNode == null)
        {
            return null;
        }        
        if (elem.parentNode.className == className)
        {
            return elem.parentNode;
        }
        return this.getAncestorWithClass(elem.parentNode, className);
    }
}           

//--------------------------------------------------------------------------------------------------------------------

function corners()
{
    var gs0;
    var gs1; 
    var gs2;
    var gs3;  
    var gs4;
    var gs5;
    var gs6;
    var gs7;
    var gs8;
    var gs9;
    var nul;
    
    this.setup = function()
    {
	    if (! document.getElementById)
		    return;
		    
        var filterHue = document.colour.defaultColor;
        gs0 = new Hue('#000000').filter(filterHue);
        gs1 = new Hue('#202020').filter(filterHue); 
        gs2 = new Hue('#787878').filter(filterHue);
        gs3 = new Hue('#BABABA').filter(filterHue);  
        gs4 = new Hue('#E5E5E5').filter(filterHue);
        
        gs5 = new Hue('#1F1F1F').filter(filterHue);
        gs6 = new Hue('#A7A7A7').filter(filterHue);
        gs7 = new Hue('#FCFCFC').filter(filterHue);
        
        gs8 = new Hue('#747474').filter(filterHue);
        gs9 = new Hue('#F2F2F2').filter(filterHue);
        
        nul = new Hue('#FFFFFF');		    

	    var pageBanner = document.direct.pageBanner;
	    var bannerHeight = pageBanner.offsetHeight;
	    var bannerWidth = pageBanner.offsetWidth;
	    var realbody = document.direct.realbody;
	    var top = realbody.offsetTop;
	    var bottom = realbody.offsetTop + realbody.outerHeight - 1;
	    var right = realbody.offsetWidth + document.getCssValue(realbody, "marginLeft") + document.getCssValue(realbody, "marginRight");

	    var body = document.direct.body;
	    if (body)
	    {
		    if (! body.appendChild)
			    return;
		    var cornerTL = body.appendChild(document.createElement("span"));
		    cornerTL.setAttribute("id", "CornerTL");
		    var cornerTR = body.appendChild(document.createElement("span"));
		    cornerTR.setAttribute("id", "CornerTR");
		    var cornerBL = body.appendChild(document.createElement("span"));
		    cornerBL.setAttribute("id", "CornerBL");
		    var cornerBR = body.appendChild(document.createElement("span"));
		    cornerBR.setAttribute("id", "CornerBR");
    		
		    this.addCorner10(cornerTL, 1, 1);
		    this.addCorner10(cornerTR, 1, -1);
		    this.addCorner10(cornerBL, -1, 1);
		    this.addCorner10(cornerBR, -1, -1);
		    
		    this.placeCorner(cornerTL, top, window.layout.menu.totalWidth, false);
	        this.placeCorner(cornerTR, top, right, true);
	        this.placeCorner(cornerBL, bottom, window.layout.menu.totalWidth, false);
	        this.placeCorner(cornerBR, bottom, right, true);
    		
		    var cornerUTL = body.appendChild(document.createElement("span"));
		    cornerUTL.setAttribute("id", "CornerUTL");
		    var cornerUTR = body.appendChild(document.createElement("span"));
		    cornerUTR.setAttribute("id", "CornerUTR");
		    var cornerUBL = body.appendChild(document.createElement("span"));
		    cornerUBL.setAttribute("id", "CornerUBL");
		    var cornerUBR = body.appendChild(document.createElement("span"));
		    cornerUBR.setAttribute("id", "CornerUBR");
    		
		    this.addUCorner10(cornerUTL, 1, 1);
		    this.addUCorner10(cornerUTR, 1, -1);
		    this.addUCorner10(cornerUBL, -1, 1);
		    this.addUCorner10(cornerUBR, -1, -1);
		    
		    this.placeCorner(cornerUTL, 5, 5, false);
		    this.placeCorner(cornerUTR, 5, 5, true);
	        this.placeCorner(cornerUBL, bannerHeight - 6, 5, false);
	        this.placeCorner(cornerUBR, bannerHeight - 6, 5, true);
	        
	        this.cornerReplace();
	    }
	}

    this.cornerReplace = function()
    {
        var cornerTL = document.getElementById('CornerTL');
	    var cornerTR = document.getElementById('CornerTR');
	    var cornerBL = document.getElementById('CornerBL');
	    var cornerBR = document.getElementById('CornerBR');
	    
	    var cornerUBL = document.getElementById('CornerUBL');
	    var cornerUBR = document.getElementById('CornerUBR');

	    cornerTL.style.display = 'none';
	    cornerTR.style.display = 'none';
	    cornerBR.style.display = 'none';
	    cornerBL.style.display = 'none';
	    
	    cornerUBR.style.display = 'none';
	    cornerUBL.style.display = 'none';

	    var pageBanner = document.getElementById('PageBanner');
	    if (pageBanner == null)
	    {
		    pageBanner = document.getElementById('EmpressBanner');
	    }
	    var bannerHeight = pageBanner.offsetHeight;
	    var bannerWidth = pageBanner.offsetWidth;
	    var realbody = document.direct.realbody;
	    var top = realbody.offsetTop;
	    var bottom = realbody.offsetTop + realbody.outerHeight - 1;
	    var right = realbody.offsetWidth - realbody.clientWidth + 6;
	    if (document.direct.rightMenu != null)
	    {
	        right = right + document.direct.rightMenu.offsetWidth + 2;
	    }
	    
	    this.placeCorner(cornerTL, top, window.layout.menu.totalWidth, false);
	    this.placeCorner(cornerTR, top, right, true);
	    this.placeCorner(cornerBL, bottom, window.layout.menu.totalWidth, false);
	    this.placeCorner(cornerBR, bottom, right, true);
	    
	    this.placeCorner(cornerUBL, bannerHeight - 6, 5, false);
	    this.placeCorner(cornerUBR, bannerHeight - 6, 5, true);
        
        cornerTL.style.display = 'inline';
	    cornerTR.style.display = 'inline';
	    cornerBR.style.display = 'inline';
	    cornerBL.style.display = 'inline';
	    
	    cornerUBR.style.display = 'inline';
	    cornerUBL.style.display = 'inline';
    }
    
    this.placeCorner = function(cornerArea, v, h, rgt)
    {
        cornerArea.style.top = v + "px";
        if (rgt)
        {
            cornerArea.style.right = h + "px";
        }
        else
        {
            cornerArea.style.left = h + "px";
        }
    }
    
    var drop = function(corner)
    {
        corner.parentNode.removeChild(corner);
    }
    
    this.resetup = function()
    {
    	if (! document.getElementById)
		    return;
		    
        drop(document.getElementById('CornerTL'));
	    drop(document.getElementById('CornerTR'));
	    drop(document.getElementById('CornerBL'));
	    drop(document.getElementById('CornerBR'));
	    
        drop(document.getElementById('CornerUTL'));
	    drop(document.getElementById('CornerUTR'));
	    drop(document.getElementById('CornerUBL'));
	    drop(document.getElementById('CornerUBR'));
	    
	    this.setup();
    }
    

    
    this.addCorner10 = function(cornerArea, vInc, hInc)
    {
        cornerArea.style.position = 'absolute';
        cornerArea.style.zIndex = 1;
        this.addCornerLine10(cornerArea, vInc * 0, hInc, gs0, gs0, gs0, gs0, gs0, gs0, gs1, gs2, gs3, gs4);
        this.addCornerLine10(cornerArea, vInc * 1, hInc, gs0, gs0, gs0, gs0, gs5, gs6, gs7);
        this.addCornerLine10(cornerArea, vInc * 2, hInc, gs0, gs0, gs0, gs8, gs9);
        this.addCornerLine10(cornerArea, vInc * 3, hInc, gs0, gs0, gs8);
        this.addCornerLine10(cornerArea, vInc * 4, hInc, gs0, gs5, gs9);
        this.addCornerLine10(cornerArea, vInc * 5, hInc, gs0, gs6);
        this.addCornerLine10(cornerArea, vInc * 6, hInc, gs1, gs7);
        this.addCornerLine10(cornerArea, vInc * 7, hInc, gs2);
        this.addCornerLine10(cornerArea, vInc * 8, hInc, gs3);
        this.addCornerLine10(cornerArea, vInc * 9, hInc, gs4);
    }
    
    this.addUCorner10 = function(cornerArea, vInc, hInc)
    {
        cornerArea.style.position = 'absolute';
        cornerArea.style.zIndex = 1;
        this.addCornerLine10(cornerArea, vInc * 0, hInc, gs0, gs0, gs0, gs0, gs0, gs0, gs1);
        this.addCornerLine10(cornerArea, vInc * 1, hInc, gs0, gs0, gs0, gs0);
        this.addCornerLine10(cornerArea, vInc * 2, hInc, gs0, gs0, gs0);
        this.addCornerLine10(cornerArea, vInc * 3, hInc, gs0, gs0);
        this.addCornerLine10(cornerArea, vInc * 4, hInc, gs0);
        this.addCornerLine10(cornerArea, vInc * 5, hInc, gs0);
        this.addCornerLine10(cornerArea, vInc * 6, hInc, gs1);
    }
    
    this.addCornerLine10 = function(cornerArea, v, hInc)
    {
        for (var i = 3 ; i < arguments.length ; i++)
        {
            this.addCornerCellHue(cornerArea, v, hInc * (i - 3), arguments[i]);
        }
    }
    
    this.addCornerCellHue = function(cornerArea, row, left, clr)
    {
        var cornerCell = cornerArea.appendChild(document.createElement("span"));
        cornerCell.className = "cornerLF";
        cornerCell.appendChild(document.createTextNode(" "));
        cornerCell.style.top = row + "px";
        cornerCell.style.left = left + "px";
        cornerCell.style.zIndex = 1;
        cornerCell.style.backgroundColor = clr.color;
    }
}

/* Copyright � 2006-2009 Nicholas Stimpson. All Rights Reserved */

function resize()
{
	if (! navigator.compat.independentScrollAreas)
		return;
		
	// protect against IE resize bug
    var currentSize = window.viewport.getDimensions();
    if (window.viewportSize)
        if (currentSize.width == window.viewportSize.width && currentSize.height == window.viewportSize.height)
            return;     // bogus resize event
    window.viewportSize = currentSize;
	
	if (document.getElementById)
	{
		window.onresize=null;
		var vpHeight = currentSize.height;
		var tabs = document.direct.tabs;
		
		window.tabs.tabsDistribute(tabs, true);
		
		var realbody = document.direct.realbody;
		
		var menu = document.direct.menu;
		var rightMenu = document.direct.rightMenu;
		var pageBanner = document.direct.pageBanner;
		var bannerHeight = pageBanner.offsetHeight;
		var bannerWidth = pageBanner.offsetWidth;

		realbody.outerHeight = vpHeight - (bannerHeight + tabs.totalHeight + window.layout.viewport.bottomMargin);
		if (navigator.compat.paddingExtendsWidth)
		{
		    realbody.preparedHeight = realbody.outerHeight - (document.getCssValue(realbody, "paddingTop") + document.getCssValue(realbody, "paddingBottom"));
		}
		else
		{
		    realbody.preparedHeight = realbody.outerHeight;
		}
		
		realbody.style.height = realbody.preparedHeight + "px";
		
		menu.style.height = realbody.outerHeight + "px";
		window.menu.setMenuWidth(realbody.outerHeight);
		window.auxMenu.place(bannerHeight + tabs.totalHeight);
		
        if (document.getElementsByTagName)
    	{
	        var imgs = document.getElementsByTagName("img");
	        if ((imgs != null) && imgs.length > 0)
	        {
                sizeImages(imgs);
	        }
	    }
	    
	    setTimeout(function() { window.realbody.spreadQAAnswers(); }, 1);
	    
        window.realbody.resizeIndirectContent();
	    
	    var cornerArea = document.getElementById('CornerTL');
		if (cornerArea)
		{
		    // defer the corner adjustment so IE6 catches up with the new location of realbody.
		    // cornerReplace call must be wrapped in an anonymous function to get the value 
		    // of "this" correct inside the function.
			setTimeout(function() { window.corners.cornerReplace(); }, 1);
		}

		padToBottom();
		
		window.onresize=resize;
	}
	
	function padToBottom()
	{
	    var realbody = document.direct.realbody;
	    var ip = document.getElementById('ip');
        var content = document.getElementById('content');
        if (getDisplayHeight(realbody) > getDisplayHeight(content) + getDisplayHeight(ip))
        {
            content.style.paddingBottom = (document.getCssValue(content, "paddingBottom") + getDisplayHeight(realbody) - (getDisplayHeight(content) + getDisplayHeight(ip))) + "px";
        }
        if (document.getElementsByClassName)
        {
            var localEvents = document.getElementsByClassName("localEvent");
            if (localEvents.length > 0)
            {
                var lastLocalEvent = localEvents[localEvents.length - 1];
                var pad = realbody.outerHeight - getDisplayHeight(lastLocalEvent) - getDisplayHeight(ip);
                if (document.getCssValue(content, "paddingBottom") < pad)
                {
                    content.style.paddingBottom = pad + "px";
                }
            }
        }
    }
    
    function sizeImages(imgs)
    {
        document.getElementById('content').style.paddingBottom = null;
        var realbody = document.direct.realbody;
        var body = document.getElementById('body');
        var realcontent = document.getElementById('realcontent');
        if (realcontent == null)
            return;
        var ip = document.getElementById('ip');
        var content = document.getElementById('content');
        var maxWidth = getDisplayWidth(body);
        maxWidth = maxWidth - (document.getCssValue(realbody, "marginLeft") + document.getCssValue(realbody, "marginRight"));
	    maxWidth = maxWidth - (realbody.preparedHeight < realbody.scrollHeight ? window.layout.realbody.vScrollWidth : 0);
	    var maxHeight = realbody.outerHeight - getDisplayHeight(ip);
	    for (j = 0 ; j < 2 ; j++)
	    {
            for (i = 0 ; i < imgs.length ; i++)
            {
                var img = imgs.item(i);
                if (img.parentNode.className == "HeaderImageFrameJS")
                {
                    if ((img.id == null) || (img.id.length == 0))
                    {
                        img.id = "DynamicID" + document.dynamicIdIndex++;
                    }
                    if (img.fixedSize != "true")
                    {
                        imgHeight = maxHeight;
                        imgHeight = imgHeight - (getDisplayHeight(content) - img.clientHeight);
                        imgHeight = (imgHeight > 200 ? imgHeight : 200);
                        img.style.height = imgHeight + "px";
                        img.style.width = "auto";
                   
                        imgWidth = maxWidth - ((img.offsetLeft + (navigator.compat.positioningFloat ? 0 : img.parentNode.offsetLeft)) * 2);
                        imgWidth = (imgWidth > 200 ? imgWidth : 200);
                        if (getDisplayWidth(img) > imgWidth)
                        {
                            img.style.height = "auto";
                            img.style.width = imgWidth + "px";
                        }

                        window.images.setCaptionDimensions(img);
                        attachSizeControl(img);
                    }
                }
            }
        }

        function attachSizeControl(img)
        {
            if (img.nextSibling)
            {
                var control = img.nextSibling;
                if (control.className != "SizeControl")
	            {
	    	        control = document.createElement("div"); 
	                control.className = "SizeControl";
	                control.style.width = img.offsetWidth + "px";
	                innercontrol = document.createElement("div"); 
	                innercontrol.className = "SizeControlInner";
	                anchor = document.createElement("a"); 
	                anchor.style.cursor = navigator.compat.pointerCursor;
	                anchor.className = "SizeControlAnchor";
	                anchor.id = "DynamicID" + document.dynamicIdIndex++;
	                anchor.onclick = function() { toggleSizeControl(anchor.id,img.id); } ;
	                anchor.scaled = true;
	                anchor.appendChild(document.createTextNode("Scale to original size"));
	                innercontrol.appendChild(anchor);
	                control.appendChild(innercontrol);
	                img.parentNode.insertBefore(control, img.nextSibling);
                }
            }
            
            function toggleSizeControl(anchorId, imgId)
            {
                var img = document.getElementById(imgId);
                var anchor = document.getElementById(anchorId);
                if (! anchor.scaled)
                {
                    anchor.firstChild.nodeValue = "Scale to original size";
                    img.fixedSize='false';
                    sizeImages(document.getElementsByTagName('img'));
                    window.images.setCaptionDimensions(img);
                }
                else
                {
                    anchor.firstChild.nodeValue = "Scale to Fit";
                    img.style.height="auto";
                    img.style.width="auto";
                    img.fixedSize='true';
                    window.images.setCaptionDimensions(img);
                }
                
                padToBottom();
                
                anchor.scaled = ! anchor.scaled;
                return false;
            }
        }
    }
}

function textScaleDetector()
{
    // In the CSS this iframe will obtain a width measured in 'Em's. When a user
    // changes their text size, the iframe will change size and its resize event
    // will fire. The onresize handler then calls the resize function above on
    // the main page.
    this.setup = function()
    {
    	if (document.getElementById && document.createElement)
	    {
	        var iframe = document.createElement("iframe");
	        iframe.id = "emTextScale";
	        iframe.name = "emTextScale";
	        iframe.width = "1";
	        iframe.height = "1";
	        iframe.scrolling = "no";
	        iframe.src = "html/textScale.html";
	        document.getElementById("body").appendChild(iframe);
        }
    }

    this.scale = function()
    {
        window.tabs.reset();
        resize();
    }
}

function styleChangeDetector()
{
    // In the CSS this iframe is assigned an id "styleChange" which is will 
    // obtain a width defined by the CSS. Each CSS file will define cssSignature 
    // with different width in pixels. If the user changes the CSS stylesheet, the 
    // size of the iframe will change and it's resize event will fire. The 
    // onresize handler then calls the resize function above on the main page.
    this.setup = function()
    {
    	if (document.getElementById && document.createElement)
	    {
	        var iframe = document.createElement("iframe");
	        iframe.id = "styleChange";
	        iframe.name = "styleChange";
	        iframe.width = "1";
	        iframe.height = "1";
	        iframe.scrolling = "no";
	        iframe.src = "html/cssCharacteristic.html";
	        document.getElementById("body").appendChild(iframe);
        }
    }

    this.scale = function()
    {
        document.colour = new colour();
        window.tabs.reset();
        window.menu.resetState();
        window.corners.resetup();
        if (window.cacadeStyleSheet)
        {
            window.cacadeStyleSheet.preserve();
        }
    }
}



/* Copyright � 2006-2009 Nicholas Stimpson. All Rights Reserved */

window.tabStates =
{
    DEFAULT: 1,
    SELECTED: 2,
    HOVER: 3
};

function tabs()
{
    this.setup = function()
    {
	    if (! document.direct)
		    return;
	    var tabs = document.direct.tabs;
	    if (tabs)
	    {
		    tabs.totalHeight = 0; // initialise
    		
		    if (! tabs.appendChild)
			    return;
	        this.measureTabs(tabs);
    		    
   	        window.menu.hideMenu();
    		
		    try
		    {
		        this.hideSeparators(tabs);
		        this.addTabs(tabs);
		        this.tabsDistribute(tabs, false);
		    }
            finally
            {
		        window.menu.showMenu();
		    }
	    }
	}

    this.hideSeparators = function(tabs)
    {
	    var i;
	    var tabColl = tabs.childNodes;

	    for (i = 0 ; i < tabColl.length ; i++)
	    {
		    var tab = tabColl.item(i);
		    if (tab.className == "LinkSeparator")
		    {
			    tab.style.display = "none";
		    } 
	    }
    }
    
    this.addTabs = function(tabs)
    {
        // To avoid time taken doing page updates, remove the tabs section from the DOM
        var parent = tabs.parentNode;
        var following = tabs.nextSibling;
        parent.removeChild(tabs);
        
	    for (var i = 0 ; i < tabs.tabSet.length ; i++)
	    {
		    var tab = tabs.tabSet[i];
		    tab.style.position = "absolute";
		    tab.style.zIndex = tabs.tabSet.length + 2 - i;
		    tab.style.backgroundColor = "transparent";
		    if (tab.getElementsByTagName("input").length + tab.getElementsByTagName("INPUT").length == 0)
		    {
		        this.tabForge(tab);
		        tab.onclick = this.tabClick;
		        tab.onmouseover = this.tabHi;
		        tab.onmouseout = this.tabLo;
		    }
		    disableInnerAnchor(tab);
	    }
	    
	    // now put the tabs back in the DOM
	    parent.insertBefore(tabs, following);
    }
    
    this.tabClick = function()
    {
        var tabElem = window.tabs.getRealTab(this);
        var anchorColl = tabElem.childNodes;
        for (i = 0 ; i < anchorColl.length ; i++)
        {
	        var anchor = anchorColl.item(i);
	        if (anchor.href)
	        {
		        location.href = anchor.href;
		        return;
	        } 
        }
    }
    
    this.tabHi = function()
    {
        try { window.tabs.setTabHi(window.tabs.getRealTab(this)); } catch (err) {};
    }

    this.tabLo = function()
    {
        try { window.tabs.setTabLo(window.tabs.getRealTab(this)); } catch (err) {};
    }

    this.tabForge = function(realTab)
    {
	    realTab.LF = new Array();
	    var h = document.direct.tabs.tabHeight;
	    realTab.hgt = h;
	    realTab.minTabWidth = realTab.originalWidth + Math.round(h / window.layout.tabs.gradient) - 2;
	    for (var i = 0 ; i < h ; i++)
	    {
		    var tabElem = realTab.appendChild(document.createElement("span"));
		    tabElem.className = "tabLF";
		    tabElem.appendChild(document.createTextNode(" "));
		    tabElem.defaultColor = document.colour.colorShade(document.colour.defaultColor, i, h);
		    tabElem.selectedColor = document.colour.colorShade(document.colour.selectedColor, i, h);
		    tabElem.shadowColor = document.colour.colorShade(document.colour.shadowColor, i, h);
		    tabElem.hoverColor = document.colour.colorShade(document.colour.remoteHoverColor, i, h);
	    
		    tabElem.style.top = i + "px";
		    tabElem.style.cursor = navigator.compat.pointerCursor;

		    this.setColor(tabElem, (realTab.className == "tab") ? window.tabStates.DEFAULT : window.tabStates.SELECTED);
		    tabElem.realTab = realTab;
		    realTab.LF[i] = tabElem;
	    }
    }
    
    this.measureTabs = function(tabs)
    {
	    var j = 0;
	    var tabColl = tabs.childNodes;
	    var gotHeight = false;
	    
	    tabs.originalHeight = 0;

	    tabs.tabSet = new Array();
	    for (var i = 0 ; i < tabColl.length ; i++)
	    {
		    var tab = tabColl.item(i);
		    if ((tab.className == "tab") || (tab.className == "tabCurrent"))
		    {
			    tab.originalWidth = window.opera ? tab.clientWidth : tab.offsetWidth;
			    //tab.originalWidth = tab.offsetWidth;
			    tab.originalHeight = tab.offsetHeight;
			    tabs.tabSet[j++] = tab;
			    if (! gotHeight)
			    {
			        tabs.tabHeight = Math.floor( (tab.offsetHeight * 4) / 3);;
			        gotHeight = true;
			    }
		    } 
	    }
    }
    
    this.reset = function ()
    {
	    if (! document.direct)
		    return;

	    var tabs = document.direct.tabs;
	    if (tabs)
	    {
		    if (! tabs.appendChild)
			    return;
			    
			this.measureTabs(tabs);

	        window.menu.hideMenu();

            try
            {
	            for (var i = 0 ; i < tabs.tabSet.length ; i++)
	            {
		            var tab = tabs.tabSet[i];
		            this.tabReforge(tab);
	            }
		        this.tabsDistribute(tabs, false);
		    }
            finally
            {
		        window.menu.showMenu();
		    }
	    }
	}
	    
    this.tabReforge = function(realTab)
    {
        if (realTab.LF)
        {
            var h = document.direct.tabs.tabHeight;
            realTab.hgt = h;
            realTab.minTabWidth = realTab.originalWidth + Math.round(h / window.layout.tabs.gradient) - 2;
            if (h < realTab.LF.length)
            {
                for (var i = realTab.LF.length - 1 ; i >= h ; i--)
                {
                    var tabElem = realTab.LF[i];
                    realTab.removeChild(tabElem);
                }
                realTab.LF.length = h;
            }

            for (var i = realTab.LF.length ; i < h ; i++)
            {
                var tabElem = realTab.appendChild(document.createElement("span"));
                tabElem.className = "tabLF";
                tabElem.appendChild(document.createTextNode(" "));
		        tabElem.style.top = i + "px";
		        tabElem.style.cursor = navigator.compat.pointerCursor;
	            tabElem.realTab = realTab;
	            realTab.LF[i] = tabElem;
            }
            for (var i = 0 ; i < h ; i++)
            {
                var tabElem = realTab.LF[i];
                tabElem.defaultColor = document.colour.colorShade(document.colour.defaultColor, i, h);
                tabElem.selectedColor = document.colour.colorShade(document.colour.selectedColor, i, h);
                tabElem.shadowColor = document.colour.colorShade(document.colour.shadowColor, i, h);
                tabElem.hoverColor = document.colour.colorShade(document.colour.remoteHoverColor, i, h);
		        this.setColor(tabElem, (realTab.className == "tab") ? window.tabStates.DEFAULT : window.tabStates.SELECTED);
	        }
	    }
    }

    this.tabsDistribute = function(tabs, resize)
    {
	    if (tabs)
	    {
		    if (tabs.tabSet.length > 0)
	        {
			    var tabSpace = document.direct.tabs.offsetWidth - 2 - window.layout.tabs.overlap;
			    var rows = this.tabsRowsNeeded(tabs, tabSpace);
			    var tabsHeight = tabs.tabSet[0].hgt;
			    var lastPushback = 0;
    			
			    while (true)
			    {
			        var res = this.tabsDistrib(tabs, document.direct.pageBanner.offsetHeight, 0, tabSpace, 0, rows);
			        if (res == 0)
			            break;
			        if (res == lastPushback) // protect against loop - Opera 9.50beta - Check full version.
			            break;
			        rows++;
			        lastPushback = res;
			    }
    			
			    tabs.totalHeight = tabsHeight * rows + window.layout.tabs.marginBelow;
   			    tabs.style.paddingBottom = (tabs.totalHeight - (tabs.offsetHeight - document.getCssValue(tabs, "paddingBottom"))) + "px";
    		
		        var slopeLens = new Array();
		        var tab = tabs.tabSet[0];
		        for (i = 0 ; i < tab.hgt ; i++)
		        {
		            slopeLens[i] = Math.round((tab.hgt - i) / window.layout.tabs.gradient);
	            }

                if (tabs.tabSet.length > 0)
                {
       	            var chamferWidth =  (2 * Math.round(tabs.tabSet[0].hgt / window.layout.tabs.gradient)) - window.layout.tabs.overlap;
	                for (var k = 0 ; k < tabs.tabSet.length ; k++)
	                {
		                this.tabPainter(tabs.tabSet[k], chamferWidth, slopeLens);
	                }
	            }
	        }
	    }
	}
	
	this.tabsRowsNeeded = function(tabs, tabSpace)
    {
	    var k;
	    var rows = 1;
	    var offset = 0;
	    if (tabs.tabSet.length < 1)
	    {
	        return 0;
	    }
	    var chamferWidth =  (2 * Math.round(tabs.tabSet[0].hgt / window.layout.tabs.gradient)) - window.layout.tabs.overlap;
	    for (k = 0 ; k < tabs.tabSet.length ; k++)
	    {
		    var tab = tabs.tabSet[k];
		    
		    var width = tab.originalWidth + chamferWidth;
		    if (offset + width > tabSpace)
		    {
			    rows++;
			    offset = width;
		    }
		    else
		    {
			    offset = offset + width;
		    }
	    }	
	    return rows;
    }

    this.tabsDistrib = function(tabs, top, first, tabSpace, currrow, nrows)
    {
	    if (nrows == currrow)
	    {
		    return 0;
	    }
	    if (tabs.tabSet.length > 0)
	    {
		    var tabsHeight = tabs.tabSet[0].hgt;
		    var leftChamfer = Math.round(tabsHeight / window.layout.tabs.gradient);
    	    var chamferWidth =  (2 * leftChamfer) - window.layout.tabs.overlap;
		    var widthToEnd = 0;
		    for (var k = first ; k < tabs.tabSet.length ; k++)
		    {
			    var tab = tabs.tabSet[k];
			    widthToEnd = widthToEnd + tab.originalWidth;
		    }
		    var optimumRight = widthToEnd / (nrows - currrow);
		    var width = 0;
		    var widthToCurrent = 0;
		    // allocate tabs to the current row
		    var tabRowGroup = new Array();
		    var newrow = true;
		    for (var k = first ; k < tabs.tabSet.length ; k++, newrow = false)
		    {
			    var tab = tabs.tabSet[k];
			    tab.overlapped = true;
			    if ((! tab.LF) && (k > first))
			    {
			        tabs.tabSet[k - 1].overlapped = false;
			    }
			    var offsetToCurrent = widthToCurrent;
			    widthToCurrent = widthToCurrent + tab.originalWidth;

			    if (widthToCurrent > optimumRight)
			    {
			        var pushback;
				    if ((widthToCurrent - optimumRight) > (optimumRight - offsetToCurrent))
				    {
					    pushback = this.tabsDistrib(tabs, top + tabsHeight, k, tabSpace, currrow + 1, nrows);
					    widthToCurrent = offsetToCurrent;
					    for (p = 0 ; p < pushback ; p++)
					    {
					        widthToCurrent = widthToCurrent + tabs.tabSet[k + p].originalWidth;
					        tabRowGroup[tabRowGroup.length] = tabs.tabSet[k + p];
					    }
					    break;
				    }
				    else
				    {
					    pushback = this.tabsDistrib(tabs, top + tabsHeight, k + 1, tabSpace, currrow + 1, nrows);
					    tabRowGroup[tabRowGroup.length] = tab;
					    for (p = 0 ; p < pushback ; p++)
					    {
					        widthToCurrent = widthToCurrent + tabs.tabSet[k + p + 1].originalWidth;
					        tabRowGroup[tabRowGroup.length] = tabs.tabSet[k + p + 1];
					    }
					    break;
				    }
			    }
			    else
			    {
				    tabRowGroup[tabRowGroup.length] = tab;
			    }
		    }
		    tabRowGroup[tabRowGroup.length - 1].overlapped = false;
		    
		    var moveToPrecedingRow = 0;
		    while ((chamferWidth * (tabRowGroup.length + 1) + widthToCurrent) > tabSpace)
		    {
		        moveToPrecedingRow++;
		        var oWidth = tabRowGroup[0].originalWidth;
		        widthToCurrent = widthToCurrent - oWidth;
		        tabRowGroup.shift();
		    }
		    
		    var nSpacedTabs = 0;
		    for (t = 0 ; t < tabRowGroup.length ; t++)
		    {
		        if (tabRowGroup[t].LF)
		            nSpacedTabs++;
		    }
		    
		    // actually position the tabs, but simply record their widths for later
		    var totalSpacing = (chamferWidth * tabRowGroup.length);// + window.layout.tabs.overlap;
		    var additionalLength = tabSpace - (totalSpacing + widthToCurrent);
		    //alert("tabSpace = " + tabSpace + ", totalSpacing = " + totalSpacing + ", widthToCurrent = " + widthToCurrent);

		    var extendedAll = Math.floor(additionalLength / nSpacedTabs); 
		    var extendedSome = additionalLength % nSpacedTabs; 
    		
		    widthToCurrent = 0;
		    var extendedWidth = 0;
		    var offset = window.layout.tabs.indent;
		    for (var k = 0 ; k < tabRowGroup.length ; k++)
		    {
			    var tab = tabRowGroup[k];
			    var wid = tab.originalWidth;
			    var offsetToCurrent = widthToCurrent;
    			
    			if (tab.LF)
    			{
			        tab.extendedWidth = extendedAll + (k < extendedSome ? 1 : 0);
			        tab.style.left = (offset + offsetToCurrent + leftChamfer + tab.extendedWidth / 2) + "px";
			        tab.style.top = top + "px";
			        tab.tabRow = currrow;
			        widthToCurrent = widthToCurrent + wid + chamferWidth + tab.extendedWidth;
			    }
			    else
			    {
			        tab.extendedWidth = 0;
			        tab.style.left = (offset + offsetToCurrent + 1 + leftChamfer * 2) + "px";
			        tab.style.top = top + "px";
			        tab.tabRow = currrow;
			        widthToCurrent = widthToCurrent + wid;
			    }
		    }
		    return moveToPrecedingRow;
	    }
	    return 0;
    }

    this.tabPainter = function(realTab, chamferWidth, slopeLens)
    {
	    if (realTab && realTab.LF && realTab.LF[0])
	    {
		    if (realTab.tabRow == 0)
		    {
			    realTab.LF[0].style.height = "1px";
			    realTab.LF[0].style.top = "0px";
		    }
		    else
		    {
			    realTab.LF[0].style.height = (1 + (realTab.tabRow * (realTab.hgt - 1))) + "px";
			    realTab.LF[0].style.top = "-" + (realTab.tabRow * (realTab.hgt - 1)) + "px";
		    }
		    var width = realTab.originalWidth + realTab.extendedWidth + (navigator.compat.quirksMode ? 2 : 0);
		    var extendedLeft = realTab.extendedWidth / 2;
		    var maxLen = chamferWidth - window.layout.tabs.borderWidth;
		    for (i = 0 ; i < realTab.hgt ; i++)
		    {
			    var tabElem = realTab.LF[i];
			    var slopeLen = slopeLens[i];
    			
			    var offset = 0 - (slopeLen + extendedLeft);
			    var length = width + (realTab.overlapped ? Math.min((2 * slopeLen), maxLen) : (2 * slopeLen));
			    
			    tabElem.style.left = offset + "px";
			    tabElem.style.width = length + "px";	
		    }
	    }
    }

    this.getRealTab = function(elem)
    {
	    var className = elem.className;
	    if (className == "tabLF")
	    {
		    return elem.realTab;
	    } 
	    else
	    {
		    return elem;
	    }
    }

    this.setTabHi = function(tabElem)
    {
	    var i;
	    if (window.tabStates == null) window.tabStates = new stateEnum();
	    tabElem.isover = true;
	    if (tabElem.LF)
	    {
		    for (i = 0 ; i < tabElem.LF.length ; i++)
		    {
			    this.setColor(tabElem.LF[i], window.tabStates.HOVER);
		    }
	    }
    }

    this.setTabLo = function(tabElem)
    {
	    var i;
	    if (window.tabStates == null) window.tabStates = new stateEnum();
	    tabElem.isover = false;
	    if (tabElem.LF)
	    {
		    for (i = 0 ; i < tabElem.LF.length ; i++)
		    {
			    this.setColor(tabElem.LF[i], (tabElem.className == "tab") ? window.tabStates.DEFAULT : window.tabStates.SELECTED);
		    }
	    }
    }

    this.setColor = function(tabElem, tabType)
    {
        if (tabType == window.tabStates.SELECTED)
        {
	        tabElem.style.backgroundColor = tabElem.selectedColor.color;
        }
        else if (tabType == 20)
        {
	        tabElem.style.backgroundColor = tabElem.shadowColor.color;
        }
        else if (tabType == window.tabStates.HOVER)
        {
	        tabElem.style.backgroundColor = tabElem.hoverColor.color;
        }
        else
        {
	        tabElem.style.backgroundColor = tabElem.defaultColor.color;
        }
        tabElem.style.borderColor = tabElem.shadowColor.color;
    }
}
/* Copyright � 2009 Nicholas Stimpson. All Rights Reserved */

function viewport()
{
    this.setup = function()
    {
        if (! document.getElementById)
	        return;
    		
        var body = document.getElementById('body');
        body.style.overflow="hidden";
        body.onmousemove = this.clearAccessLinks;
        
        // opera puts it's primary scroll on the html element
        // but this only hides the scroll bar on v9.0 or later
        var html = document.getElementById('html');
        html.style.overflow="hidden";
        html.style.height="100%"
        
        this.createUnderlay();
    }
    
   	this.clearAccessLinks = function()
    {
        var body = document.getElementById('body');
        body.onmousemove=null;
        var accessmenu = document.getElementById('accessmenu');
        accessmenu.style.display="none";
    }
       
    this.createUnderlay = function()
    {
        var body = document.getElementById('body');
        var underlay = document.createElement('div');
        underlay.id = "underlay";
        underlay.style.position = "absolute";
        underlay.style.height = "100%";
        underlay.style.width = "100%";
        underlay.style.zIndex = "-1";
        body.insertBefore(underlay, body.firstChild);
    }
    
    this.getDimensions = function()
    {
        var dims = new dimensions();
        if ((document.getElementById) && (! window.msie))
	        if (document.getElementById('underlay'))
	            if (typeof document.getElementById('underlay').offsetWidth != 'undefined')
	            {
	                dims.width = document.getElementById('underlay').offsetWidth;
	                dims.height = document.getElementById('underlay').offsetHeight;
	            }
        if (typeof window.innerWidth != 'undefined')
        {
            dims.width = window.innerWidth;
            dims.height = window.innerHeight;
        }
        else if (typeof document.documentElement != 'undefined' &&
                 typeof document.documentElement.clientWidth != 'undefined' &&
                 document.documentElement.clientWidth != 0)
        {
            dims.width = document.documentElement.clientWidth;
            dims.height = document.documentElement.clientHeight;
        }
        else
        {
            dims.width = document.getElementsByTagName('body')[0].clientWidth;
            dims.height = document.getElementsByTagName('body')[0].clientHeight;
        }
        return dims;
    }
}

function dimensions()
{
    this.width = 0;
    this.height = 0;
}




function cookieManager()
{
    this.create = function(name,value,days)
    {
        if (days)
        {
            var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            var expires = "; expires="+date.toGMTString();
        }
        else expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
    }

    this.read = function(name)
    {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++)
        {
            var c = ca[i];
            while (c.charAt(0)==' ') 
                c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) 
                return c.substring(nameEQ.length,c.length);
        }
        return null;
    }
}



function cacadeStyleSheet()
{
    this.setup = function()
    {
        var title = window.cookieManager.read("style");
        if (title)
        {
            var a;
            for (var i = 0; (a = document.getElementsByTagName("link")[i]); i++)
            {
                if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title"))
                {
                    a.disabled = (a.getAttribute("title") != title);
                }
            }
        }
    }
    
    this.preserve = function()
    {
        window.cookieManager.create("style", this.getActive());
    }
    
    this.setActive = function(title)
    {
        var a, main;
        for (var i = 0; (a = document.getElementsByTagName("link")[i]); i++)
        {
            if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title"))
            {
                a.disabled = (a.getAttribute("title") != title);
            }
        }
        if (window.styleChangeDetector && window.styleChangeDetector.scale)
        {
            window.styleChangeDetector.scale();
        }
        window.cookieManager.create("style", title);
    }

    this.getActive = function()
    {
        var a;
        for (var i = 0; (a = document.getElementsByTagName("link")[i]); i++)
        {
            if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) 
                return a.getAttribute("title");
        }
        return null;
    }

    this.getPreferred = function()
    {
        var a;
        for (var i = 0; (a = document.getElementsByTagName("link")[i]); i++)
        {
            if (a.getAttribute("rel").indexOf("style") != -1
                    && a.getAttribute("rel").indexOf("alt") == -1
                    && a.getAttribute("title")) 
                return a.getAttribute("title");
        }
        return null;
    }
}


/* Copyright � 2006-2009 Nicholas Stimpson. All Rights Reserved */

function immediate() 
{
	compatibility();

	window.cookieManager = new cookieManager();
	window.cacadeStyleSheet = new cacadeStyleSheet();
	window.cacadeStyleSheet.setup();
}

function initialize() 
{
    compatSetup();
	document.colour = new colour();
	window.layout = new layout();
	if (document.getElementById)
	{
		document.direct = new direct();
	}
	document.dynamicIdIndex = 1;
	window.viewport = new viewport();
	window.viewport.setup();
	window.menu = new menu();
	window.menu.setup();
	window.tabs = new tabs();
	window.tabs.setup();
	window.realbody = new realbody();
	window.realbody.setup();
	window.auxMenu = new auxMenu();
	window.auxMenu.setup();
    window.geoColumn = new geoColumn();
	window.geoColumn.setup();
	
	// Set up of the on-resize event now that the objects are ready, as IE7 wants 
	// to do a resize as a result of the html.style.overflow="hidden"; command in viewport.setup.
	window.onresize=resize;
	window.images = new images();
	window.images.setup();
	window.textScaleDetector = new textScaleDetector();
	window.textScaleDetector.setup();
	window.styleChangeDetector = new styleChangeDetector();
	window.styleChangeDetector.setup();
	window.corners = new corners();
	window.corners.setup();
	resize();
	window.realbody.setScrollState();
	window.realbody.positionAnchor();
	window.geograph = new geograph();
	window.geograph.setup();
}

// direct object constructor - a directory of frequently used DOM objects
function direct()
{
    this.body = document.getElementById("body");
	this.tabs = document.getElementById("Tabs");
	this.realbody = document.getElementById("realbody");
	this.indirectContent = document.getElementById("indirect-content");
	this.menu = document.getElementById("menu");
	
	this.pageBanner = function()
	{
	    var banner = document.getElementById('PageBanner');
	    if (banner == null)
	    {
		    banner = document.getElementById('EmpressBanner');
	    }
	    return banner;
    }();
}

window.addEvent(window, "load", initialize);

immediate();

