
//
// init() is called to initialize the accordion effect.
//

function init(){
	
	var stretchers = document.getElementsByClassName("stretcher"); //div that stretches
	var toggles = document.getElementsByClassName("toggle"); //h3s where I click on
	
	//accordion effect
	var myAccordion = new fx.Accordion(
		toggles, stretchers, {opacity: true, duration: 500}
	);
	
	
	
	var menuItems = matchMenuIds();
	
	if (typeof currentCat != 'undefined') {
		if (typeof menuItems[currentCat] != 'undefined') {
			var indice = menuItems[currentCat];
			myAccordion.showThisHideOpen(stretchers[indice]);
		}	
	}
	
	
}




//
// fadeout() utilizes moo.fx to create a fade out effect.
//

function fadeout(q) {
	
	var qw;
	var qw = new fx.Opacity(q, {duration: 1000, onComplete: function()
  {
    document.getElementById(q).style.display = "none";
  }
	});
  
	qw.setOpacity(1);
	qw.custom(1, 0);
}




//
// fadein() utilizes moo.fx to create a fade in effect.
//

function fadein(a) {
	var as;
	var as = new fx.Opacity(a, {duration: 1000});
	as.setOpacity(0);
	document.getElementById(a).style.display = "block";
	as.custom(0, 1);
}



//
// modMenu() receives an id of an anchor, and modifies
// its background image to either a collapse or open icon.
//

function modMenu(id) {
	
	var menuItem = document.getElementById(id);
	
	if (menuItem.style.backgroundImage == 'url(images/icon-expand.gif)') 
		menuItem.style.backgroundImage = 'url(images/icon-collapse.gif)';	
	else
		menuItem.style.backgroundImage = 'url(images/icon-expand.gif)';	
	
	var ids = grabMenuIds();

	for (var i=0; i < ids.length; i++ ) {
		
		if (ids[i] != id.substring(7)) {
			
			var tag = 'menucat'+ids[i]; 
			var	tagItem = document.getElementById(tag);

			if (tagItem.style.backgroundImage == 'url(images/icon-collapse.gif)') 
				tagItem.style.backgroundImage = 'url(images/icon-expand.gif)';
		
		}
		
	}

	return false;

}


//
// grabMenuIds() walks the dom and finds anchors
// with ids that have the prefix menucat (our menu links)
//
function grabMenuIds() {
  var children = document.getElementsByTagName('a');
  var elements = new Array();
  
  for (var i = 0; i < children.length; i++) {
    var child = children[i];
    var idName = child.getAttribute("id");
    
	if (idName != undefined) {
	
		if (idName.substring(0,7) == 'menucat')
			elements.push(idName.substring(7));
			
	}
		
  }
  
  return elements;
}





//
// matchMenuIds() takes our menu id's array and matches
// each category id with the ordered id of the toggles
// so we can open and close stretchers based on category id.
//
// menuItem[catID] = toggleId;
//
function matchMenuIds() {

  var menuItems = grabMenuIds();	
  var matchedMenu = new Array();
  
  for (var i = 0; i < menuItems.length; i++)
		matchedMenu[menuItems[i]] = i;
  
  return matchedMenu;
}


