Of.Windows = {
	name: 'Windows',
	namespace: 'Of',
	type: 'Namespace'
};

Of.Windows.Base = new Class({
	name: 'Window',
	namespace: 'Of',
	type: 'Window',
	
	Extends: Of.Base,
	Implements: Options,
	
	options: {
		local: {
			closed: false,
			size: null,
			position: null
		},
		properties: {}
	},
	
	onBeforePropSet: $empty,
	onAfterPropSet: $empty,
	
	init: function(options)
	{
		this.setOptions({}, this.options, options);
		this.onBeforePropSet();
		this._initProps();
		this.onAfterPropSet();
		this._processOptions();
	},
	_processOptions: function()
	{
		if (this.options.draggable)
		{
			this.makeDraggable({handle: this.getProp('title') || this});
		}
	},
	_initProps: function()
	{
		this.getElements('[prop]').each(function(property){
			var propertyName = property.getAttribute('prop');
			this.options.properties[propertyName] = property;
			
			var initFuncName = 'init_' + propertyName;
			var propertyOptions = property.getAttribute('options') || {};
			
			if ($defined(this[initFuncName]))
			{
				this[initFuncName](property, propertyOptions);
			}
		}.bind(this));
	},
	getLocal: function(localName)
	{
		if ($defined(this.options.local[localName]))
			return this.options.local[localName];
			
		return false;
	},
	setLocal: function(localName, localeValue)
	{
		return this.options.local[localName] = localeValue;
	},
	getProp: function(propertyName)
	{
		if ($defined(this.options.properties[propertyName]))
		{
			return this.options.properties[propertyName];
		}
		
		return false;
	},
	open: function()
	{
		this.setStyles({opacity: 0, visibility: 'hidden'});
		this.removeClass('closed');
		
		var newLeft = document.getSize().x/2 - this.getSize().x/2;
		this.setStyles({left: newLeft});
		
		this.morph({opacity: 1});
		this.options.local.closed = false;
	},
	close: function()
	{
		this.morph({opacity: 0});
		this.addClass.delay(1000, this, 'closed');
		this.options.local.closed = true;
	},
	isClosed: function()
	{
		return this.options.local.closed;
	},
	toggle: function()
	{
		var newTop = this.getSize().y/2 + this.getPosition().y;
		this.morph({height: 0, top: newTop});
	}
});

Of.Windows.Properties = new Class({
	name: 'Properties',
	namespace: 'Of.Windows',
	type: 'Helper Class',
	init_close: function(property, options)
	{
		property.setAttribute('href', 'javascript:void(0)');
		
		property.addEvent('click', function(){
			this.close();
		}.bind(this));
	},
	init_button: function(property, options)
	{
	}
});

Of.Windows.Error = new Class({
	name: 'Error',
	namespace: 'Of.Windows',
	type: 'Helper Class (Error)',
	addError: function(error)
	{
	},
	getErrors: function()
	{
	},
	cleanErrors: function()
	{
	},
	init_error: function(property, options)
	{
	}
});

Of.Windows.Simple = new Class({
	name: 'Simple',
	namespace: 'Of.Windows',
	type: 'Window',
	Extends: Of.Windows.Base,
	Implements: [Of.Windows.Properties, Of.Windows.Error]
});
