//*** This code is copyright 2003 by Gavin Kistner, !@phrogz.net
//*** It is covered under the license viewable at http://phrogz.net/JS/_ReuseLicense.txt
//*** Reuse or modification is free provided you abide by the terms of that license.
//*** (Including the first two lines above in your source code satisfies the conditions.)


// Include this JS library on your HTML page, and if the url loads with #foo
// that corresponds to a particular ID on your page, the element with that ID
// will have the class 'linkhighlight' applied to it.
//
// Further, clicking on links within the page that go to other anchors will
// automatically clear that class (if it exists) and apply it to the new element
//
// Note: requires id="foo" on the target elements, *not* name="foo"


AttachEvent(window,'load',function(){
	var hashRE = /#([^#]+)$/,hash;
	if (document.links){
		for (var i=0,len=document.links.length;i<len;i++){
			var a = document.links[i];
			if (a.href && (hash=hashRE.exec(a.href))) AttachEvent(a,'click',new Function("AnchorHighlight('"+hash[1]+"')"),false);
		}
	}
	AnchorHighlight(location.hash.substring(1));
},false);

function AnchorHighlight(objID){
	if (!objID) return;
	var obj=document.getElementById?document.getElementById(objID):document.all?document.all[objID]:null;
	if (!obj) return;
	if (window.lastHighlightedAnchor) KillClass(lastHighlightedAnchor,'linkhighlight');
	AddClass(window.lastHighlightedAnchor=obj,'linkhighlight');
	if (typeof(obj.scrollIntoView)=='function') obj.scrollIntoView();
}



// ********************************************************************************************
// *** LIBRARY FUNCTIONS FOLLOW; SEE http://phrogz.net/JS/ FOR LATEST VERSIONS ****************
// ********************************************************************************************

function AttachEvent(obj,evt,fnc,useCapture){
	if (!useCapture) useCapture=false;
	if (obj.addEventListener){
		obj.addEventListener(evt,fnc,useCapture);
		return true;
	} else if (obj.attachEvent) return obj.attachEvent("on"+evt,fnc);
	else{
		MyAttachEvent(obj,evt,fnc);
		obj['on'+evt]=function(){ MyFireEvent(obj,evt) };
	}
} 
function MyAttachEvent(obj,evt,fnc){
	if (!obj.myEvents) obj.myEvents={};
	if (!obj.myEvents[evt]) obj.myEvents[evt]=[];
	var evts = obj.myEvents[evt];
	evts[evts.length]=fnc;
}
function MyFireEvent(obj,evt){
	if (!obj || !obj.myEvents || !obj.myEvents[evt]) return;
	var evts = obj.myEvents[evt];
	for (var i=0,len=evts.length;i<len;i++) evts[i]();
}


function AddClass(obj,cName){ KillClass(obj,cName); return obj.className+=(obj.className.length>0?' ':'')+cName; }
function KillClass(obj,cName){ return obj.className=obj.className.replace(new RegExp("^"+cName+"\\b\\s*|\\s*\\b"+cName+"\\b",'g'),''); }
function HasClass(obj,cName){ return (!obj || !obj.className)?false:(new RegExp("\\b"+cName+"\\b")).test(obj.className) }