/**********************************************************
					SHOW ONLY
***********************************************************
		
Pieced together from various code snippets.

To use, add the class "Hidden_Content" to items with a 
matching class (e.g. "Video") that need to be hidden.

Insert like such: 
	<a href="javascript:ShowOnly('1','Video','1');">Introduction</a>
to only show that content. Should work like a charm!

Assembled and modified by Stephen Shaw, shshaw@gmail.com
I found large portions of the code given for free, and
Jesus was a big fan of sharing, so it's only fair that I 
allow you to use / copy this code as you see fit.

**********************************************************/


// Hide all inactive content with the class ".Hidden_Content"
document.write("<style type=\"text/css\">.Hidden_Content { display: none; }</style>");

/* HIDE ALL function 
Hides all of a specific class */
var allPageTags = new Array(); 
var allPageTags=document.getElementsByTagName("*");

function hideAll(theClass) {	
	for (i=0; i<allPageTags.length; i++) {
		if (allPageTags[i].className.search(theClass)!=-1) { allPageTags[i].style.display = 'none';	}
	}
}

/* ADD CLASS function
Adds a specific class to an object */
function AddClass(id, strClass) {
	var n=document.getElementById(id);
	if(n) { n.className+=n.className?' Highlight':'Highlight'; }
}

/* REMOVE CLASS function
Remove class from an object */
   
function RemoveClass(objElement, strClass) {
   if ( objElement.className ) { // if there is a class
		var arrList = objElement.className.split(' '); // the classes are just a space separated list, so first get the list
		var strClassUpper = strClass.toUpperCase(); // get uppercase class for comparison purposes
	
		for ( var i = 0; i < arrList.length; i++ ) { 	// find all instances and remove them
			if ( arrList[i].toUpperCase() == strClassUpper ) { // if class found
				arrList.splice(i, 1); // remove array item
				i--;
			}
		 }
		 objElement.className = arrList.join(' '); // assign modified class name attribute
   }
}

/* HIGHLIGHT function
Adds a class to on object, and removes the class from the others */
function Highlight(id) {	
	for (i=0; i<allPageTags.length; i++) {
		if (allPageTags[i].className.search('Highlight')!=-1) { RemoveClass(allPageTags[i],'Highlight'); }
	}
	
	AddClass("Header_" + id,'Highlight');	
}

/* SHOW ONLY function
This is the meat & potatoes, shows only one item of the certain class, and if you so choose, highlights the activation link. */

		function ShowOnly(id,className, highlightHeader) {
			var content = document.getElementById(id);
			
			hideAll(className);
			
			if(content.style.display == 'block') { content.style.display = 'none'; }
			else { 		setTimeout("animateFade(" + new Date().getTime() + ",'" + id + "')", 33);
						content.style.display = 'block'; }
			
			if(highlightHeader) { Highlight(id); }
		}

/* Bonus Function!
SHOWHIDE allows you to show or hide one specific item */
function ShowHide(id, className) {
	var content = document.getElementById(id);
	
	if(content.style.display == 'block') { content.style.display = 'none'; }
	else { content.style.display = 'block'; }
}

var TimeToFade = 1000.0;

function fade(eid)
{
  var element = document.getElementById(eid);
  if(element == null)
    return;
   
  if(element.FadeState == null)
  {
    if(element.style.opacity == null
        || element.style.opacity == ''
        || element.style.opacity == '1')
    {
      element.FadeState = -2;
    }
    else
    {
      element.FadeState = 2;
    }
  }
   
  if(element.FadeState == 1 || element.FadeState == -1)
  {
    element.FadeState = element.FadeState == 1 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
  }
  else
  {
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade;
    setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
  }  
}

function animateFade(lastTick, eid)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
 
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.opacity = element.FadeState == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = '
        + (element.FadeState == 1 ? '100' : '0') + ')';
    element.FadeState = element.FadeState == 1 ? 2 : -2;
    return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
 
  setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}