/**
 * indicator.js
 * 
 * Draws attention to elements that are
 * anchored with name="someName" and called by url#name.
 *
 * (c) 2007 Jeff Pickhardt
 * All Rights Reserved
 */


/* AttentionFunction is called on the attention element
 * Change this if you want to change the attention effects
 */
var IndicatorFunction = function(elem) {
	Effect.Shake(elem);
}

var Indicator = Class.create();

Indicator.prototype = {
	Version: '1.0',

	initialize: function() {
		this.clearIndicates();
		var currentUrl=window.location.toString();
		var poundIndex=currentUrl.indexOf('#');
		if(-1!=poundIndex) {
			var anchorName=currentUrl.substr(poundIndex+1);
			this.indicate(anchorName);
		}
		this.makeLinksIndicators();
		versionElements=document.getElementsByClassName("indicator-version");
		for(var i=0; i<versionElements.length; i++) {
			versionElements[i].innerHTML=this.Version;
		}
		if($("indicator-version")!=null) {
			$("indicator-version").innerHTML=this.Version;
		}
	},
	
	makeLinksIndicators: function() {
		var indicators=document.getElementsByClassName('indicator');
		for(var i=0; i<indicators.length; i++) {
			var href=indicators[i].href;
			var poundIndex=href.indexOf('#');
			if(-1!=poundIndex) {
				indicators[i].onclick=function() {
						var href=this.href;
						var poundIndex=href.indexOf('#');
						var anchorName=href.substr(poundIndex+1);
						myIndicator.clearIndicates();
						myIndicator.indicate(anchorName);
					};
			}
			
		}
		
		
	},
	
	clearIndicates: function() {
		var indicates=document.getElementsByClassName('indicated');
		for(var i=0; i<indicates.length; i++) {
			Element.removeClassName(indicates[i], 'indicated');
		}
	},
	
	indicate: function(anchorName) {
		anchors=document.getElementsByClassName(anchorName);
		for(var i=0; i<anchors.length; i++) {
			Element.addClassName(anchors[i], 'indicated');
			IndicatorFunction(anchors[i]);
		}
		anchorById=$(anchorName);
		if(anchorById!=null) {
			Element.addClassName(anchorById, 'indicated');
			IndicatorFunction(anchorById);
		}
	}
	
};

function initIndicator() {
	myIndicator = new Indicator(); // global
}
Event.observe(window, 'load', initIndicator, false);