var Panel = new Class({
	
	Implements: Chain,
	
	initialize: function(element, url, morph, settings)
	{
		this.id = element;
		this.e = $(element);
		this.url = url;
		this.m = morph;
		this.s = settings;
		
		this.applySettings();
		this.t = new Fx.Morph(this.e,{duration:'normal', transition:'cubic:out', onComplete: function() { this.afterMorph();}.bind(this) });
		this.e.setStyle('opacity',0);
		//this.t.addEvent('onComplete', function() { this.callChain();}.bind(this))};
	},
	
	
	doRefresh: function()
	{
		this.clearChain();
		this.chain(	function(){ this.doMorph(this.m.morphClose); }		);
		this.chain(	function(){ this.doRequest(); }					);
		this.chain(	function(){ this.doMorph(this.m.morphOpen); }		);
		this.callChain();
	},
	
	doOpen: function()
	{
		this.clearChain();
		this.chain(	function(){ this.doRequest(); }					);
		this.chain(	function(){ this.doMorph(this.m.morphOpen); }		);
		this.callChain();
	},
	
	doClose: function()
	{
		this.clearChain();
		this.chain(	function(){ this.doMorph(this.m.morphClose); }		);
		this.callChain();
	},
	
	doRequest: function()
	{
		new Request.HTML({url:this.url, update:this.e, 	data:vo, onSuccess:function(responseTree, responseElements, responseHTML, responseJavaScript){this.afterRequest(responseTree, responseElements, responseHTML, responseJavaScript);}.bind(this) }).send();
	},
	
	afterRequest: function(responseTree, responseElements, responseHTML, responseJavaScript)
	{
		//alert(responseJavaScript);
		this.callChain();
		initAjaxButton(this.id);
		
			if(this.e == $('content') && vo.what == 'getItem')
			{
				
				var h = $('content').getSize().y;
			
				if(h <1400){h=1150;}
				
				$('content').setStyle('height',h);
				$('nav').setStyle('height',h);
				$('related').setStyle('height',h);
				
				
			}
			
			if(this.e == $('list') && vo.what == 'getList')
			{
				
				var h = $('list').getSize().y;
				if(h <1000){h=1000;}
				
				
				$('nav').setStyle('height',h);
				$('list').setStyle('height',h);
				
			}
		
	},
	
	doMorph: function(what)
	{
		//this.e.setStyle('height',1000);
		this.t.start(what);
	},
	
	afterMorph: function(t)
	{
		if(this.callChain()== false)
		{
			var h = document.getScrollSize().y;
			
		
		
			
			if($('player')&&this.id=='content')
			{
				$('player').setStyle('visibility','visible');
				//$('player').innerHTML = '&nbsp;'
				writePlayer();
			}
			if(this.parentChain)
			{
				this.parentChain.callChain();
			}
		}else{
			this.callChain();
		}
	},
	
	addToParentChain: function(parentChain)
	{
		this.parentChain = parentChain;
	},
	
	applySettings: function()
	{
		this.e.setStyle('width',this.s.width);
		this.e.setStyle('top',this.s.top);
		this.e.setStyle('left',this.s.left);
		this.e.setStyle('marginLeft',this.s.marginLeft);
		this.e.setStyle('display', 'block');
	}
	
});


