var SidebarReload = Class.create();

SidebarReload.prototype =
{
	initialize:function()
	{
		this.speedMorph = 0.5;
		this.speedBlind = 1.0;
		Event.observe(document,'dom:loaded',this.makeSidebar.bindAsEventListener(this));
	},
	
	makeSidebar:function()
	{
		this.arrowOff = $$('.buttons')[0];
		this.arrowOn = $$('.clickedbuttons')[0];
		this.elementLeft = $$('.forums')[0];
		this.elementRight = $$('.sidebar')[0];
		this.arrowOn.hide();
		Event.observe(this.arrowOn,'click',this.sidebarOn.bindAsEventListener(this));
		Event.observe(this.arrowOff,'click',this.sidebarOff.bindAsEventListener(this));
		
		if(Cookie.get('sidebar_status') == 'off')
		{
			this.arrowOff.hide();
			this.arrowOn.show();
			this.elementRight.hide();
			this.elementLeft.setStyle('width: 100%;')
		}
	},
				
	sidebarOn:function(e)
	{
		this.arrowOff.show();
		this.arrowOn.hide();
		//$$(sidebar_reload.elementLeft).setStyle({'width': '82%'});
		//this.elementRight.show();
		
		
		Cookie.set('sidebar_status','visible');
		new Effect.Morph(sidebar_reload.elementLeft,
		{
			style:'width: 82%',
			duration:sidebar_reload.speedMorph,
			afterFinish:function()
			{
				new Effect.Parallel([
					new Effect.BlindDown(sidebar_reload.elementRight,{sync:true}),
					new Effect.Opacity(sidebar_reload.elementRight,{sync:true, from:0,to:1})
				], {
					duration:sidebar_reload.speedBlind,
				});
			}
		});
	},
	
	sidebarOff:function(e)
	{
		this.arrowOn.show();
		this.arrowOff.hide();
		//this.elementRight.hide();
		//$$(sidebar_reload.elementLeft).setStyle({'width': '100%'});
		
		Cookie.set('sidebar_status','off');
		
		new Effect.Parallel([
			new Effect.BlindUp(sidebar_reload.elementRight,{sync:true}),
			new Effect.Opacity(sidebar_reload.elementRight,{sync:true, from:1,to:0})
		], {
			duration: sidebar_reload.speedBlind,
			afterFinish:function()
			{
				new Effect.Morph(sidebar_reload.elementLeft,
				{
					style:'width: 100%',
					duration:sidebar_reload.speedMorph,
				});
			}
		});
	}
};
		
var sidebar_reload = new SidebarReload();

