/* - - - - - - - - - - - - - - - - - - - - -
Version info
$Id: generic_toggler.js 832 2009-07-06 11:07:10Z ascherff $
$Rev: 832 $
$Author: ascherff $
$LastChangedDate: 2009-07-06 13:07:10 +0200 (Mon, 06 Jul 2009) $
- - - - - - - - - - - - - - - - - - - - - */
function hideAllToggles(){
	$$('.toggle').each(function(item) {
		var targetId = item.href.split('#')[1];
		var targetEl = $(targetId);
		targetEl.hide();
	});
}
function toggleTarget(){
	$$('.toggle').each(function(item) {
		var targetId = item.href.split('#')[1];
		var targetEl = $(targetId);
		Event.observe(item, 'click', function(evt){
			Event.stop(evt);
			if(targetEl.style.display == 'none'){
				item.addClassName('active');
				targetEl.show();
			}
			else {
				item.removeClassName('active');
				targetEl.hide();
			}
		});
	});
}

function checkURL(){
	if(location.href.split('#')[1]){
		var targetId = location.href.split('#')[1];
		if($(targetId)){
			$(targetId).show();
		}
	}
}

function showTargetById(id){
	if($(id)){
		var item = $(id);
		item.show();
		item.previous().down('a').addClassName('active');
		new Effect.ScrollTo(item);
	}
}

function initToggler(){
	// generic togglers
	hideAllToggles();
	toggleTarget();
	checkURL();
}
document.observe('dom:loaded', function(){
	initToggler()
});