CKEDITOR.plugins.add('dclink', {
	icons: 'dclink',
	init: function(editor) {
		editor.addCommand('dcLinkCommand', {
			exec: function(editor) {
				if (editor.getSelection().getNative().toString().replace(/\s*/,'')!='') {
					var url = 'popup_link.php?editor='+editor.name;
					var p_win = window.open(url,'dc_popup'
								,'alwaysRaised=yes,dependent=yes,toolbar=yes,'+
								'height=420,width=520,menubar=no,resizable=yes,scrollbars=yes,status=no');
				}
			}
		});

		editor.ui.addButton('dcLink', {
			label: 'Link',
			command: 'dcLinkCommand',
			toolbar: 'insert'
		});

		editor.on('doubleclick',function(e) {
			if (e.data.element.getName()!='a') {
				return false;
			}

			console.log('a dialog: ', e.data.element.getName());
			console.log('selection: ', editor.getSelection());
			//.getNative().toString()
			var element = CKEDITOR.plugins.link.getSelectedLink(editor) || e.data.element;

			if (!element.isReadOnly()) {
				console.log('a dialog: ', element);
				var url = 'popup_link.php?editor='+editor.name;
				var p_win = window.open(url,'dc_popup');

			}
		});
	}
});
