var amai = {
		
	extras: true,
	bubbles: {},
		
	init: function(){

		//eventos de los extras
		$('.switch a').click(function(){	
			(amai.extras) ? amai.undecorate() : amai.decorate()
			return false;
		});
		//la lengua
		$('#lengua').hide();
		$('#amai_logo').hover(
			function(){if(amai.extras) $('#lengua').show();},
			function(){if(amai.extras) $('#lengua').hide();}
		);
	    
		//las animaciones flash
	    var lang = $('#header-alt').attr('rel');
	    swfobject.embedSWF(
	    	"/layout/extras/amai_header-"+lang+".swf", "header-alt",
	    	"800", "400", "8.0.0",
	    	'/js/swfobject/expressInstall.swf',
	    	{}, 
	    	{'wmode': 'transparent'},
	    	{'class': 'extras'}
	    );
	    //el fondo
		swfobject.embedSWF(
	    	"/layout/extras/fondobb.swf", "fondobb",
	    	"100%", "100%", "8.0.0",
	    	'/js/swfobject/expressInstall.swf',
	    	{},
	    	{'wmode': 'transparent'},
	    	{'class': 'extras'}
	    );

		//y decoramos
		var extras = $.cookie('amai-extras');
		amai.extras = (extras == 'off') ? false : true;
		(amai.extras) ? amai.decorate() : amai.undecorate();

	},
		
	decorate: function(){
		//alert('decoramos');
		amai.extras = true;
		$.cookie('amai-extras', 'on', {path: '/'});
        $('.extras').fadeIn();
        $('#switch_on').fadeOut();
		$('#amai_texto').animate({marginTop: 0, marginBottom: 60});
        return true;
	},
	undecorate: function(){
		//alert('undecoramos');
		amai.extras = false;
		$.cookie('amai-extras', 'off', {path: '/'});
        $('.extras').fadeOut();
        $('#switch_on').fadeIn();
		$('#amai_texto').animate({marginTop: 40, marginBottom: 8});
		return true;
	},
	
	//funcion extra para ajustar los márgenes del menú
	fixMenu: function(){
		var menu = $($('div.menu ul').get(0));
		var li = menu.children();
		var w0 = menu.width();
		if(!$.support.boxModel) w0 =- 40;
		var w1 = 0;
		li.each(function(){ w1 += $(this).width(); });
		var m = Math.floor((w0 - w1 - 20)/(li.length * 2));
		//console.log(w0+' - '+w1+' - '+m);
		li.css({
			'marginLeft': m,
			'marginRight': m
		});		
	}
	
	
}
/*
$(function(){ 
	amai.fixMenu();
	$('body').hide();
});
$(window).load(function(){
	amai.init();
	$('body').show();
});
*/
