/* Son of Suckerfish - Menusystem mouseover and mouseout events for child elements */
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

/* Mootools powered items to initialize */
window.addEvent('domready', function() {
	
	// FX.Slide effect for contact info
	var btns = $$(".contactlink"); //The buttons to trigger the slides;
	var slides = $$(".contactslide"); //The elements to be slides;
	var mySlide = [];
	var openSlide = -1; //Create a flag variable to be checked and test if any slide is opened;
	slides.each(function(slide, idx) { //For each element in slides do...
		mySlide[idx] = new Fx.Slide(slide, {mode:'horizontal', duration: 500}).hide(); //Create an array with the Fx.Slide for each element in slides and hides it;
		btns[idx].addEvent('click', function(e) { //Add a click event for each element in btns;
			//e = new Event(e);
			if ( openSlide == -1 ) { //Check if a slide has been opened before;
				openSlide = idx;
				mySlide[idx].slideIn(); //Slide In the slide;
			} else {
				mySlide[openSlide].slideOut(); //Slide Out the previous openened slide;
				mySlide[idx].slideIn(); //Slide In the slide;
				if ( openSlide != idx ) openSlide = idx; //openSlide will now be the current open slide;
				else openSlide = -1; //If closing the open item, will reset openSlide to it's initial state;
			}
			//e.stop();
		});
	});
	
	// Accordian for projects and management pages
	var accordion = new Accordion(
		$$('.toggler'), // Class of the accordian buttons
		$$('.slide'), { // Class of the containers to open
			// Accordian options
			alwaysHide: true,
			opacity: false,
			start: 'all-closed',
			onActive: function(toggler, element) {
				toggler.setStyles({});
			},
			onBackground: function(toggler, element) {
				toggler.setStyles({});
			}
		}
	);
			
	// Slide for projects page
	var list = $$('#projslideContainer'); // slide containers
	var headings = $$('#projslideControl'); // buttons
	var collapsibles = new Array();
	headings.each( function(heading, i) {
		var collapsible = new Fx.Slide(list[i], { 
			duration: 500, 
			transition: Fx.Transitions.linear
		}).hide(); // start containers hidden
		collapsibles[i] = collapsible;
		heading.onclick = function(){
			var span = $E('span', heading);
			if(span){
				var newHTML = span.innerHTML == 'ON' ? 'OFF' : 'ON'; // swap control
				span.setHTML(newHTML);
			}
			collapsible.toggle();
			return false;
		}
	});
	
});