// JavaScript Document
/*	FUNCTION buildLayer
	Builds a complete master layer containing a link and sub-links. The entire construction can be positioned independently. It is made up of three levels of DIVs:
	
	1:	Master layer containing the main link and:
		2:	Popup layer. Simply a container for the links but with a horizontal line across the top of its box. Contains the links:
			3:	Links layer. A DIV containing all the sub links to the main link. Has a vertical line down the left of its box
			
	This arranged can illustrated as follows:

	master layer (nav_layerID)	
	+---------------------------------------------------------------------+
	|             popup layer (popup_layerID   links layer (links)        |
	| Master link ----------------------------+-----------------------+   |
	|                                         | Sub link              |   |
	|                                         | Sub link              |   |
	|                                         | Sub link              |   |
	|                                         +-----------------------+   |
	|                                                                     |
	+---------------------------------------------------------------------+

	The function takes the following parameters:

		layerID - the master layer identifier. As there will be several master layers on the page the resulting DIV tag is named 'nav_layerID'
		layerLabel - the text that is to appear as the label for the master link. 
		URL - the URL that the master link points to 
		t - the top position of the master layer. Left positioning is set to 10px by the function
		links - an array of links that are to be placed in the links layer. This parameter is of the form:
		
			link name , URL , target ; link name , URL , target ; . . .
			
		l - the left positioning of the popup layer
		w - the width of the links layer. The position of the links layer is right relative to the popup layer
*/
function addNav(layerID,layerLabel,URL,t,links,l,w) {
	var linksArray = links.split(';');
	var theLinks = '';
	var pLayer,cLayer = '';
	var mLayer = '';
	var masterWidth = 320;
	
	// Build the list of links
	for (x=0; x<linksArray.length; x++) {
		thisLink = linksArray[x].split(',');
		theLinks += '<p><a id="' + thisLink[0] + '" href="' + thisLink[1] + '"';
		
		if (thisLink[2] != '') {
			theLinks += ' target="' + thisLink[2] + '"';
		}
		theLinks += ' class="navLink">' + thisLink[0] + '</a></p>';
	}
	// Build the child layer, containing the links. 
	cLayer = '<div id="links" class="linkBody" style="width:' + w + 'px;">' + theLinks + '</div>';

	// Build the parent layer, containing the top line and the child layer
	pWidth = masterWidth-l;
	if (links != '') {
		pLayer = '<div id="popup_' + layerID + '" class="linkLine" style="visibility:hidden; left:' + l + 'px; top:10px; width:' + pWidth + 'px;">' + cLayer  + '</div>';
	} else {
		pLayer = '<div id="popup_' + layerID + '" class="linkLine" style="visibility:hidden; left:' + l + 'px; top:10px; width:' + pWidth + 'px;"></div>';
	}
	
	// Got the popup links layer, now to build the nav link that brings it up. If no links are supplied then a popup is not created
	mLayer = '<div id="nav_' + layerID + '" style="width:' + masterWidth + 'px; position:absolute; top:' + t + 'px; left:10px;"><a id="' + layerID + '" href="' + URL + '" class="navLink"';
	if (links != '') {
		mLayer += ' onClick="toggleLayer(\'popup_' + layerID + '\')"';
	} else {
		mLayer += ' onClick="hideAll()"';
	}
	mLayer += '>' + layerLabel + '</a>' + pLayer + '</a></div>';
	
	return(mLayer);
}

function buildNavBar() {
	var html = '';

	html += addNav('home','home','index.htm',10,'',45,0);
	html += addNav('approach','approach','approach.htm',45,'',75,0);
	html += addNav('people','people','people.htm',80,'jamie pratt,people_jp.htm,;estelle matthews,people_em.htm,;simon reed,people_sr.htm,;richard northedge,people_rn.htm,;melanie wright,people_mw.htm,;neal cooper,people_nc.htm,',50,140);
	html += addNav('coaching','presentation coaching','coaching.htm',115,'executive coaching,coaching_exec.htm,;group coaching,coaching_group.htm,',150,140);
	html += addNav('clients','our clients','clients.htm',150,'',75,150);
	html += addNav('ipo','IPOs','ipo.htm',185,'',40,0);
	html += addNav('media','media training','training.htm',220,'broadcast / press,training_broadcast.htm,;sports,training_sports.htm,',100,150);
	html += addNav('pitches','winning pitches','pitches.htm',255,'',105,150);
	html += addNav('faq','faq','faq.htm',290,'',25,0);
	html += addNav('contact','contact','contactUs.htm',325,'',50,0);
	
	return html;
}


