var Drawer = new Class({	
	
	initialize: function(content, controller, open)
	{
		this.c = controller;
		this.content = content;
		
		this.height = this.content.getSize().y;;
		
		this.open = open; 
		if(!this.open) this.content.setStyle('height','0');		
		
		this.t = new Fx.Morph(this.content,{duration:'normal', transition:'cubic:out', onComplete: function() { this.afterMorph();}.bind(this) });
		
		this.drawerButtons = [];
		
		$$('.drawerButton').each
		(
			function(e)
			{
				this.drawerButtons.include(new DrawerButton(e, this.c, this));
			}.bind(this)
		);
	},
	
	toggleDrawer:function(h)
	{
		this.open ? this.closeDrawer() : this.openDrawer();		
	},
	
	openDrawer: function()
	{
		var m = {'height':[this.height]};
		this.t.start(m);
	},
	
	closeDrawer: function()
	{
		var m = {'height':[0]};
		this.t.start(m);
	},
	
	afterMorph: function()
	{
		this.open = this.open ? false : true;	
		this.c.doEvent('playerHandleReady', this);
		
		this.drawerButtons.each
		(
			function(b)
			{
				if (this.open) 
				{
					b.imgElement.set('src', b.vo.openedOut);
				}else{
					b.imgElement.set('src', b.vo.closedOut);
				}
			}.bind(this)
		
		);
	}
});



var DrawerButton = new Class({	
	
	Extends: Button,
	
	initialize:function(element, controller, drawer)
	{
		this.setElement(element);
		this.setController(controller,'playerHandleClicked');
		
		this.drawer = drawer;
		this.vo = eval("(" + this.e.get('id') + ")");
		
		this.imgElement =  new Element('img',{'src': this.vo.closedOut}); 	
		this.imgElement.inject(this.e);
		
	},
	
	doMouseover: function()
	{
		
		if (this.drawer.open)
		{
			this.e.style.cursor = 'pointer';
			this.imgElement.set('src', this.vo.openedOver);
		}else{
			this.e.style.cursor = 'pointer';
			this.imgElement.set('src', this.vo.closedOver);
		}
	},
	
	doMouseout: function()
	{
		if (this.drawer.open)
		{
			this.e.style.cursor = 'pointer';
			this.imgElement.set('src', this.vo.openedOut);
		}else{
			this.e.style.cursor = 'pointer';
			this.imgElement.set('src', this.vo.closedOut);
		}
	}
});


