/* * GetSolution main js *  * Copyright (C) 2005 * by Davide S. Casali * www.digitalhymn.com
 *
 * Last release: 2005-11-16 * */


/****************************************************************************************************
 * This swaps the current 'display' status of the item identified by a specific id
 *
 * @param	string id of the tag
 */
function switchdis(strDiv)
{
	if (document.getElementById)
	{
		// DOM3 = IE5+, NS6+, FF0.7+
		elmDisplay = document.getElementById(strDiv).style.display;
		
		if (elmDisplay == 'block')
		{
			document.getElementById(strDiv).style.display = 'none';
		}
		else
		{
			document.getElementById(strDiv).style.display = 'block';
		}
	}
}

/****************************************************************************************************
 * Apply zebra rows to the specified table.
 * From ALA: Zebra tables
 *
 * @param	table id attribute value
 * @param	optional even row color
 * @param	optional odd row color
 */
function stripe(id)
{	
	// the flag we'll use to keep track of 
	// whether the current row is odd or even
	var even = false;
	
	// if arguments are provided to specify the colours
	// of the even & odd rows, then use the them;
	// otherwise use the following defaults:
	var evenColor = arguments[1] ? arguments[1] : "#FFFFFF";
	var oddColor = arguments[2] ? arguments[2] : "#F8F8F8";
	
	// obtain a reference to the desired table
	// if no such table exists, abort
	var table = document.getElementById(id);
	if (!table) { return; }
	
	// by definition, tables can have more than one tbody
	// element, so we'll have to get the list of child
	// &lt;tbody&gt;s 
	var tbodies = table.getElementsByTagName("tbody");
	if (!tbodies) { tbodies = table; } // no tbody, using table instead (+Folletto)
	
	// and iterate through them...
	for (var h = 0; h < tbodies.length; h++)
	{
		// find all the &lt;tr&gt; elements... 
		var trs = tbodies[h].getElementsByTagName("tr");
		
		// ... and iterate through them
		for (var i = 0; i < trs.length; i++)
		{
			// avoid rows that have a class attribute
			// or backgroundColor style
			if (!hasClass(trs[i]) && !trs[i].style.backgroundColor)
			{
				// get all the cells in this row...
				var tds = trs[i].getElementsByTagName("td");
				
				// and iterate through them...
				for (var j = 0; j < tds.length; j++)
				{
					var mytd = tds[j];
					
					// avoid cells that have a class attribute
					// or backgroundColor style
					if (!hasClass(mytd) && !mytd.style.backgroundColor)
					{
						mytd.style.backgroundColor = even ? evenColor : oddColor;		
					}
				}
			}
			// flip from odd to even, or vice-versa
			even = !even;
		}
	}
}

/****************************************************************************************************
 * Returns the class attribute value of the specified DOM node.
 * This function is needed to work around a bug in IE related to element attributes.
 * From ALA: Zebra tables
 *
 * @param	object
 */
function hasClass(obj)
{
	var result = false;
	if (obj.getAttributeNode("class") != null)
	{
		result = obj.getAttributeNode("class").value;
	}
	return result;
}

/****************************************************************************************************
 * Suckerfish set of functions.
 * 
 * @author	Patrick Griffiths, Dan Webb from HTMLdog (http://htmldog.com/articles/suckerfish/)
 */
function suckerfish(type, tag, parentId) {	if (window.attachEvent) {		window.attachEvent("onload", function() {			var sfEls = (parentId==null)?document.getElementsByTagName(tag):document.getElementById(parentId).getElementsByTagName(tag);			type(sfEls);		});	}}sfHover = function(sfEls) {	for (var i=0; i<sfEls.length; i++) {		sfEls[i].onmouseover=function() {			this.className+=" sfhover";		}		sfEls[i].onmouseout=function() {			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");		}	}}sfFocus = function(sfEls) {	for (var i=0; i<sfEls.length; i++) {		sfEls[i].onfocus=function() {			this.className+=" sffocus";		}		sfEls[i].onblur=function() {			this.className=this.className.replace(new RegExp(" sffocus\\b"), "");		}	}}sfActive = function(sfEls) {	for (var i=0; i<sfEls.length; i++) {		sfEls[i].onmousedown=function() {			this.className+=" sfactive";		}		sfEls[i].onmouseup=function() {			this.className=this.className.replace(new RegExp(" sfactive\\b"), "");		}	}}sfTarget = function(sfEls) {	var aEls = document.getElementsByTagName("A");	document.lastTarget = null;	for (var i=0; i<sfEls.length; i++) {		if (sfEls[i].id) {			if (location.hash==("#" + sfEls[i].id)) {				sfEls[i].className+=" sftarget";				document.lastTarget=sfEls[i];			}			for (var j=0; j<aEls.length; j++) {				if (aEls[j].hash==("#" + sfEls[i].id)) aEls[j].targetEl = sfEls[i];				aEls[j].onclick = function() {					if (document.lastTarget) document.lastTarget.className = document.lastTarget.className.replace(new RegExp(" sftarget\\b"), "");					if (this.targetEl) this.targetEl.className+=" sftarget";					document.lastTarget=this.targetEl;					return true;				}			}		}	}}

/****************************************************************************************************
 * TRIGGERS
 * All the triggers must be at bottom, otherwise the rest of the code will not be usable.
 * 
 */
suckerfish(sfHover, "li", "nav");
