

CKEDITOR.plugins.add( 'SFLinkGenerator', {
	
	init: function(editor) {

		var centerPopup = function(url, title, w, h) {
		    var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
		    var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;
		    width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
		    height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
		    var left = ((width / 2) - (w / 2)) + dualScreenLeft;
		    var top = ((height / 2) - (h / 2)) + dualScreenTop;
		    var newWindow = window.open(url, title, 'status=no, menubar=no, titlebar=no, scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
		    if (window.focus) {
		        newWindow.focus();
		    }
		};

		// Command.
		editor.addCommand('SFLinkGeneratorPopup', {
			exec: function() {
				CKEDITOR.linkGeneratorOpener = editor;
				centerPopup('/SITEFORUM?t=/contentManager/create.link&app=embedded', "link-generator-popup", 500, 600);
			}
		});
		
		// Button.
		editor.ui.addButton('SFLinkGenerator', {
			label: 'SITEFORUM Link Generator',
			command: 'SFLinkGeneratorPopup',
			icon:  '/global_files/icons/fugue/globe--plus.png'
		});
	}
});


