// 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 = 250;
	var navWidth = 100;
	var root = 'http://www.ghostlight.co.uk/';
	
	// When testing locally, use the following value of root. Comment out when running on the web server
	//root = 'file:///Users/paulnaylor/Sites/My%20Web%20Site/Site%20v6.2/'
	//root = 'http://localhost/coolIris/'
	
	// Build the list of links
	for (x=0; x<linksArray.length; x++) {
		// Add the full web URL to the beginning of the link, so we can nav to anywhere on the site
		thisLink = linksArray[x].split(',');
		
		theLinks += '<p style="line-height:6pt;"><a id="' + thisLink[0] + '" href="' + root + 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="p_' + layerID + '" class="linkLine" style="visibility:hidden; left:' + l + 'px; top:10px; width:' + pWidth + 'px;">' + cLayer  + '</div>';
	} else {
		pLayer = '<div id="p_' + 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
	if (URL == '#') {
		URL = 'javascript:void(0);';
	} else {
		URL = root + URL;
	}
	
	mLayer = '<div id="n' + layerID + '" style="width:' + navWidth + 'px; position:absolute; top:' + t + 'px; left:10px;"><a id="' + layerID + '" href="' + URL + '" class="navLink"';
	if (links != '') {
		mLayer += ' onClick="toggleLayer(\'p_' + layerID + '\')"';
		//mLayer += ' onClick="alert(\'p_' + layerID + '\')"';
	} else {
		mLayer += ' onClick="hideAll()"';
	}
	mLayer += '>' + layerLabel + '</a>' + pLayer + '</a></div>';
	
	return(mLayer);
}

function buildNavBar() {
	var html = '';

	html += addNav('about','About','#',90,'About me,about.htm,;Day Job,dayjob.htm,',65,120);
	html += addNav('galleries','Gallery','#',125,'Enter gallery,galleries/index.asp,;View comments,galleries/viewComments.asp,',65,120);
	html += addNav('coolness','Coolness','#',160,'Without whom...,links/withoutWhom.htm,;News,links/news.htm,;Photographyment,links/photographyment.htm,;Killing time,links/killingTime.htm,;Geek,links/geek.htm,;Fringe,links/fringe.htm,',65,120);
	html += addNav('blogish','Blog (ish)','blogish.asp',195,'',65,0);
	html += addNav('contact','Contact','#',255,'Send email,contact/sendEmail.asp,;Sign guestbook,contact/guestbook_sign.asp,;Read guestbook,contact/guestbook_read.asp,',65,120);

	return html;
}


