// Array of arrays
// Term, abbreviaion, definition, display on glossary page
var glossary = [
	["Australian Building Greenhouse Rating", ["ABGR"], "A scheme that benchmarks the greenhouse performance of office buildings.  It rates base-buildings, tenancies and whole buildings from one to five stars with five stars representing exceptional greenhouse performance.  Current best practice in the Australian market is three stars and the average is 2.5 stars: <a href=\"http://www.abgr.com.au\">www.abgr.com.au</a>."],
	["Australian Bureau of Statistics", ["ABS"], "The central statistical authority of the Australian Government: <a href=\"http://www.abs.gov.au\">www.abs.gov.au</a>."],
	["Australian Capital Territory", ["ACT"], ""],
	["Australian Greenhouse Office", ["AGO"], "The key Australian Government agency for greenhouse matters.  The AGO is part of the Commonwealth Department of the Environment and Heritage and is responsible for both the coordination of domestic climate change policy and for managing the majority of programs under the Australian Government's climate change strategy: <a href=\"http://www.greenhouse.gov.au\">www.greenhouse.gov.au</a>."],
	["Australian Institute of Family Studies", ["AIFS"], "The Australian Government statutory authority established to promote the identification and understanding of factors affecting marital and family stability in Australia: <a href=\"http://www.aifs.gov.au\">www.aifs.gov.au</a>."],
	["Average Time Lost Rate", ["ATLR"], "The average time lost per lost-time incident reflective of the severity of injuries suffered.<br/>ATLR = Number of Days Lost / Number of Occurrences. "],
	["Base building", ["Base building"], "The common area of a commercial building that is not leased to tenants.  Base building services refer to those services provided by the landlord for tenants, such as air conditioning, water supplies, common area lighting, lifts and carpark services but excluding office lighting and tenant equipment."],
	["Bioswale", ["Bioswale"], "A device utilising vegetation such as reeds, grasses and other perennials to filter and absorb nutrients from stormwater before it is released into the environment."],
	["Building and Sustainability Index", ["BASIX"], "BASIX is an on-line assessment tool that forecasts a house or unit's post-occupancy energy and water requirements and compares them to reduction targets set down by the NSW State Government.  In NSW a design must meet these targets before the local council issues approval for construction: <a href=\"http://www.basix.nsw.gov.au\">www.basix.nsw.gov.au</a>."],
	["Building Code of Australia", ["BCA"], "The BCA contains technical provisions for the design and construction of buildings and other structures, covering such matters as structure, fire resistance, energy efficiency, access and egress, services and equipment, and certain aspects of health and amenity: <a href=\"http://www.abcb.gov.au\">www.abcb.gov.au</a>."],
	["Carbon dioxide equivalent", ["CO2-e","CO<sub>2</sub>-e"], "A method for comparing the emissions from various greenhouse gases based upon their global warming potential.  For example, one tonne of methane represents 21T <span title=CO2-e>CO<sub>2</sub>-e</span> because the global warming potential for methane over 100 years is 21 times that of carbon dioxide."],
	["Commercial & Industrial", ["C&I"], "Waste generated from the day-to-day operation of our buildings.  Examples of C&I waste include paper, cardboard, glass bottles, aluminium cans and food."],
	["Construction & Demolition", ["C&D"], "Waste generated from infrequent construction and demolition activities.  Examples of C&D waste include timber, windows, plasterboard, carpets, cabling and masonry rubble."],
	["Development Control Plan", ["DCP"], "A document set down by planning authorities that specifies the rules, conditions and controls applying to various forms of development."],
	["Ecologically Sustainable Development", ["ESD"], "According to the Brundtland Report Our Common Future: 'Development that meets the needs of the present without compromising the ability of future generations to meet their own needs'."],
	["Green Building Council of Australia", ["GBCA"], "The Australian-based representative of the World Green Building Council that promotes green building programs, technologies, design practices and operations: <a href=\"http://www.gbcaus.org\">www.gbcaus.org</a>."],
	["Green Star", ["Green Star"], "A rating system overseen by the GBCA for evaluating the environmental design and achievements of buildings. There are a range of Green Star rating tools for use in assessing the environmental performance of buildings in a specific sector (office, retail, healthcare, education) at a distinct phases in the development cycle (design, construction, and operation)."],
	["Heating, Ventilation & Air-Conditioning", ["HVAC"], "The three principal base building service elements used to provide comfortable conditions for tenants.  HVAC generally accounts for the majority of a base building's energy consumption and a substantial proportion of water consumption."],
	["Indoor Environmental Quality", ["IEQ"], "The quality of the air and environment inside buildings, based on pollutant concentrations and conditions that can affect the health, comfort and productivity of occupants – including temperature, relative humidity, light, sound and other factors: <a href=\"http://www.epa.gov/iaq/\">www.epa.gov/iaq/</a>"],
	["Injury and Illness Statistics Score", ["IISI"], "Determined by multiplying the LTIFR with the ATLR."],
	["Light & Power", ["L&P"], "'Tenant L&P' and  'Base Building L&P' both describe energy supplied for lighting and plug-in electrical devices.  Light & Power generally represents the second biggest component of a base building's energy consumption after HVAC.  Lifts, hot water and carpark services come under their own separate categories."],
	["Lost Time Injury Frequency Rate", ["LTIFR"], "The number of lost time injuries for every one million hours worked."],
	["National Australian Built Environment Rating System", ["NABERS"], "A performance-based rating system for existing buildings that rates a building from one to five stars on the basis of its measured operational impacts on the environment.  Current best practice in the Australian market is three stars and the average is 2.5 stars: <a href=\"http://www.nabers.com.au\">www.nabers.com.au</a>."],
	["Net Lettable Area", ["NLA"], "The sum of the areas presented on each of a building's individual leases plus any lettable vacant area.  Areas in Investa buildings are measured in accordance with the Property Council of Australia's current method of measurement for Lettable Area, or equivalent."],
	["New South Wales", ["NSW"], ""],
	["NSW Greenhouse Gas Abatement Certificates", ["NGACs"], "Tradable abatement certificates recognised under the GGAS.  1 NGAC = 1T CO<sub>2</sub>-e emissions avoided."],
	["NSW Greenhouse Gas Abatement Scheme", ["GGAS"], "A greenhouse gas emissions trading scheme operating in NSW and the ACT that requires individual electricity retailers, and certain other parties who buy or sell electricity, to meet mandatory benchmarks based on the size of their share of the electricity market. If these parties, known as benchmark participants, fail to meet their benchmarks, then a penalty is assigned: <a href=\"http://www.greenhousegas.nsw.gov.au\">www.greenhousegas.nsw.gov.au</a>."],
	["Queensland", ["QLD"],""],
	["Safety, Health & Environment", ["SH&E"], ""],
	["South Australia", ["SA"], ""],
	["Tenancy", ["Tenancy","Tenancies"], "The part of a commercial building that is occupied, or able to be occupied, by tenants.  Tenancy services refer to those services that are not provided by the landlord such as office lighting, tenant equipment and supplementary air conditioning."],
	["Victoria", ["VIC"], ""],
	["Volatile Organic Compound", ["VOC","VOCs"], "Gases emitted or 'off-gassed' from materials such as building products, paints and lacquers, cleaning agents, furnishings, photocopiers, glues and adhesives via evaporation at room temperature.  VOCs may have adverse health effects and are not always associated with an odour."],
	["Water Sensitive Urban Design", ["WSUD"], "A design approach that integrates water cycle management into urban planning in a way that attempts to mimic the natural water cycle."],
	["Western Australia", ["WA"], ""]
];

function bodyLoad()
{
	imageFormat();
	// Add glossary
	addGlossary(document.getElementById("contentright"));
	addGlossary(document.getElementById("content"));
}

function addGlossary(element)
{
	// Recurse backwards through the child nodes so we miss out on any ones we've just added.
	for (var i=element.childNodes.length-1; i>=0; i--)
		addGlossary(element.childNodes[i]);

	// Tag specifically titled elements
	if (element.title != "")
		for (var i=0; i<glossary.length; i++)
			for (var j=0; j<glossary[i][1].length; j++)
				if (element.title == glossary[i][1][j])
					tagElement(element, glossary[i]);

	// Process the current node if it's a text node and it's got a parent (why wouldn't it!?)
	if (element.nodeType == 3 && element.parentNode)
	{
		var text = element.data;
		var newText = null;
		var completed = 0;
		var cNext = "";
		var cPrev = "";
		var punc = "().,'\" :";
		var length = 0;
		while (completed < element.data.length)
		{
			var index = 0;
			var item = null;
			var position = text.length;
			
			// Find the next glossary term usage
			for (var i=0; i<glossary.length; i++)
				for (var j=0; j<glossary[i][1].length; j++)
				{
					index = text.toLowerCase().indexOf(glossary[i][1][j].toLowerCase(), completed);
					cNext = (index < text.length)?text.substring(glossary[i][1][j].length + index, glossary[i][1][j].length + index+1):"";
					cPrev = (index > 0)?text.substring(index-1, index):"";
					if (index < position && index != -1 && punc.indexOf(cPrev) != -1 && punc.indexOf(cNext) != -1)
					{
						position = index;
						item = glossary[i];
						length = glossary[i][1][j].length;
					}
				}
			
			// Add the data from before any found data
			element.parentNode.insertBefore(document.createTextNode(text.substring(completed, position)), element);
			completed = position;
			
			// Add found data with title tag.
			if (item != null)
			{
				var gloss = document.createElement("span");
				gloss.innerHTML = text.substring(completed, completed+length).replace(/&/, "&amp;");
				tagElement(gloss, item);
				element.parentNode.insertBefore(gloss, element);
				completed += length;
			}
		}
		// Remove the origional text node
		element.parentNode.removeChild(element);
	}
}

function tagElement(element, glossary)
{
	element.className = "glossary";
	element.title = glossary[0]
		+ ((glossary[1][0] != glossary[0] && glossary[2] != "")?" (" + glossary[1][0] + ")":"")
		+ ((glossary[2] != "")?": " + glossary[2].replace(/<(.|\n)+?>/g, ""):"");
}

function imageFormat()
{
	var paddingSize = 5;
	var images = document.getElementsByTagName("img");
	for (var i=0; i<images.length; i++)
	{
		var image = images[i];
		if (image.className=="image")
		{
			var div = document.createElement("div");
			var parent = image.parentNode;

			// Setup the div layer styles
			div.className = image.className;
			div.style.width = (image.clientWidth + paddingSize*2)+"px";
			div.style.cssFloat = image.align;
			div.style.styleFloat = image.align;
			div.className = image.className;
			if (image.align!="right") div.style.marginLeft = "0px";
			if (image.align!="left") div.style.marginRight = "0px";

			image.style.margin = paddingSize + "px";
			image.align="";
			image.className = "";

			// Put the div into the heirachy
			parent.replaceChild(div, image);
			div.appendChild(image);

			// Add the caption
			if (image.title)
			{
				var caption = document.createElement("div");
				caption.innerHTML = image.title;
				div.appendChild(caption);
			}
			
			// Add the popup
			if (image.src.indexOf(".thumb.")!=-1 || image.src.indexOf(".popup.")!=-1)
			{
				image.title = "Click to view a larger version";
				image.onclick = function () { imagePopup(this); };
			}
			else
				image.title = image.alt;
		}
	}
}

function imagePopup(object)
{
	var filename = object.src.replace(".thumb.", ".popup.");
	var openWindow = window.open("", "", "resizable=no,menubar=no,status=no,titlebar=no,toolbar=no,height="+(object.clientHeight*3+20)+",width="+(object.clientWidth*3+20)+"", false);
	openWindow.document.body.style.border = "10px;";
	openWindow.document.body.style.padding = "0px;";
	openWindow.document.body.innerHTML = '<img src="' + filename + '" alt="' + object.alt + '" />';
}