var RuzafaSala = Class.create(
{
	body:			false,
	node:			false,
	state:			false,
	opacity:		false,
	websiteLogo:	false,
	salaLogo:		false,
	salaContent:	false,
	
	initialize: function(node)
	{
		this.body			=	$(document.body);
		this.node			=	node;
		this.state			=	this.body.hasClassName("page_sala") ? true : false;

		//	We need this opacity map to determine which way to animate the opacity, 
		//	depending on whether you start in the sala page or not
		//	Otherwise, you end up animating the wrong way
		this.opacity		=	this.state ? [1,0] : [0,1];
		
		this.websiteLogo	=	this.node.down(".left_logo img");
		this.salaLogo		=	this.node.down(".right_logo img");
		this.salaContent	=	this.body.down(".sala");
		
		if(this.salaContent){		
			this.setupLogo();
			this.setupMouseHandler();
		}
	},
	
	getState: function()
	{
		return this.state;
	},
	
	setupMenu: function(menu)
	{
		this.menu = menu;
	},
	
	setupMouseHandler: function()
	{
		var po = this;
		
		this.node.select("a").invoke("observe","click",function(event){
			if(this.up(".left_logo")){
				po.hide();
			}else{
				po.show();
			}
			
			event.stop();
			return false;
		});
	},
	
	setupLogo: function()
	{},
	
	show: function()
	{
		if(this.state == false){
			this.state = true;
			
			this.menu.hide();
			
			this.body.morph("background:#FFFFFF",2);
			
			this.salaContent.morph("opacity:1",{
				duration: 2,
				before:function(s){ 
					s.element.setStyle({display:"block"});
				},
				after: function(){
					if(this.body.hasClassName("page_sala")){
						this.node.select("a").invoke("setStyle",{backgroundPosition:"0 100px"});
					}
				}.bind(this)
			});
			
			if(this.body.hasClassName("page_sala")){
				this.node.select(".normal_logo").invoke("morph","opacity:1",2);	
			}
		}
	},
	
	hide: function()
	{
		if(this.state == true){
			this.state = false;
			
			this.menu.show();
			
			this.body.morph("background:#413132",2);
			
			this.salaContent.morph("opacity:0",{
				duration: 2,
				after:function(s){ 
					s.element.setStyle({display:"none"}); 
				}
			});
			
			if(this.body.hasClassName("page_sala")){
				this.node.select("a").invoke("setStyle",{backgroundPosition:"0 0"});
				this.node.select(".normal_logo").invoke("morph","opacity:0",2);
			}
		}
	}
});
