﻿// JavaScript Document
// Internal Navigation Generator v0.91
globalsClass = function(selectedEls, indexClass, topImageSrc, layerID) {

	this.selectedEls = selectedEls;
	this.elCounter = 0;
	this.indexCounter = 0;
	this.indexClass = indexClass;
	this.topImageSrc = topImageSrc;
	this.layerID = layerID;
	this.lastOne = false;

}
var globals;
createIndexNavigation = function(el, headClass, indexClass, topImageSrc) {

	parent_ref = null;
	selectedEls = document.getElementsByTagName(el);
	globals = new globalsClass(selectedEls, indexClass, topImageSrc);

	while (globals.elCounter < globals.selectedEls.length) {

		if (selectedEls[globals.elCounter].className == headClass && headClass != '') {

			createNavigation();
			globals.indexCounter++;

		} else if (headClass == '') {

			createNavigation();
			globals.indexCounter++;

		}

		globals.elCounter++;

	}

}
createNavigation = function() {


	/**
	/*this part creates multiple top links
	*/
	top_el = createTop(globals.topImageSrc);
	parent_ref = selectedEls[globals.elCounter].parentNode;
	if (selectedEls[globals.elCounter + 1]) {

		parent_ref.insertBefore(top_el, selectedEls[globals.elCounter + 1]);

	} else {

		/**
		*places a top link at the end of the parent node of the text
		*/
		parent_ref.appendChild(top_el);
		globals.lastOne = true;

	}

	/**
	/*this part creates an index link in the containter with an id=pageIndexContainer
	*/
	if (selectedEls[globals.elCounter].firstChild) {
		indexText = selectedEls[globals.elCounter].firstChild.nodeValue;
		anchor_el = createAnchor();

		selectedEls[globals.elCounter].appendChild(anchor_el);
		createIndexLink(indexText);
	}
}
createIndexLink = function(indexText) {

	if (document.getElementById('pageIndexContainer')) {
		href_str = '#' + globals.indexCounter;
		seperator_tn = document.createTextNode(' | ');
		link_el = document.createElement('a');

		//var overEvent = "this.className='paginaindex_over';";
		//var outEvent = "this.className='paginaindex';";
		//var clickEvent = "document.location.href='" + href_str + "';";

		//link_el.setAttribute('onMouseOver', overEvent);
		//link_el.setAttribute('onMouseOut', outEvent);
		link_el.setAttribute('href', href_str);
		link_el.setAttribute('class', globals.indexClass);
		link_el.setAttribute('className', globals.indexClass);
		link_el.appendChild(document.createTextNode(indexText));

		document.getElementById('pageIndexContainer').appendChild(link_el);
		if (!globals.lastOne) {

			document.getElementById('pageIndexContainer').appendChild(seperator_tn);

		}
	}
}
createAnchor = function() {

	try {

		//non-IE browser; use canonical method to create named element
		anchor_el = document.createElement('<a name="' + globals.indexCounter + '">');

	} catch (e) {

		anchor_el = document.createElement('a');
		anchor_el.setAttribute('name', globals.indexCounter);

	}

	return anchor_el;

}
createTop = function() {

	link_el = document.createElement('a');
	link_el.setAttribute('href', '#top');

	image_el = document.createElement('img');
	image_el.setAttribute('src', globals.topImageSrc);
	image_el.setAttribute('border', '0');

	link_el.appendChild(image_el);

	return link_el;

}