

function menufx_onload(){
	//var aTogglers = [];
	$$('#NavBar li span#navLabel').each(function(el) { 
		var nParentLi =0;										 
		for(var pe=el;pe!=null && pe.id!='NavBar';pe=pe.getParent()) {
			if( pe.tagName.toLowerCase()=='li' ) 
				nParentLi++;
		}
		if(pe==null || pe.hasClass('noMenuFX') || (nParentLi>1 && !pe.hasClass('allLevelMenuFX')))
			return;
			
		el.addEvent('mouseenter',function(){		
		el.setStyle('background-position','bottom right');
		myEffect = el.effect('margin-left', {duration: 100,transition: Fx.Transitions.linear, wait: true}).start('10','30');
		})
		
		el.addEvent('mouseleave',function(){
		el.setStyle('background-position','top right');
		myEffect = el.effect('margin-left', {duration: 800,transition: Fx.Transitions.Bounce.easeOut, wait: true}).start('30','0');
		})
	
	})
	
	//myStretch = aTogglers;
	//myStretcher = []; //document.getElementsByClassName('accordion');
	
	// setup the accordion elements by clearing display styles	
	//myStretcher.each(function(el){
	//	el.style.display = '';
	//});	
	
/*var ac = new Fx.Accordion(myStretch,myStretcher,
 
  {
		onActive: function(tog){
         tog.setStyle('color', '#ACDA4E');
		tog.setStyle('background-color', '#1d1d1d');
		tog.setStyle('cursor', 'help');
		
    },
    onBackground: function(tog){
       
		tog.setStyle('color', '#FFF');
		tog.setStyle('background-color', '#2d2d2d');
		tog.setStyle('cursor', 'help');
		
    },
		alwaysHide: true,
		start : 'all-closed',
		opacity : true			
	}); */
}

if( window.addEvent ) 
{
  window.addEvent('load',menufx_onload);
}	

var SlideList = new Class({ 
	initialize: function(menu, options) { 
		if(menu.hasClass('noMenuFX'))
			return;
			
		this.setOptions(this.getOptions(), options);   
		this.menu = $(menu);
		this.current = null; 
  
		this.menu.getElements('li').each(function(item){ 
			item.addEvent('mouseover', function(){ this.moveBg(item); }.bind(this)); 
			item.addEvent('mouseout', function(){ this.moveBg(this.current); }.bind(this)); 
			item.addEvent('click', function(event){ this.clickItem(event, item); }.bind(this)); 
		}.bind(this)); 
  
		this.back = new Element('li').addClass('background').adopt(new Element('div').addClass('left')).injectInside(this.menu); 
		this.back.fx = this.back.effects(this.options); 
		this.setCurrent(this.current); 
	}, 
  
	setCurrent: function(el, effect){ 
		if( el ) {
			this.back.setStyles({left: (el.offsetLeft)+'px', width: (el.offsetWidth)+'px'}); 
			(effect) ? this.back.effect('opacity').set(0).start(1) : this.back.setOpacity(1); 
		}
		else {
			this.back.setStyles({left: '-500px', width: '100px'}); 
			(effect) ? this.back.effect('opacity').set(0).start(1) : this.back.setOpacity(1); 			
		}
		this.current = el; 
	}, 
  
	getOptions: function(){ 
		return { 
			transition: Fx.Transitions.sineInOut, 
			duration: 500, wait: false, 
			onClick: Class.empty 
		}; 
	}, 
  
	clickItem: function(event, item) { 
		this.setCurrent(item, true); 
		this.current = item; 
		this.options.onClick(new Event(event), item); 
	}, 
  
	moveBg: function(to) { 
		if( this.moveBgTimeout!=null ) {
			window.clearTimeout(this.moveBgTimeout);
			this.moveBgTimeout=null;
		}
		if(to==null) {
			var self = this;
			this.moveBgTimeout = window.setTimeout(function() {
				self.moveBgTo(-500,100);
			},500);
		}
		else {		
			this.moveBgTo(to.offsetLeft,to.offsetWidth);
		}
	},
	
	moveBgTo: function(dstOffsetLeft,dstOffsetWidth) {
		this.back.fx.custom({ 
			left: [this.back.offsetLeft, dstOffsetLeft], 
			width: [this.back.offsetWidth, dstOffsetWidth] 
		}); 		 		
	} 
}); 
  
SlideList.implement(new Options); 

window.addEvent('domready', function() { 
	var sl = new SlideList($('hNavBar'), {transition: Fx.Transitions.backOut, duration: 700, onClick: function(ev, item) { /*ev.stop();*/ }}); 
}); 
