if (typeof(SC) == "undefined") { SC = {}; }

SC.Panel = Class.create();
Object.extend(SC.Panel.prototype, Event.Listener);
Object.extend(SC.Panel.prototype, Event.Publisher);
Object.extend(SC.Panel.prototype, {
	
	title_attr:'panel_title',
	style_attr:'panel_style',
	
	initialize: function(items, options) {
		this.items = items;
		
		this.options = options || {};
		
		if (this.items.length>0) {
			this.createPanel();
			this.setDefaults();
			this.setItemAttributes();
		}
	},
	createPanel: function() {
		that = this;
		this.items.each(function(item){
			var title = item.readAttribute(that.title_attr);			var style = item.readAttribute("style");			if (title == null) title = "";			if (style == null) style = "";
			item.content = Builder.node('div', {'class':'panel_content '});
			item.content.innerHTML = item.innerHTML;
			item.header = Builder.node('div',{'class':'panel_header'}, [ 
				Builder.node('h1',title) 
			]);	
			item.shadow = Builder.node('div', {'class':'panel_shadow ','style':style});
			$(item.shadow).insert({top:item.header});			$(item.shadow).insert(item.content);
			item.replace( item.shadow );
		});
	},
	
	buildContents: function() {},
	
 	setDefaults: function() {
		that = this;
		this.items.each(function(item){
			if (item.readAttribute(that.style_attr)) {
				var panel = ('{"' + item.readAttribute(that.style_attr).gsub(';', '","').gsub(':', '":"') + '"}').evalJSON();
				var style = "width:"+panel.width+"px";
				$(item.shadow).setStyle(style);
				$(item.content).setStyle(style);
			}
		});
 	},
	setItemAttributes: function() {}	
});