/*
 * Corner
 */

Gx.Corner = new Class({
	Implements: [Events],
	initialize: function(container, options) {
		this.container = $(container).setOpacity(0).setBlock();
		this.cr = {top: {}, middle: {}, bottom: {}};
		
		$each(this.cr, function(prop, name) {
			['left', 'center', 'right'].each(function(classname) {
				prop[classname] = new Element('div', {'class': 'corner ' + name + ' ' + classname}).inject(container, 'top');
				prop[classname].size = prop[classname].getSize();
			});
		});
		
		this.resize();
		//this.fireEvent('onInitialize');
		this.container.setStyle('display', 'none');
	},
	resize: function() {
		if (this.container.getStyle('display') == 'none')
			this.container.setOpacity(0).setBlock();
	
		var cs = this.container.getSize(), value = {
			top: 	{ top: 0, height: this.cr.top.left.size.y },
			middle: { top: this.cr.top.left.size.y, height: cs.y - this.cr.top.left.size.y - this.cr.bottom.left.size.y },
			bottom: { top: cs.y - this.cr.bottom.left.size.y, height: this.cr.bottom.left.size.y }
		};

		$each(this.cr, function(prop, name) {
			prop.left.setStyles({
				height: value[name].height,
				left: 0,
				top: value[name].top
			});
			
			prop.center.setStyles({
				height: value[name].height,
				width: cs.x - prop.left.size.x - prop.right.size.x,
				left: prop.left.size.x,
				top: value[name].top
			});
	
			prop.right.setStyles({
				height: value[name].height,
				left: cs.x - prop.right.size.x,
				top: value[name].top
			});
		});
	}
});
