/* Straight up Dustin Diaz */
/* Copied straight from the website */
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

/* Straight up Dustin Diaz */
/* Copied straight from the website */
function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}

var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();
addEvent(window,'unload',EventCache.flush);





/* Straight up Dustin Diaz, almost */
/* This is the function to collapse everything when the page loads */
/* I had to do some recoding here to use the getElementsByClass */
/* I changed the argument variable and linked objs to the getElementsByClass
    function call (compare to original code, only 1 new line)*/
function collapseAll(objClass) {
	var objs = getElementsByClass(objClass);
	var i;
	for (i=0;i<objs.length;i++ ) {
		objs[i].style.display = 'none';
	}
}

function pageLoad() {
	collapseAll('collapse');
	show('assembly');
}

addEvent(window,'load',pageLoad);


/*  Straight up me */
/*  I wrote this function to do three things:
     1.) If the given class is shown, then just hide it
          else
     2.) hide everything
          then
     3.) Show the desired class*/
function show(objClassToShow) {
	var objsToShow = getElementsByClass('collapse ' + objClassToShow);  //Get the objects of the specific class
	
	if (objsToShow[0].style.display == 'none') {   //Meaning, if the object is hidden, then lets show it
		collapseAll('collapse'); //hide everything first
		
		var i;
		for (i = 0; i < objsToShow.length; i++) {
			objsToShow[i].style.display = '';   //now lets show just our class
		}
	} else {
		collapseAll('collapse');  // Class is visible, so let's hide it
	}
}























