//mainMenu by karurosu v0.1
//mainMenu-new by perrohunter v0.2

//changeLog
// 0.1 version inicial
// 0.2 version para el nuevo estilo de wadboard
// 0.21 se arreglo el bug que hacia brincar la pantalla

function mainMenu() {
	
	var hiden = false;
	
	var accordion;
	var mySlide;

	var ordisp;
	var origPos;
	
	var origColor;
	var origFont;
	
	var maxGrowt;
	var paddMinus;
	
	document.acid = 0;
	
	
	
	var toggler = $('toggle');
	toggler.addClass('toggleron');
		
	
	this.testPoint = function()
	{
		alert('ordisp:'+ordisp+' origpos:'+origPos);
	}	
		

	
	var busy = true;
	
	this.completed = function()
	{
		if(hiden == true)
		{
			$('lefter').setStyle('opacity',0);
			toggler.removeClass('toggleron');
			toggler.addClass('toggleroff');
		}
		
		
		busy = false;
		
	};
	
	this.build = function()
	{
		/* Fix version 0.21 de perrohunter */

	var myAccordion = new Accordion('ul.menu', 'div.mcontent0', 'li.childMenu', {
		opacity: false,
		onActive: function(toggler, element){
			toggler.setStyle('color', '#fefefe');
		},
		onBackground: function(toggler, element){
			toggler.setStyle('color', '#ffffff');
		}
	});
		
		$$('.childMenu1').addEvent('click',function() {
			$$('.childMenu1').removeClass('tabact');
			this.addClass('tabact');
		});

		
		
	
		
		mySlide = new Fx.Slide('lefter', {mode: 'horizontal', onComplete: this.completed, transition: Fx.Transitions.linear});
		$('lefter').getParent().setAttribute("id","sideslide");
		fx = new Fx.Styles('content', {transition: Fx.Transitions.linear});
	
		ordisp = $('menu').getStyle('display');
		origPos = $('content').getStyle('width').toInt();
		paddMinus = $('content').getStyle('padding-left').toInt() + $('content').getStyle('padding-right').toInt();
		maxGrowt = $('wrapper').getStyle('width').toInt() - paddMinus;
		busy = false;
	}
	

	
	this.hide = function()
	{
		if(hiden == false)
		{
			this.toggle();
		}
	}
	this.show = function()
	{
		if(hiden == true)
		{
			this.toggle();
		}
	}
	this.toggle = function()
	{
		if(busy == true)
		{
			return;
		}
		busy = true;
		
		
		if(hiden == true)
		{
			$('lefter').setStyle('opacity',1);
			toggler.addClass('toggleron');
			toggler.removeClass('toggleroff');
		}
		
		if($('content').getStyle('width').toInt() == maxGrowt )
		{
			
			
			fx.start({'width': origPos});
			(function() { mySlide.toggle();  } ).delay(25);
			
			
		}
		else
		{
			(function() { fx.start({'width': maxGrowt} ); }).delay(25);
			mySlide.toggle();
		}
		
		hiden = !hiden;
		
		
			
		
	}
	
	
	this.build();
	//mySlide.hide();
	hiden = false;
	//$('contentDiv').setStyle('width',600);
}
