window.addEvent('domready', function() {//---START PRIMARY FUNCTION---required for all mootools js frameworks
									 
/*=Accordions
-----------------------------------------------------------------------
-----------------------------------------------------------------------
*/
if($chk( $('accordion') )) {
	var myAccordion = new Accordion($$('div.accordions h3.toggler'), $$('div.accordions div.element'), {
		opacity: false
	});
	
	$$('.areas').each(function(item){						
		var elAcc = item.getElement('.accordions');
		var elBg = item.getElement('.bgAlpha');
		var FxAcc = new Fx.Morph(elAcc);
		var FxBg = new Fx.Morph(elBg);
		
		FxBg.set({opacity: 0});
		item.addEvent('mouseenter', function(){
			FxAcc.set({opacity: 1});
			FxBg.set({opacity: .7});
		});
		
		item.addEvent('mouseleave', function(){
			FxAcc.set({opacity: 0});
			FxBg.set({opacity: 0});
		});
	});
}
/*----------------------------------------------
-------------FUNCTIONS--------------------------
-----------------------------------------------*/

//---MAKE GLOBAL NAV UL'S SAME HEIGHT---
if($chk( $('global-nav') )) {
	var navHeight = $('global-nav').getStyle('height').toInt(); //GET HEIGHT OF FIRST UL (LONGEST ONE)
	$$('.global-nav-items').setStyle('height',navHeight);
}

/*=Menu Function
-----------------------------------------------------------------------
-----------------------------------------------------------------------
*/

$$('a.toggle').each(function(e,index) {
	//Set Variables						 
	var toggle = new Array(); //Array used to determine if mouse is over a menu
	var menuPrefix = "global-";//First part of the menu id
	var navMenu = menuPrefix+e.get('name'); //Name of the menu that we want to control
	//Since we set the css to display:none in the css we change it here to display:block so that we have access to its opacity properties
	$(navMenu).setStyle('display', 'block');
	//Now that the menu is visible we need to set the opacity to 0 so that it remains invisible initially
	var myFx = new Fx.Morph(navMenu, {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
	myFx.set({opacity: 0});
	//Set up functions to handle fade-in and fade-out
	function fadeout() {
		if(toggle[index] != 1) {
			myFx.start({opacity: 0}).chain(
				function(){$(navMenu).setStyle('display', 'none');}			   
			);
		}
	}
	function fadein() {
		$(navMenu).setStyle('display', 'block');
		myFx.start({opacity: 1});
	}
	//Add events to the toggle links
	e.addEvent('click',function(event) {
		fadein();
		return false;
	});
	e.addEvent('mouseleave',function(event) {
		toggle[index] = 0;
		fadeout.delay(300,e);
	});
	//Add events to the Menus
	$(navMenu).addEvent('mouseenter',function(event) {
		toggle[index] = 1; //This keeps the menu from disappearing if the mouse is on it
		return false;
	});
	$(navMenu).addEvent('mouseleave',function(event) {
		toggle[index] = 0;									  								  
		fadeout();
		toggle[index] = 1; //We set this back to 1 in order to keep the menus from disappearing as soon as you click on them
		return false;
	});
});

//---------SLIDE TRANSITIONS----------
if($chk( $('member-form') )) {
	var loginSlide = new Fx.Slide('member-form');
	loginSlide.hide();
	$('member-form').setStyle('display', 'block');
	$('member-form').setStyle('visibility', 'visible');
	$('toggle-member-form').addEvent('click', function(){
		loginSlide.toggle();
	});
}

if($chk($('news-more-slide'))) {
	var newsSlide = new Fx.Slide('news-more-slide');
	$('news-more-slide').setStyle('visibility', 'visible');
	newsSlide.hide();
	$('toggle-news').addEvent('click', function(){
		newsSlide.toggle();
	});
}

});
// =========================== 
//
// ===========================
function comboItemSelected(oList1,oList2,cType) {
	if (oList2!=null){
 	    alert('oList2 Not Null and need to clear it out');
		clearComboOrList(oList2);
       if (oList1.selectedIndex==-1){
         oList2.options[oList2.options.length] = new Option('SELECT','');
       } else {
	  // fillCombobox(oList2,cType + '=' + oList1.options[oList1.selectedIndex].value);
	   fillCombobox(oList2,cType + oList1.options[oList1.selectedIndex].value);
	   }
	}
}

function clearComboOrList(oList) {
   for (var i = oList.options.length-1; i>=0 ; i--) {
	   oList.options[i]=null;
   }
   oList.selectedIndex = -1;
   if (oList.onchange) oList.onchange();
}

function fillCombobox(oList,vValue){
   if (vValue!=''){
	   if (assocArray[vValue]){
		   oList.options[0] = new Option('SELECT','');
		   var arrX = assocArray[vValue];
           for ( var i = 0; i<arrX.length ; i = i+2 ){
			   if (arrX[i]!='EOF') oList.options[oList.options.length] = new Option(arrX[i+1],arrX[i]);
           }
           if (oList.options.length == 1){
			   oList.selectedIndex=0;
			   if (oList.onchange) oList.onchange();
           }
       } else {
		 oList.options[0] = new Option('None Selected','');  
	   }
   }
}

function listboxItemSelected(oList1,oList2,cType) {
   if (oList2!=null) {
	   clearComboOrList(oList2);
      if (oList1.selectedIndex==-1) {
         oList2.options[oList2.options.length] = new Option('SELECT','');
      } else {
		 fillListbox(oList2,cType + oList1.options[oList1.selectedIndex].value)
		 // fillListbox(oList2,oList1.name + '=' + oList1.options[oList1.selectedIndex].value)
	  }
   }
   else {

   }
}


function fillListbox(oList,vValue){
   if (vValue!=''){
	   if (assocArray[vValue]){
		   var arrX = assocArray[vValue];
		   for ( var i = 0; i<arrX.length ; i = i+2 ){
			   
			   if (arrX[i]!='EOF') oList.options[oList.options.length] = new Option(arrX[i+1],arrX[i]);

           }
           if (oList.options.length == 1){
			   oList.selectedIndex=0;
			   if (oList.onchange) oList.onchange();
 
           }
       } else {
		 oList.options[0] = new Option('None Selected','');  
	   }

   }
   else {
     	
   }
 
}//-----------END PRIMARY FUNCTION---