/**
 * @author   Ivan Andonov
 * @email    ivan.andonov[at]design[dot]bg
 *
 * @require  init
 *           use  dbg.Debug
 * @optional 
 **/

dbg.extend({
	
	ShortcutCall : new dbg.Class.create('ShortcutCall', dbg).extend({
	
		// PRIVATE PROPS
		_shotcuts : {},
		
		// PRIVATE METHODS
		_get : function(shortcut, local) {
			return local ? this._shotcuts['$'+shortcut] : window['$'+shortcut];
		},
		
		_delete : function(shortcut) {
			delete window['$'+shortcut];
		},
		
		// PUBLIC METHODS
		add : function(shortcut, target, method) {
			var t = target;
			var m = method;
			var shortcuts = typeof(shortcut) == 'string' ? [shortcut] : shortcut;
			var len = shortcuts.length;
			for (var i = 0; i < len; i++) {
				window['$'+shortcuts[i]] = function(shortcut) {
					try {
						return (typeof(m) == 'string' ? t[m] : m).apply(t, arguments);
					} catch (error) {
						try {
							$logError('WARNING: shortcut "'+shortcuts+'" delegate error on method '+t+'.'+m+ '; description: '+(error.description || error));
						} catch(e) {};
					}
				};
			}
		},
		
		remove : function(shortcut) {
			var s = this._get(shortcut);
			if (s) {
				delete s;
			} else {
				delete this.shotcuts[shortcut];
			}
		},
		
		disable : function() {
			var s = this._get(shortcut);
			if (s) {
				this._shotcuts[shortcut] = s;
				delete s;
			}
		},
		
		enable : function() {
			var s = this._get(shortcut);
			if (s) {
				this._shotcuts[shortcut] = s;
				delete s;
			}
		}
		
	})
	
});

dbg.ShortcutCall.add('shortcut', dbg.ShortcutCall, 'add');