var ISM_Anchors = null;
var ISM_Prefix = new String("ISM_");

function ISmartAnchor(anchor){
	if (typeof(anchor) != "string"){
		ISM_Anchors = document.getElementsByTagName("a");
		var tmpAnchors = new Array();
		for (var i = 0; i < ISM_Anchors.length; i++){
			if (ISM_Anchors[i].href && ISM_Anchors[i].hash && ("/"+location.pathname).indexOf(ISM_Anchors[i].pathname) > 0){
				tmpAnchors[tmpAnchors.length] = {object:ISM_Anchors[i], hash: ISM_Anchors[i].hash};
				ISM_Anchors[i].href = "javascript:ISmartAnchor('" + ISM_Anchors[i].hash + "')";
			}
		}
		ISM_Anchors = tmpAnchors;
		if (getAnchorValue(location).length > 0){ ISmartAnchor_Onclick(ISM_Prefix + getAnchorValue(location)) }
	}
	else{
		location.href = anchor;
		ISmartAnchor_Onclick(ISM_Prefix + anchor.substr(1, anchor.length - 1))
	}
}

function getAnchorValue(object){ 
	try{ return object.hash.substr(1,(object.hash.length)); }
	catch(e){ return ""; }
}

function ISmartAnchor_Onclick(anchor){
	var elm = document.getElementById(anchor);
	for (var i = 0; i < ISM_Anchors.length; i++){
		try{ document.getElementById(ISM_Prefix + getAnchorValue(ISM_Anchors[i])).className = ""; }
		catch(e){}			
	}
	if (elm != null) { elm.className = "SmartAnchorSectionOn"; }
}