
function $(id) {
	return document.getElementById(id);
}

//---------------- Switcher --------------------------

var Switcher = function(initial, container, section) {
	this.initial = initial;
	this.container = container;
	this.section = section;
	this.visibles = {};
}

Switcher.prototype = {
	
	showElement: function(what, id) {
		if (!id) return;
		this.display(what, 'none');
		this.visibles[what] = $(id);
		this.display(what, 'inline');
	},
	
	display: function(what, style) {
		if (this.visibles[what] && this.visibles[what].style) {
			this.visibles[what].style.display = style;
		}
	},
	
	show: function(id, secid) {
		this.showElement('refid', id);
		this.showElement('secid', secid);
	},
	
	load: function() {
		this.show(this.initial, this.section);
		var links = document.getElementsByTagName("a");
		var switcher = this;
		for (var i=0; i < links.length; i++) {
			if (links[i].className.match(this.container)) {
				links[i].onmouseover = function() {
					switcher.show(this.getAttribute('refid'), this.getAttribute('secid'));
					return false;
				};
				links[i].onclick = links[i].onmouseover;
			}
		}
	}
};

noop = function() {};

Switcher.register = function(initial, container, section) {
	window.old_unload = window.onload || noop;
	window.onload = function() {
		window.old_unload();
		window.switcher = new Switcher(initial, container, section).load();
	};
};


//---------------- Popups --------------------------

function openPopup(which) {
	var popup = $(which);
	if (popup && popup.style) {
		popup.style.display = 'block';
		document.body.className = 'popBody';
		window._onkeydown = window.onkeydown;
		window.onkeydown = function(e) {
			var evt = e || window.event;
			if (evt.keyCode == 27) { //Escape
				popup.onclick();
				window.onkeydown = window._onkeydown;				
			}
		}
	}

	popup.onclick = function() {
		this.style.display = 'none';
		document.body.className = '';
	}
}
	

//---------------- Loading Sign --------------------------
	
function hideLoadingSign() {
	var load = $('loading');
	if (load && load.style) {
		load.style.display = 'none';
	}
}


