if(!$chk(slvr)) {
	var slvr = {};
}

/**
 * slvr.NotificationCenter
 *
 * @classDescription slvr.NotificationCenter
 */
slvr.NotificationCenter = new Class({

	/**
	 * Options
	 * 
	 * @type {Object}
	 */
	options: {

	},
	
	notificationList: null,
	
	/**
	 * slvr.NotificationCenter Constructor
	 * 
	 * @param {Object} options
	 */
	initialize: function(options) {
		this.setOptions(options);
		this.notificationList = {};
		window.addEvent('resize', this.windowResizeHandler.bindWithEvent(this));
		window.document.addEvent('click', this.documentClickedHandler.bindWithEvent(this));
	},
	
	addObserver: function(observer, name, method) {
		if(!$chk(this.notificationList[name])) {
			this.notificationList[name] = [];
		}
		this.notificationList[name].push({'observer': observer, 'method': method});
	},
	
	removeObserver: function(observer, name) {
		if($chk(this.notificationList[name])) {
			for(var i=0;i<this.notificationList[name].length;i++) {
				if(this.notificationList[name][i] !== null && this.notificationList[name][i]['observer'] == observer) {
					this.notificationList[name][i] = null;
				}
			}

		}
	},
	
	postNotification: function(name) {
		
		if($chk(this.notificationList[name])) {
			for(var i=0;i<this.notificationList[name].length;i++) {
				if(this.notificationList[name][i] !== null) {
					this.notificationList[name][i].method();
				}
			}
		}

	},
	
	windowResizeHandler: function(e) {
		this.postNotification('windowDidResize');
	},
	
	documentClickedHandler: function(e) {
		this.postNotification('documentWasClicked');
	}

});
slvr.NotificationCenter.implement(new Options);
slvr.NotificationCenter.implement(new Events);

slvr.SharedNotificationCenter = function() {
	if(!$chk(window.SharedNotificationCenterInstance)) {
		window.SharedNotificationCenterInstance = new slvr.NotificationCenter();
	}
	return window.SharedNotificationCenterInstance;
}
