/*
hide.js
(c) 1992-2005 Cisco Systems, Inc. All rights reserved. 
Terms and Conditions: http://cisco.com/en/US/swassets/sw293/sitewide_important_notices.html
*/	

document.writeln('<style>');
document.writeln('.hide-target-hidden{display:none;}');
document.writeln('.hide-noscript{display:none;}');
document.writeln('</style>');

function HidePair(tri, tar) {
	var trigger;
	var target;	

	this.trigger = tri;
	this.target = tar;

	this.getTrigger = function() { return this.trigger; }
	this.setTriggerClass = function(newclass) { this.trigger.className = newclass; }
	this.getTarget = function() { return this.target; }
	this.setTargetClass = function(newclass) { this.target.className = newclass; }
}

function HideGroup(name) {
	var GroupName;
	var Active;
	var Pairs;
	
	this.GroupName = name;
	this.Pairs = new Array();
	this.Active = new String();
	this.getName = function() { return this.GroupName; }
	this.setName = function(str) { this.GroupName = str; }
	this.getActive = function() { return this.Active; }
	this.setActive = function(str) { this.Active = str; }
	this.addPair = function(trigger, target) { 
		newp = new HidePair(trigger, target)
		this.Pairs.push( newp ); 
	}
	this.hideAll = function() {
		for (var i=0; i < this.Pairs.length; i++) {
			this.Pairs[i].setTriggerClass(cssTriggerRoot + '-' + this.GroupName);
			
			if (this.Pairs[i].getTarget() && (this.Pairs[i].getTarget() != '') ) {
				this.Pairs[i].setTargetClass( cssTargetHidden );
			} else {
				hide_debug("ERROR: Can't HIDE target for trigger: '" + this.Pairs[i].getTrigger().id + "' it doesn't exist.");
			}
		}
	}
}


// Trigger IDs
var triggerKey = new String ('hide-id-trigger-');
var targetKey = new String ('hide-id-target-');

// CSS Strings
var cssTriggerRoot = new String ('hide-trigger');
var cssTargetShown = new String ('hide-target-shown');
var cssTargetHidden = new String ('hide-target-hidden');

// Script Variables
var hide_Groups = new Array();

function hide_debug(s) {
	// lets us leave debugging in.
	try {
		debug(s);
	} catch (error) {
		// do nothing;
	}
}

function hide_ShowClassInfo() {
	var s = new String("hide.js css trigger classes\n[Group Name]\n[inactive]:[active]\n");

	s = s.concat("--------------------\n");

	for (var i = 0; i < hide_Groups.length; i++) {
		g = hide_Groups[i].getName();
		s = s.concat("Group: '" + g + "'\n" );
		s = s.concat(cssTriggerRoot + "-" + g + ":" + cssTriggerRoot + "-" + g + "-" + "active\n\n");
	}
	alert (s);
		
}


function hide_DoClick(argTrigger, history, hide_active) {
	var trigger = argTrigger;
	hide_debug("hide_DoClick(): trigger = '" + trigger.id + "'");

	// determine the trigger's group and identifier (not html id.)
	var temp_sGroup = hide_ParseGroup(trigger.id, triggerKey);
	var temp_sPairID = hide_ParsePairID(trigger.id, triggerKey);
	
	// retrieve the group this trigger is in.
	thisGroup = hide_GetGroup(temp_sGroup);
	hide_debug("  -> Corresponding target = '" + targetKey + temp_sGroup + "-" + temp_sPairID);
	
	// hide all target's in the triggers's group (including its own target)
	thisGroup.hideAll();
	
	// show the clicked trigger's target.
	// if the trigger is active already, and toggle is true we 
	// do nothing, so it will revert to closed state.
	if ( (thisGroup.getActive() != trigger.id) || !hide_active ) {
		target = document.getElementById(targetKey + temp_sGroup + "-" + temp_sPairID);
		if (target) {
			target.className = cssTargetShown;
		} else {
			hide_debug("  -> ERROR: Can't SHOW target for trigger: '" + trigger.id + "'");
		}
		trigger.className = cssTriggerRoot + '-' + thisGroup.getName() + '-active';
		thisGroup.setActive(trigger.id);
	} else if ( (thisGroup.getActive() == trigger.id) && hide_active) { 
		// leave the panel closed, but update the active, (and thus the history/init state.)
		thisGroup.setActive('');
	}

	if (history) {
		hide_debug("  -> update history");
		hide_setHash();
	}
	return false;
}

function hide_GetGroup(group) {
	var index = hide_LookupGroup(group);
	if (index < 0) {
		hide_Groups.push( new HideGroup(group) );
		outGroup = hide_Groups[hide_Groups.length-1];
	} else {
		outGroup = hide_Groups[index];
	}
	return outGroup;
}

function hide_LookupGroup(group) {
	var found;
	found = -1;
	for (var i = 0; i < hide_Groups.length; i++) {
		if ( hide_Groups[i].getName() == group) {
			found = i;
		}
	}
	return found;
}

function hide_InitActive() {
	hide_debug("hide_initActive():");

	htriggers = window.location.hash;
	htriggers = new String(htriggers);
	
	hide_debug(" --> raw hash: '" + htriggers + "'");
	// trim off the hash mark.
	if ( htriggers.charAt(0) == '#' ) {
		htriggers = htriggers.substr(1);	
	}
	
	htriggers = htriggers.split(",");
	for (var i = 0; i < htriggers.length; i++) {
		hide_debug(" --> hash triggers[" + i + "] : '" + htriggers[i] + "'");
		if ( htriggers[i] != '' ) {
			if ( trigger = document.getElementById(htriggers[i]) ) {
				hide_DoClick(trigger, false, false);
			}	
		}
	}
}

function hide_setHash() {
	var newhash = new String();
	var active;
	for (var i = 0; i < hide_Groups.length; i++) {
		newhash = newhash.concat( "," + hide_Groups[i].getActive() ); 
	}
	window.location.hash = newhash;
	hide_debug("  -> Set Active Trigger: '" + newhash + "'");	
}

function hide_ParseGroup(id, key) {
	var info = id.substr(key.length, id.length);
	var out = info.split("-")[0];
	return out;
}

function hide_ParsePairID(id, key) {
	var info = id.substr(key.length, id.length);
	var out = info.split("-")[1];
	return out;
}

function hide_Init() {
	var nTriggers = 0;
	var nTriggerErrors = 0;
	var group;
	var index;
	
	hide_debug("hide_Init():");
	
	hide_debug("  -> Finding Triggers:</br>");
	// run through the anchors looking for id's like our keys
	var pageLinks = document.getElementsByTagName('a');
	var numlinks = pageLinks.length;
	hide_debug(" Links in page: " + numlinks);
	for (var i = 0; i < numlinks; i++) {
		var trigger = pageLinks[i];
		var triggerID = trigger.id;
		
		if (triggerID.indexOf(triggerKey) != -1) {
			// found a trigger
			hide_debug("Trigger found, id: '" + triggerID + "'");
			nTriggers++;
			
			// set its onclick
			trigger.onclick = new Function("{ return hide_DoClick(this, true, true); }");
			hide_debug("  -> onclick set");

			// parse out it's group
			gname = hide_ParseGroup(triggerID, triggerKey);
			
			// parse out the index/identifer of the trigger
			// hide-id-trigger-[group]-[index]
			// index can be a string.
			index = hide_ParsePairID(triggerID, triggerKey);
			
			// retrieve the group from the list of groups.
			Group = hide_GetGroup(gname);
			hide_debug("GetGroup returned: " + Group.getName());

			// build the corresponding target id string.
			targetID = targetKey + gname + '-' + index;
			
			// get the target out of the DOM
			target = document.getElementById( targetID );
			if (!target) {
				// oops
				hide_debug("  -> ERROR: Hideable Trigger without Target: id: '" + triggerID + "'");
				nTriggerErrors++;
				Group.addPair(trigger, null);
			} else {
				// add the trigger/target pair to the group list.
				csstriggeractive = cssTriggerRoot + '-' + gname + '-active'
				hide_debug("  -> target found: " + target.id);
				hide_debug("  -> trigger class: '" + trigger.className + "': looking for " + csstriggeractive );
				if (trigger.className == csstriggeractive) {
					target.className = cssTargetShown;
				} else {
					trigger.className = cssTriggerRoot + '-' + gname;
					target.className = cssTargetHidden;
				}
				hide_debug("  -> target classnmae set: classname=" + target.className);
				Group.addPair(trigger, target);
			}
			hide_debug("");
		}
	}
	
	
	
	hide_debug("Summary:");
	// build list of groups.
	s = '';
	for (i = 0; i < hide_Groups.length; i++) {
		s += "'" + hide_Groups[i].getName() + "', ";
	}
	hide_debug("Total Hideable Triggers: " + nTriggers + " / " + nTriggerErrors + " Error(s)");
	hide_debug("Total Hideable Groups: " + hide_Groups.length + ": " + s);
	
	hide_InitActive();
		
	hide_debug("hide_Init(): Complete ---------------------------");
}
addToWindowOnLoad(hide_Init);




