/* Christian Heilmann's in-page navigation solution
** shows only one (1) section at a time based on a menu
** selection (TOC); 
********************************************************/

iv={
	// css classes
	dynamicClass:'dyn',
	currentLinkClass1:'current1',
	currentLinkClass2:'current2',
	showClass:'show',

	// IDs
	parentID:'content',
	tocID:'tocmenu',

	// global properties
	current:null,
	currentLink:null,
	topLink:null,
	currentBulletplaceholder: null,

	init:function(){
		// check that DOM is supported and all necessary elements are available
		if(!document.getElementById || !document.createTextNode){return;}
		iv.parent=document.getElementById(iv.parentID);
		iv.toc=document.getElementById(iv.tocID);
		if(!iv.parent || !iv.toc){return;}
		DOMhelp.cssjs('add',iv.parent,iv.dynamicClass);

		var loc = window.location.hash.replace('#','');
		var toclinks = iv.toc.getElementsByTagName('a');

		for(var i = 0; i < toclinks.length; i++){
			if(toclinks[i].getAttribute('href').replace(/.*#/,'')==loc){
				iv.currentLink=toclinks[i];
			}
			DOMhelp.addEvent(toclinks[i],'click',iv.getSection,false);
		}
		if(!iv.currentLink){
			iv.currentLink=toclinks[0];
			
		}
		iv.showSection(iv.currentLink);
	},
	getSection:function(e){
		var t=DOMhelp.getTarget(e);		
		iv.showSection(t);
		DOMhelp.cancelClick(e);		// cancel default behavior of clicking on an anchor
	},
	// "o" is the full URL including hash(#) id
	// "targetname" is the id name i.e. id="online", targetname is "online"
	showSection:function(o){

		var targetName=o.getAttribute('href').replace(/.*#/,'');
		//alert('HELLO: '+targetName+" "+o);		
		var section=document.getElementById(targetName).parentNode;
		var bulletplaceholder = o.parentNode;
		if(iv.current!=null){
			DOMhelp.cssjs('remove',iv.current,iv.showClass);
			DOMhelp.cssjs('remove',iv.currentLink,iv.currentLinkClass1);
			DOMhelp.cssjs('remove',iv.currentBulletplaceholder,iv.currentLinkClass2);			
		}
		DOMhelp.cssjs('add',section,iv.showClass);
		DOMhelp.cssjs('add',o,iv.currentLinkClass1);
 		DOMhelp.cssjs('add',bulletplaceholder,iv.currentLinkClass2);
		iv.current=section;
		iv.currentLink=o;
		iv.currentBulletplaceholder = bulletplaceholder;
	}
	
}

// this load function not used - instead, iv.init is called
// from within the onload "solution" below
//DOMhelp.addEvent(window, 'load', iv.init, false);




/* Dean Edwards' cross-browser onload solution; allows content to be
** hidden before it is displayed (i.e. the office map)
********************************************************/
function start() {
	// quit if this function has already been called
	if (arguments.callee.done) return;

	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;

	// kill the timer
	if (_timer) {
		clearInterval(_timer);
		_timer = null;
	}
	
	iv.init();

};

/* for Mozilla */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", start, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
			start(); // call the onload handler
		}
	};
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			start(); // call the onload handler
		}
	}, 10);
}

/* for other browsers */
window.onload = start;
/*******************************************************/