// JavaScript Document

/**********************************************
 * Index listing of logos
 * 
 * 001 - ACI
 * 006 - AIAQC
 * 008 - AIST
 * 011 - ASTM
 * 017 - ICC
 * 019 - IFMA
 * 022 - NAPP
 * 023 - NIBS
 * 030 - NFPA
 * ?034 - LEED AP?
 *
 * To change the logos that are displayed,
 * just change the topImageIndices and/or 
 * bottomImageIndices to the desired index and 
 * order from the list above or the XML file.
 ***********************************************/
 
var topImageIndices = ['017','011','023','030'];
var bottomImageIndices = ['008','001','019'];
var topImages = [];
var bottomImages = [];

function findImages() 
{
	var imageList = xmlDoc.getElementsByTagName("INDEX");
	var imageListLength = imageList.length;
	var imageTest;

	for (var i=0; i<imageListLength; i++) {
		imageTest = imageList[i].firstChild.data;
		
		var j;	// Loop counter
		for (j=0; j<topImageIndices.length; j++) {
			if (imageTest == topImageIndices[j]) { topImages[j] = i; }
		}
		for (j=0; j<bottomImageIndices.length; j++) {
			if (imageTest == bottomImageIndices[j])	{ bottomImages[j] = i; }
		}
	}
}

function createImages(imageArray)
{	
	var imagesLength = imageArray.length;
	var logoImages = "";
	
	for (var i=0; i<imagesLength; i++) {
		logoImages += "<a href='"+xmlDoc.getElementsByTagName("URL")[imageArray[i]].firstChild.data+"' target='_blank'>";
		logoImages += "<img src='content/images/"+xmlDoc.getElementsByTagName("LOGO")[imageArray[i]].firstChild.data+"' ";
		logoImages += "alt='"+xmlDoc.getElementsByTagName("ACRONYM")[imageArray[i]].firstChild.data+"' /></a>";
	}
	document.write(logoImages);
}

function createIndex()
{
	var affiliation = xmlDoc.getElementsByTagName("GROUP");
	
	// Top Image Row
	document.write("<div id='topImageRow'>");
	createImages(topImages);
	document.write("</div>");
	
	// Main List
	document.write("<div id='mainList'><ul class='square'>");
	for (var i=0; i<affiliation.length; i++) {
		document.write("<li>");
		document.write("<a href='"+(xmlDoc.getElementsByTagName("URL")[i].firstChild.data)+"' target='_blank' ");
		document.write("title='"+(xmlDoc.getElementsByTagName("URL")[i].firstChild.data)+"' >");
		document.write("<b>");
		document.write(xmlDoc.getElementsByTagName('ACRONYM')[i].firstChild.data);
		document.write("</b>: ");
		document.write(xmlDoc.getElementsByTagName("NAME")[i].firstChild.data);
		document.write("</a>");
		document.write("</li>");
	}
	document.write("</ul></div>");
	
	// Bottom Image Row
	document.write("<div id='bottomImageRow'>");
	createImages(bottomImages);
	document.write("</div>");
}

function affiliations_index() {
	var whichXML = "affiliations.xml";
	importXML(whichXML);
	findImages();
	createIndex();
}
