
var PanelItems = new Class
({
	initialize: function(panel_hdg_close, panel_num) 
	{
	        //alert("PanelItems: initialize");
		this.Panels = new Array();		
		$each(panel_hdg_close, function(trigger) { this.panels_allow_toggle($(trigger)); }, this);		
		this.panels_close_all(true);
		this.Panels[panel_num].panel_open(false);
	},
	
	panels_allow_toggle: function(trigger) 
	{
	        //alert("PanelItems: panels_allow_toggle");
		this.Panels[this.Panels.length] = new PanelActions(trigger, this);
	},
	
	panels_close_all: function(quick, panel_open_rqst) 
	{
	        //alert("PanelItems: panels_close_all");    
		$each(this.Panels, function(trigger) { if (trigger !== panel_open_rqst) trigger.panel_close(quick); });
	}
});

var PanelActions = new Class
({
	initialize: function(trigger, parent) 
	{
	        //alert("PanelActions: initialize");
		this.Element = trigger;
		this.Parent = parent;
		/* Panel content */
		this.Content = trigger.getNext();
		this.Container = new Element('div');
		this.Effect = new Fx.Styles(this.Container, {duration:500, transition:Fx.Transitions.circOut});
		this.IsOpen = true;
		this.Content.replaceWith(this.Container).appendChild(this.Content);
		this.MaxHeight	= this.Content.getSize().scrollSize.y;
		
		this.Container.setStyles
		({
		'overflow-x': 'hidden',
		'overflow-y': 'hidden'
		});
		
		// panel_cnt + padding - allow scrolling if necessary
		if (this.MaxHeight > 114)
		{
			this.Container.setStyles
			({
			'overflow-y': 'scroll'
			});
		}				
		this.MaxHeight = '115';
					
		this.Element.addEvent('click', this.panel_toggle.bind(this, [false]));
		this.Element.setStyle('cursor', 'pointer');
	},
	
	panel_open: function(quick) 
	{
	        //alert("PanelActions: panel_open");
		this.IsOpen = true;
		this.Effect.stop();
		this.Element.removeClass('panel_hdg_close');
		this.Element.addClass('panel_hdg_open');		
		
		if (quick) 
		{
			this.Effect.set
			({
				height:  [this.MaxHeight],
				opacity: [1]
			});
		}
		else 
		{
			this.Effect.start
			({
				height:  [this.MaxHeight],
				opacity: [1]
			});
		}
		
		this.Parent.panels_close_all(false, this);
	},	
			
	panel_close: function(quick) 
	{
	        //alert("PanelActions: panel_close");
	        // alert(quick);
		this.IsOpen = false;
		this.Effect.stop();
		this.Element.addClass('panel_hdg_close');
		this.Element.removeClass('panel_hdg_open');
		
		if (quick) 
		{
			this.Effect.set
			({
				height:  [0],
				opacity: [0]
			});
		}
		else 
		{
			this.Effect.start
			({
				height:  [0],
				opacity: [0]
			});
		}
	},	
	
	panel_toggle: function(quick) 
	{
	        //alert("PanelActions: panel_toggle");
		if (this.IsOpen)
			this.panel_close(quick);
		else
			this.panel_open(quick);
	}
});

