window.addEvent('domready', function() {	
	
	var mainemnu  = new MainMenu();
	var menuform = new MenuFormation();
	//new AlignPointFort();	
	//new Slideshow('show', ['1.jpg', '2.jpg', '3.jpg'], { controller: true, hu: 'images/' });
	
});


//window.addEvent('load', function() {	});




var MainMenu = new Class({
	
	initialize: function(){
        
        if (!$('mainmenus')) return;
        
        this.actualul = null;
        this.actualdrawer = null;
        this.allbtns = [];
        this.rows = $('mainmenus').getElements('.mainmenu');
		var id = 0;
		this.rows.each(function(row) {
			id++;
			row.drawer = new Element('div', {
			    'class': 'drawer',
			    'id':'drawer'+id
			});
			
			row.drawer.inject(row, 'after');
			
			this.mainbtns =  row.getElements('.level1');
				
			this.allbtns.combine(this.mainbtns);
			
			this.mainbtns.each(function(btn) {
				
				btn.ul = btn.getElement('ul');
							
				if (btn.ul != null) {
					
					btn.firsta = btn.ul.getElement('a');
					
					var hasactive = btn.ul.getElement('.active');

					if (hasactive != null){
						this.actualdrawer = row.drawer;
						this.actualul = btn.ul;
					}else{
						btn.ul.setStyle('display', 'none');
					}
					
					row.drawer.grab(btn.ul);
					
					btn.a = btn.getElement('a');
					

					this.killHref(btn.a);				

					row.drawer.slide = new Fx.Tween(row.drawer, {'transition': 'quad:out', 'duration':200});
				
					btn.a.addEvent('click', function(e){
						
						this.allbtns.each(function(b) {b.removeClass('active')});
						btn.addClass('active');
						if (this.actualdrawer != row.drawer) {
							e.stop();	
							btn.ul.setStyle('display', '');
							var h = btn.ul.getCoordinates().height;
							if (this.actualdrawer) this.actualdrawer.slide.start('height',0);
							row.drawer.slide.start('height',0, h);	
							
							

						}

						if (this.actualul != null) {
							this.actualul.setStyle('display', 'none');
						}
							
						btn.ul.setStyle('display', '');
						
						this.actualul = btn.ul;
						this.actualdrawer = row.drawer;
						
						(function(){ window.location.href = btn.firsta; }).delay(300);
						
					}.bind(this));
				}
	
			}.bind(this));	
			
			
		
		}.bind(this));
		
	 }, //end constructor
	 
	 
	
	 
	 killHref : function(e){
		e.set('href', 'javascript:void(0)');
	},
	
	
	
	closeMe : function(){
		
				
	}	// end methods	
	 
	 
	 
	 
});// end class






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



var MenuFormation = new Class({
	
	initialize: function(){
        
       	if (!$('rollovermenu')) return;
        
       	this.imgcontainer = $('imgcontainer');
       


       	this.activea = $('rollovermenu').getElement('.active');
       	
       	if (this.activea == null) this.activea = $('rollovermenu').getElement('a');
       	//console.log("active: "+ this.activea);
	    this.imgcontainer.grab(this.activea.getNext().clone());
       
       
       	this.as = $('rollovermenu').getElements('a');
		this.as.each(function(a) {
			
			a.addEvent('mouseenter', function(e){
				this.imgcontainer.empty();
				this.imgcontainer.grab(a.getNext().clone());	
			}.bind(this));


			a.addEvent('mouseleave', function(e){
				this.imgcontainer.empty();
				this.imgcontainer.grab(this.activea.getNext().clone());
			}.bind(this));

			
		}.bind(this));
		
	 }, //end constructor
	 
	 
	
	 
	 method1 : function(e){
	},
	
	
	
	method2 : function(){			
	}	// end methods	
	 
	 
	 
	 
});// end class






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



var AlignPointFort = new Class({
	
	initialize: function(){
        
		if (!$$('.pointfort ul')) return;
       
		this.lis = $$('.pointfort ul li');
		
		
		this.lis.each(function(li) {

			txt = li.get('text').toString();
			
			txt = txt.replace(/ /g, "&nbsp;");
			txt = txt.replace(/-/g, "&#8209;");

			li.set('html', txt);
			
		});
       	
	 }
	 
	 
	 
	 
});// end class






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





