//we define two arrays, containing our toggles and divs.
var myDivs;
var myLinks;
var openSection

window.onload = function()
{
	myDivs = document.getElementsByClassName('stretcher');
	myLinks = document.getElementsByClassName('stretchtoggle');

// toggle the togglers
  myLinks.each(function(tog, i) {
    tog.onclick = function() {
			if (i % 2){
	  	     // tog.className = (tog.className == 'stretch_active2') ? 'stretchtoggle' : 'stretch_active2';
		  }else{
		     // tog.className = (tog.className == 'stretch_active1') ? 'stretchtoggle' : 'stretch_active1';
		  }
    };
	
  });


  var mooAccordion = new fx.Accordion(myLinks, myDivs, {opacity:true, width:false, height:true});

mooAccordion.showThisHideOpen = function(toShow) {

  this.elements.each(function(el, j) {
    if (el == toShow)
      this.clearAndToggle(toShow, j);
  }.bind(this));
}



/*for (z=0; z<arrMenu.length; z++) {
		menu = arrMenu[z];
		menuItem = menu[0];
	
		if (menuItem[0] == pageOn) {
			for (x=1; x<menu.length; x++) {
				currMenuItem = menu[x];
	         alert(currMenuItem);
			}
		}
}*/


	/*
if (pageOn=='dirFloortime'){
	openSection(0);
}
if (pageOn=='confTrain'){
	openSection(1);
	if (thirdLev=='confoverview' || thirdLev=='brochure' || thirdLev=='registration'){
		openSection(2);	
	}
	if (thirdLev=='summer' || thirdLev=='training' || thirdLev=='faculty' || thirdLev=='facilitators'){
		openSection(3);	
	}
}
if (pageOn=='pubsMedia'){
	openSection(4);	
}
if (pageOn=='infantMentalHealth'){
	openSection(5);	
}
if (pageOn=='resources'){
	openSection(6);	
}
if (pageOn=='membership'){
	openSection(7);	
}
if (pageOn=='about'){
	openSection(8);		
}

}

*/


//DYNAMICALLY CREATES THE NAVIGATION
for (nn=0; nn<arrMenu.length; nn++) {
		menuZ = arrMenu[nn];
		menuItemZ = menuZ[0];
		
		//alert(nn); // gives out the #s
		//alert(menuZ[0]); //
		//alert(menuZ[1]); //
		
		
		//alert(menuItemZ[0]);
	     //alert(menuZ[navz]); //everything in first array
		//alert(menuZ[1]);  //circles through first entry in each section

if (pageOn==menuZ[1]){
	openSection(lookUpOpenerNum(menuZ[1]));
	//alert(navz);
	
	
		 for (xy=0; xy<menuZ.length; xy++) {
				currMenuItemxy = menuZ[xy];
				if (currMenuItemxy.length == 4) {
					//alert("CURRENT" + nn)
					if (currMenuItemxy[3]=="BEGIN") {
						nn = nn + 1;	
					}
				
					if (thirdLev==currMenuItemxy[2]){	
						openSection(lookUpOpenerNum(currMenuItemxy[2]));
					} 
				}
			}
					   

				//alert("outside" + nn);


			  // break;
} 	
											
}

}



//////////////////////////////////////////////////////////////////


/*
				
if (pageOn=='dirFloortime'){
	openSection(0);
}
if (pageOn=='confTrain'){
	openSection(1);
	if (thirdLev=='confoverview' || thirdLev=='brochure' || thirdLev=='registration'){
		openSection(2);	
	}
	if (thirdLev=='summer' || thirdLev=='training' || thirdLev=='faculty' || thirdLev=='facilitators'){
		openSection(3);	
	}
}
if (pageOn=='pubsMedia'){
	openSection(4);	
}
if (pageOn=='infantMentalHealth'){
	openSection(5);	
}
if (pageOn=='resources'){
	openSection(6);	
}
if (pageOn=='membership'){
	openSection(7);	
}
if (pageOn=='about'){
	openSection(8);		
}

}
*/


function openSection(opennum){
	myLinks[opennum].onclick();
	
}


function lookUpOpenerNum(itemtolookfor){
	var initSize=0;
	var exitVar=0;
	var levelB;
	for (var countA=0; countA<arrMenu.length; countA++) {
		
		levelA = arrMenu[countA];
		if (levelA[1]==itemtolookfor){
			break;	
		}
		initSize++;
		if (levelA.length>0){
		
			for (var countB=0; countB<levelA.length; countB++) {
				levelB = levelA[countB];
				if (levelB.length == 4) {
					if (levelB[3]=="BEGIN") {
						initSize++;
						//alert(initSize);
					}
					if(levelB[2]==itemtolookfor){
						exitVar=1;
						break;	
					}
				}
			}
			if(exitVar==1){
				initSize=initSize-1;
				break;	
			}
		}
	}
	return initSize;	
}