    //Variables used for fixing Transparent PNG files in IE.
    var strRootPath = '/';
    
    //The master load function.
    window.onload=function() {        
        initLightbox();
         
		//Fix Internet Explorer Absolute positioning. Pass true to tell it that it's the first load.
		//Also does the work to fix PNG and a few other things.
		//Must be called AFTER any sets of the .right and .bottom properties.
		FixIE(true);
			
		//Does buttons with prefetch in all browsers
		SetupButtons();
		
		//Fix times
		FixTimes();						
    }
    
    function FixTimes() {
        var spanElements = document.getElementsByTagName('span');
        
        for(var i = 0; i < spanElements.length; i++) {
            var e = spanElements[i];
            if (e.title && e.title == "time") {
                e.innerText = new Date('Jan 01, 1900 ' + e.innerText + ' UTC').toLocaleTimeString();
            }            
        }    
    }

  	function Highlight(e) {
		e.style.backgroundColor="#264a84";
		e.style.color="White";
		e.style.borderColor="Black";
	}
	
	function Reset(e) {
		e.style.backgroundColor="#becbe1";
		e.style.color="Black";
		e.style.borderColor="Silver";
	}
    
    function GetCurrentStyleValue(Element, Property) {
        if (Element.currentStyle) {
            return Element.currentStyle[Property];
        } else {
            return window.getComputedStyle(Element, null).getPropertyValue(Property);
        }

    }
    

    
    //Resize function  If you need to do any other resizing functionality, put it in here.
    function Resize() {
        FixIE(false);
        
        CenterImageGallery();
    }
    
    function BeforePrint() {   
        for(var i = 0; i < document.body.all.length; i++) {
            var e = document.body.all[i];
            
        if (e.style.width)
            e.style.width = null;
        
        if (e.style.height)
            e.style.height = null;
        
        }
    }
    
   
    function AfterPrint() {
        window.location.reload();
    }

    function CenterImageGallery() {
     	if (document.getElementById('ImageGallery')) {
		    var ImageGallery = document.getElementById('ImageGallery');
		    var ItemCount;
    		
	        ItemCount = parseInt(ImageGallery.parentNode.offsetWidth / 185);
		    ImageGallery.style.width = ItemCount * 180 + "px";
		    ImageGallery.style.left = (ImageGallery.parentNode.offsetWidth - ImageGallery.offsetWidth) /2 + "px";
		}
    }
    
    function SetupButtons() {
        var ImgElements = document.getElementsByTagName('img');
        var BtnElements = document.getElementsByTagName('input');
        
        for(var i = 0; i < ImgElements.length; i++) {
            AssignButtonProperties(ImgElements[i]);
        }    
        
        for(var i = 0; i < BtnElements.length; i++) {
            if (BtnElements[i].getAttribute("type") == "image") {
                AssignButtonProperties(BtnElements[i]);    
            }
        }     
    }
    
    function SetupTextBoxes() {
        if (document.getElementById('help')) {
            document.getElementById('help').setAttribute("OriginalText", document.getElementById('help').innerHTML);
            
            var txtElements = document.getElementsByTagName('input');
            
            for(var i = 0; i < txtElements.length; i++) {
                txtElements[i].onfocus = txtFocus;
            }
            
            var SelectElements = document.getElementsByTagName('select');
            for(var i = 0; i < SelectElements.length; i++) {
                SelectElements[i].onfocus = txtFocus;
            }

        }
    }
    
    function txtFocus(e) {
        var eHelp = document.getElementById('help');
        
        if (eHelp && GetCurrentStyleValue(eHelp, "visibility") != "hidden") {
            if (this.getAttribute("HelpText")) {
                eHelp.innerHTML = this.getAttribute("HelpText");
            } else {
                eHelp.innerHTML = eHelp.getAttribute("OriginalText");
            }
        }
    }
    
    function AssignButtonProperties(Element) {
        if (Element.getAttribute("srcdown") || Element.getAttribute("srcover")) {
            //We have a winner
            //Pre-load the images and set the mouse events.
            
            Element.onmouseup = ButtonUp;
            Element.onmouseout = ButtonOut;
            Element.onmouseover = ButtonOver;

            if (Element.getAttribute("srcdown")) {
                Element.onmousedown = ButtonDown;
                var img = new Image();
                img.src = GetRootPath(Element.getAttribute("srcdown"));
            }

            if (Element.getAttribute("srcover")) {
                var img = new Image();
                img.src = GetRootPath(Element.getAttribute("srcover"));
            }               
        }
    }
      
    function ButtonDown(e) {
        if (!this.onmousedown) return;
        
        SetButtonImage(this, GetRootPath(this.getAttribute("srcdown")));        
    }
    
    function ButtonUp(e) {
        if (!this.onmouseup) return;
        
        if (this.getAttribute("srcup")) //Only need to call it if the srcup exists, otherwise it hasn't been changed anyhow.
            SetButtonImage(this, GetRootPath(this.getAttribute("srcup")));    
    }
    
    function ButtonOut(e) {
        if (!this.onmouseout) return;
        
        if (this.getAttribute("srcup")) //Only need to call it if the srcup exists, otherwise it hasn't been changed anyhow.
            SetButtonImage(this, GetRootPath(this.getAttribute("srcup")));    
    }
    
    function ButtonOver(e) {
        if (!this.onmouseover) return;
        
        var ButtonDown = false;
        
        //This one is a little trickier, because we have to figure out if the mouse button is down or now.
        if (!e) var e = window.event;
        var ButtonDown = GetMouseButton(e);       
        
        if (ButtonDown > 0 && this.getAttribute("srcdown")) {
            SetButtonImage(this, GetRootPath(this.getAttribute("srcdown")));
        } else {
            if (this.getAttribute("srcover")) {
                SetButtonImage(this, GetRootPath(this.getAttribute("srcover")));
            } else if (this.getAttribute("srcup")) {
                SetButtonImage(this, GetRootPath(this.getAttribute("srcup")));
            } 
        }
    }
      
    function SetButtonImage(e, Src) {
        if (e.style.filter && navigator.appVersion.indexOf("MSIE") != -1) {
  	        e.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + Src  + "', sizingMethod='image')";
        } else {
            if (!e.getAttribute("srcup"))
                e.setAttribute("srcup", e.src);
            e.src = Src;
        }
    }
    
    function checkIt(string)
    {
	    place = detect.indexOf(string) + 1;
	    thestring = string;
	    return place;
    }

    
    var Fixed = false;
    var detect = navigator.userAgent.toLowerCase();
    var OS, browser, version, total, thestring;        
    function FixIE(Load) {        
        if (checkIt('konqueror')) {
	        browser = "Konqueror";
	        OS = "Linux";
        }
        else if (checkIt('safari')) browser = "Safari"
        else if (checkIt('omniweb')) browser = "OmniWeb"
        else if (checkIt('opera')) browser = "Opera"
        else if (checkIt('webtv')) browser = "WebTV";
        else if (checkIt('icab')) browser = "iCab"
        else if (checkIt('msie')) browser = "Internet Explorer"
        else if (!checkIt('compatible')) {
	        browser = "Netscape Navigator"
	        version = detect.charAt(8);
        } else browser = "An unknown browser";

        if (!version) version = parseInt(detect.charAt(place + thestring.length));

        if (!OS)
        {
	        if (checkIt('linux')) OS = "Linux";
	        else if (checkIt('x11')) OS = "Unix";
	        else if (checkIt('mac')) OS = "Mac"
	        else if (checkIt('win')) OS = "Windows"
	        else OS = "an unknown operating system";
        }
    
		window.status = document.documentElement.clientWidth + ", " + document.documentElement.clientHeight;
		if (browser == "Internet Explorer") { //Fixes all active content in IE so that it doesn't need to be activated.		    
			//Array of elements to be replaced
		    var arrElements = new Array(3);
		    arrElements[0] = "object";
		    arrElements[1] = "embed";
		    arrElements[2] = "applet";
    	
		    //Loop over element types
		    for (n = 0; n < arrElements.length; n++) {
    		
			    //set object for brevity
			    replaceObj = document.getElementsByTagName(arrElements[n]);
    			
			    //loop over element objects returned
			    for (i = 0; i < replaceObj.length; i++ ) {
    			
				    //set parent object for brevity
				    parentObj = replaceObj[i].parentNode;
    				
				    //grab the html inside of the element before removing it from the DOM
				    newHTML = parentObj.innerHTML;
    				
				    //remove element from the DOM
				    parentObj.removeChild(replaceObj[i]);
    				
				    //stick the element right back in, but as a new object
				    parentObj.innerHTML = newHTML;    			
			    }
		    }
		}
		
        if (browser == "Internet Explorer" && version < 7) {
            FixElement(document.body, Load);            
        }
        
    }

    
    function FixElement(e, Load) {
        var right = -1;
        var left = -1;
        var top = -1;
        var bottom = -1;
       
        if (e.currentStyle && e.currentStyle.position && e.currentStyle.position == "absolute") {
            if (e.currentStyle.left && e.currentStyle.left.toLowerCase() != "auto")
                left = parseInt(e.currentStyle.left);
            
            if (e.currentStyle.right && e.currentStyle.right.toLowerCase() != "auto")
                right = parseInt(e.currentStyle.right);
                
            if (e.currentStyle.top && e.currentStyle.top.toLowerCase() != "auto")
                top = parseInt(e.currentStyle.top);
                
            if (e.currentStyle.bottom && e.currentStyle.bottom.toLowerCase() != "auto")
                bottom = parseInt(e.currentStyle.bottom);

            if (e.currentStyle.position.toLowerCase() == "absolute") {
                if (e.currentStyle.right && e.currentStyle.right.toLowerCase() != "auto" && e.currentStyle.left && e.currentStyle.left.toLowerCase() != "auto") {
                    var Parent = FindWidthSizedParent(e);
                    
                    if (Parent) {
                        var BorderWidth = 0;
                        if (e.currentStyle.borderRightWidth)
                            BorderWidth = parseInt(e.currentStyle.borderRightWidth);                           
                        
                        if (e.currentStyle.borderLeftWidth)
                            BorderWidth += parseInt(e.currentStyle.borderLeftWidth);
                            
                        if (BorderWidth.toString() == "NaN")
                            BorderWidth = 0;
                        
                        e.style.width = Parent.offsetWidth - right - left - BorderWidth;
                    }
                } 
                    
                if (e.currentStyle.bottom && e.currentStyle.bottom.toLowerCase() != "auto" && e.currentStyle.top && e.currentStyle.top.toLowerCase() != "auto") {
                    var Parent = FindHeightSizedParent(e);
                    
                    if (Parent) {
                        var BorderHeight = 0;
                        if (e.currentStyle.borderBottomWidth)
                            BorderHeight = parseInt(e.currentStyle.borderBottomWidth) + 1;
                        
                        if (e.currentStyle.borderTopWidth)
                            BorderHeight += parseInt(e.currentStyle.borderTopWidth) + 1;

                        if (BorderHeight.toString() == "NaN")
                            BorderHeight = 0;
                            
                        
                        e.style.height = Parent.offsetHeight - bottom - top - BorderHeight;
                    } else {
						if (parseFloat(document.documentElement.clientHeight /2) == parseInt(document.documentElement.clientHeight /2)) {
							e.style.height = document.documentElement.clientHeight - bottom - top;
                        } else {
							e.style.height = document.documentElement.clientHeight - bottom - top - 1;
                        }
                    }
                }
            }
        }
        
        for(var i = 0; i < e.childNodes.length; i++) {
            FixElement(e.childNodes[i], Load);
        }
    }
    
    function FindWidthSizedParent(e) {    
        if (!e || e == null || !e.parentNode) {
            return null;
        } else if (e.parentNode.currentStyle && e.parentNode.currentStyle.width && e.parentNode.offsetWidth && e.parentNode.currentStyle.width.toLowerCase() != "auto" && e.parentNode.offsetWidth > 0) {
            return e.parentNode;
        } else {
            return FindWidthSizedParent(e.parentNode);
        }
    }

    function FindHeightSizedParent(e) {
        if (e == null)
            return null;
            
            
        if (!e.parentNode || e.parentNode == null) {
            return null;
        } else if (e.parentNode.currentStyle && e.parentNode.height && e.parentNode.offsetHeight && e.parentNode.currentStyle.height && e.parentNode.currentStyle.height.toLowerCase() != "auto" && e.parentNode.offsetHeight > 0) {
            return e.parentNode;
        } else {
            return FindHeightSizedParent(e.parentNode);
        }
    }       

    //Email obviscation functions
    var tld_ = new Array()
    tld_[0] = "com";
    tld_[1] = "org";
    tld_[2] = "net";
    tld_[3] = "ws";
    tld_[4] = "info";
    tld_[10] = "co.uk";
    tld_[11] = "org.uk";
    tld_[12] = "gov.uk";
    tld_[13] = "ac.uk";
    var topDom_ = 13;
    var m_ = "mailto:";
    var a_ = "@";
    var d_ = ".";

    function mail(name, dom, tl, params) {
	    var s = e(name,dom,tl);
	    document.write('<a href="'+m_+s+params+'">'+s+'</a>');
    }
    function mail2(name, dom, tl, params, display) {
	    document.write('<a href="'+m_+e(name,dom,tl)+params+'">'+display+'</a>');
    }
    function e(name, dom, tl) {
	    var s = name+a_;
	    if (tl!=-2)
	    {
		    s+= dom;
		    if (tl>=0)
			    s+= d_+tld_[tl];
	    }
	    else
		    s+= swapper(dom);
	    return s;
    }
    function swapper(d) {
	    var s = "";
	    for (var i=0; i<d.length; i+=2)
		    if (i+1==d.length)
			    s+= d.charAt(i)
		    else
			    s+= d.charAt(i+1)+d.charAt(i);
	    return s.replace(/\?/g,'.');
    }

    function GetRootPath(Path) {
        if (Path.indexOf('~/') > -1) {
            return strRootPath + Path.substring(2, Path.length);
        } else {
            return Path;    
        }
    }
        
     ///Returns the button that is down in all browsers consistantly. Amazing.
    function GetMouseButton(theEvent) {
        if (theEvent.which && theEvent.which == 1) {
            ButtonDown = true;
        } else if (navigator.appVersion.indexOf("MSIE") != -1) {
            if (theEvent.button) {
                return theEvent.button;
            } else {
                return 0;
            }
        } else {
            if (theEvent.button) {
                if (theEvent.button == 0) {
                    return 1;
                } else if (theEvent.button == 1) {
                    return 4
                } else if (theEvent.button == 2) {
                    return 2;
                } else {
                    return 0;
                }
            } else {
                return 0;
            }
        }
    }
    
    function uppercase(e) {
        var key;
        if (e.keyCode)
            key = e.keyCode;
        else if (e.which) 
            key = e.which;

        
        if ((key > 0x60) && (key < 0x7B)) {
            if (navigator.appVersion.indexOf("MSIE") != -1)
                e.keyCode = key-0x20;
        }
    }
    
    function uppercaseexit(e) {
        e.value = e.value.toUpperCase();
    }

	window.onresize = Resize;
	window.onbeforeprint = BeforePrint;
	window.onafterprint = AfterPrint;