/* 	Internalnav enables the toggling of a block with a click of the mouse
	Version 1.00 by David Smith of Core Multimedia 2006
	For details and instructions see internalnav_1.00.html
*/
var internalnav = {
	toggle_active_class: "toggle-active",
	toggle_inactive_class: "toggle-inactive",
	target_active_class: "target-active",
	target_inactive_class: "target-inactive",
	id_identifier: "toggle-",
	init: function() {
		if(!internalnav.instance) return alert("Message from the JavaScript application Internalnav:\n\nThe object internalnav.instance is not defined.\n\nDefine it in the following way:\ninternalnav.define(\"instance-name\");\n\nFor more guidance see internalnav.html which is in the same folder as internalnav.js.\n ");
		if(document.URL || document.documentURI) // Legacy || DOM level 3 || DOM level 2
			internalnav.uri_fragment = (document.location.href || document.URL || document.documentURI).split("#")[1]; // = undefined || uri fragment
		if(!document.getElementsByTagName || !document.getElementById) return false;
		var i, j, uid, el_a, init_show_all_flag = true, toggle;
		for(var i in internalnav.instance) { // Go through each instance, for the moment the suffix -n is required for the className 'internalnav'
			var els = document.getElementById("internalnav-" + i) || document.documentElement, instance = internalnav.instance[i];
			els = els.all || els.getElementsByTagName("*");
			for(j = 0; j < els.length; j++) // Go through each element within container id=intance or whole document
				if(new RegExp("internalnav-" + i).test(els[j].className)) {
					instance.el[instance.el.length] = els[j]; // Instance array of instance elements
					if(new RegExp(internalnav.id_identifier).test(els[j].id))
						uid = els[j].id.split(internalnav.id_identifier)[1];
					else if((el_a = els[j].getElementsByTagName("a")[0]))
						uid = el_a.getAttribute("href").split("#")[1];
					instance.uid[instance.uid.length] = uid;
					toggle = instance.init_show_all;
					if((instance.init_uid == uid || instance.init_uid == "auto" && internalnav.uri_fragment == uid) && !instance.init_show_all)
						toggle = true;
					instance.show[instance.show.length] = (toggle) ? true : false;
					document.getElementById(uid).className += " " + ((toggle) ? internalnav.target_active_class : internalnav.target_inactive_class);
					els[j].className += " " + ((toggle) ? internalnav.toggle_active_class : internalnav.toggle_inactive_class);
					init_show_all_flag = false;
					els[j].onclick = function() {return internalnav.toggle(this);};
				}
		}
		return true;
	},
	define: function(instance, init_uid, autohide, prevent_all_hide, init_show_all, allow_event_to_fire) { // string, string, boolean, boolean, boolean
		if(!instance) return alert("Message from the JavaScript application Internalnav:\n\nThe function internalnav.define requires the argument instance.\n ");
		internalnav.instance = internalnav.instance || {};
		if(internalnav.instance[instance]) return alert("Message from the JavaScript application Internalnav:\n\nThe function internalnav.define cannot use the instance name \"" + instance + "\" as it is aleady in use by another internalnav.instance object.\n ");
		return internalnav.instance[instance] = { // Instance defaults, do not change
			init_uid: init_uid || false, // The default false means that at start-up all targets of an instance will get the css class defined by target_inactive_class.
			init_show_all: init_show_all || false, // The default false means that at start-up all targets of an instance will get the css class defined by target_inactive_class.
			autohide: autohide || false, // The default false means that apart from active target all targets of instance will get the css class defined by target_inactive_class
			prevent_all_hide: prevent_all_hide || false, // The default false means that all target of an instance can have their css class defined by target_inactive_class
			allow_event_to_fire: allow_event_to_fire || false, // The default of false means that the toggle will work but prevent any underlying link to fire
			el: [], uid: [], show: []
		}
	},
	toggle: function(el) {
		var instance = el.className.match(/internalnav-\w+/).toString().split("internalnav-")[1], i, j, flag = false, show;
		instance = internalnav.instance[instance];
		for(i = 0; i < instance.el.length; i++)
			if(instance.el[i] == el) { // Active element
				if(!(show = instance.show[i])) {
					document.getElementById(instance.uid[i]).className = document.getElementById(instance.uid[i]).className.replace(new RegExp(internalnav.target_inactive_class), internalnav.target_active_class);
					el.className = el.className.replace(new RegExp(internalnav.toggle_inactive_class), internalnav.toggle_active_class);
					instance.show[i] = true;
				}
				for(j = 0; j < instance.el.length; j++)
					if(instance.el[j] != el) { // Active element
						if(instance.autohide) { // Other elements
							document.getElementById(instance.uid[j]).className = document.getElementById(instance.uid[j]).className.replace(new RegExp(internalnav.target_active_class), internalnav.target_inactive_class);
							instance.el[j].className = instance.el[j].className.replace(new RegExp(internalnav.toggle_active_class), internalnav.toggle_inactive_class);
							instance.show[j] = false;
						}
						if(instance.show[j])
							flag = true;
					}
				if(show && flag && instance.prevent_all_hide || show && !instance.prevent_all_hide) {
					document.getElementById(instance.uid[i]).className = document.getElementById(instance.uid[i]).className.replace(new RegExp(internalnav.target_active_class), internalnav.target_inactive_class);
					el.className = el.className.replace(new RegExp(internalnav.toggle_active_class), internalnav.toggle_inactive_class);
					instance.show[i] = false;
				}
				break;
			}
		return instance.allow_event_to_fire;
	}
} // internalnav.define(Instance Name = string[, Start-Up ID Shown = string || "auto" || false][, Autohide = boolean][, Prevent All Hiding = boolean][, Start-Up Show All = boolean][, Allow event to fire = boolean))
internalnav.define("news", false, false, false, false, false);
internalnav.define("resources", false, false, false, false, false);