



CKEDITOR.plugins.add( 'SFStoryImages', {
	
	init: function(editor) {
		
		var centerPopup = function(url, 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, 'sfs-media-popup', 'status=no, menubar=no, titlebar=no, scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
		    if (window.focus) {
		        newWindow.focus();
		    }
		};

		// Command.
		editor.addCommand('SFStoryImagesPopup', {
			exec: function() {
				CKEDITOR.storyImagesOpener = editor;
				centerPopup('/SITEFORUM?t=/file/fm.popup&image_dialog=editorInternalPopup', 1100, 700);
			}
		});
		
		// Button.
		editor.ui.addButton( 'SFStoryImages', {
			label: 'SITEFORUM Story Images',
			command: 'SFStoryImagesPopup',
			icon:  '/global_files/icons/fugue/image--plus.png'
		});
	}
});


