Index: /CKEditor/branches/prototype/_source/plugins/image/dialogs/image.js
===================================================================
--- /CKEditor/branches/prototype/_source/plugins/image/dialogs/image.js	(revision 2812)
+++ /CKEditor/branches/prototype/_source/plugins/image/dialogs/image.js	(revision 2813)
@@ -22,11 +22,20 @@
 imageDialog = function( editor, dialogType )
 {
-	var regexSize = /^\s*(\d+)(px)?\s*$/i;
 	var uploadAction = 'nowhere.php';
+	var regexSize = /^\s*(\d+)((px)|\%)?\s*$/i;
 	var imageDialog = ( dialogType == 'image' );
+	var previewAreaHtml = '<div>' + CKEDITOR.tools.htmlEncode( editor.lang.dlgImgPreview ) +'<br>'+
+		'<div id="ImagePreviewLoader" style="display:none"><div class="loading">&nbsp;</div></div>'+
+		'<div id="ImagePreviewBox">'+
+		'<a href="javascript:void(0)" target="_blank" onclick="return false;" id="previewLink"><img id="previewImage" src="" /></a>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas feugiat consequat diam. Maecenas metus. Vivamus diam purus, cursus a, commodo non, facilisis vitae, nulla. Aenean dictum lacinia tortor. Nunc iaculis, nibh non iaculis aliquam, orci felis euismod neque, sed ornare massa mauris sed velit. Nulla pretium mi et risus. Fusce mi pede, tempor id, cursus ac, ullamcorper nec, enim. Sed tortor. Curabitur molestie. Duis velit augue, condimentum at, ultrices a, luctus ut, orci. Donec pellentesque egestas eros. Integer cursus, augue in cursus faucibus, eros pede bibendum sem, in tempus tellus justo quis ligula. Etiam eget tortor. Vestibulum rutrum, est ut placerat elementum, lectus nisl aliquam velit, tempor aliquam eros nunc nonummy metus. In eros metus, gravida a, gravida sed, lobortis id, turpis. Ut ultrices, ipsum at venenatis fringilla, sem nulla lacinia tellus, eget aliquet turpis mauris non enim. Nam turpis. Suspendisse lacinia. Curabitur ac tortor ut ipsum egestas elementum. Nunc imperdiet gravida mauris.' +
+		'</div>'+'</div>';
 
 	var addChange = function( name, input, object ){
 		var dialog = input.getDialog();
 		
+		//Don't load before onShow.
+		if ( !dialog.allowOnChange )
+			return 0;
+
 		if ( input.isChanged() || ( dialog.editMode[ object ] == false && input.getValue() != '' ))
 		{
@@ -40,5 +49,4 @@
 	{
 		var dialog = input.getDialog();
-		var editor = dialog.getParentEditor();
 
 		//Don't load before onShow.
@@ -46,5 +54,5 @@
 			return 0;
 
-		updateOriginal( dialog, true );
+		updateOriginal( dialog, true );	// true = reset size.
 		updatePreview( dialog );
 	}
@@ -53,5 +61,4 @@
 	{
 		var dialog = input.getDialog();
-		var editor = dialog.getParentEditor();
 
 		//Don't load before onShow.
@@ -69,6 +76,5 @@
 					dialog.allowOnChange = false;
 					if ( value != '' && value != 0 )
-						value = Math.round( oImageOriginal.$.height * ( value  / oImageOriginal.$.width ) );
-					// Image loaded but with unknow size.
+						value = Math.round( oImageOriginal.$.width * ( value  / oImageOriginal.$.height ) );
 					if ( !isNaN( value ) )
 						dialog.setValueOf( 'info', 'txtWidth', value );
@@ -89,6 +95,67 @@
 	}
 
+	var onChange = function( input, attribute )
+	{
+		var dialog = input.getDialog();
+
+		//Don't load before onShow.
+		if ( !dialog.allowOnChange )
+			return 0;
+
+		updatePreview( dialog );
+	}
+
 	var updatePreview = function( dialog )
 	{
+		if ( !dialog.editObj[ 'imagePreview' ] )
+			return 1;
+
+		var url = dialog.getContentElement( 'info', 'txtUrl' ).getValue();
+
+		// New url
+		if ( url != dialog.editObj[ 'imagePreview' ].getAttribute( 'src' ) )
+			dialog.editObj[ 'imagePreview' ].setAttribute( 'src', url );
+		
+		var width = 0;
+		var height = 0;
+		var oImageOriginal = dialog.editObj[ 'imageOriginal' ];
+			
+		width = dialog.getValueOf( 'info', 'txtWidth' );
+		height = dialog.getValueOf( 'info', 'txtHeight' );
+
+		if ( width == '' && oImageOriginal )
+			width = oImageOriginal.$.width;
+		if ( height == '' && oImageOriginal )
+			height = oImageOriginal.$.height;
+
+		dialog.editObj[ 'imagePreview' ].setStyle( 'width', width + 'px');
+		dialog.editObj[ 'imagePreview' ].setStyle( 'height', height + 'px');
+
+		// Read attributes
+		var border = dialog.getValueOf( 'info', 'txtBorder' );
+		var hspace = dialog.getValueOf( 'info', 'txtHSpace' );
+		var vspace = dialog.getValueOf( 'info', 'txtVSpace' );
+		var align = dialog.getValueOf( 'info', 'cmbAlign' );
+
+		// Validate values
+		border = parseInt( border, 10 );
+		hspace = parseInt( hspace, 10 );
+		vspace = parseInt( vspace, 10 );
+
+		border = isNaN( border ) ? 0 : border;
+		hspace = isNaN( hspace ) ? 0 : hspace;
+		vspace = isNaN( vspace ) ? 0 : vspace;
+
+		// TODO. Doesn't work becouse of a:active{border 0px} from reset.css
+		dialog.editObj[ 'imagePreview' ].setAttribute( 'border', border );
+		dialog.editObj[ 'imagePreview' ].setAttribute( 'hspace', hspace );
+		dialog.editObj[ 'imagePreview' ].setAttribute( 'vspace', vspace );
+		dialog.editObj[ 'imagePreview' ].setAttribute( 'align', align );
+		
+		dialog.editObj[ 'imagePreview' ].setStyle( 'border', border + 'px solid black');
+		dialog.editObj[ 'imagePreview' ].setStyle( 'margin-top', vspace + 'px');
+		dialog.editObj[ 'imagePreview' ].setStyle( 'margin-bottom', vspace + 'px');
+		dialog.editObj[ 'imagePreview' ].setStyle( 'margin-left', hspace + 'px');
+		dialog.editObj[ 'imagePreview' ].setStyle( 'margin-right', hspace + 'px');
 		return 0;
 	}
@@ -100,11 +167,23 @@
 
 		dialog.editObj[ 'imageOriginal' ].setCustomData( 'isReady', 'false' );
-		if ( dialog.editObj && url.length>0 )
-		{
+		if ( dialog.editObj && url.length > 0 )
+		{
+			// Show loader
+			var loader = CKEDITOR.document.getById( 'ImagePreviewLoader' );
+			if ( loader )
+				loader.setStyle('display', '');
+			
 			dialog.editObj[ 'imageOriginal' ].on( 'load', function()
 				{
-					//Image is ready.
+					// Image is ready.
 					this.editObj[ 'imageOriginal' ].setCustomData( 'isReady', 'true' );
 					this.editObj[ 'imageOriginal' ].removeListener( 'load' );
+					
+					// Hide loader
+					var loader = CKEDITOR.document.getById( 'ImagePreviewLoader' );
+					if ( loader )
+						loader.setStyle('display', 'none' );
+			
+					// New image -> new domensions
 					if ( forceResetSize ){
 						resetSize( this );
@@ -118,5 +197,5 @@
 	{
 		dialog.imageLockRatio = !dialog.imageLockRatio;
-		return 0;
+		return dialog.imageLockRatio;
 	}
 
@@ -144,5 +223,7 @@
 			if ( aMatchH )
 			{
-				dialog.imageDimenstions[ 'height' ] = aMatchH[1];
+				// % is allowed.
+				if ( aMatchH[2] == '%' )
+					aMatchH[1] += '%';
 				heightText = aMatchH[1];
 			}
@@ -155,8 +236,17 @@
 			if ( aMatchW )
 			{
-				dialog.imageDimenstions[ 'width' ] = aMatchW[1];
+				// % is allowed.
+				if ( aMatchW[2] == '%' )
+					aMatchW[1] += '%';
 				widthText = aMatchW[1];
 			}
 		}
+
+		// Refresh LockRatio button
+		var btnLockSizes = CKEDITOR.document.getById( 'btnLockSizes' );
+		if ( dialog.imageLockRatio )
+			btnLockSizes.removeClass( 'BtnUnlocked' );
+		else
+			btnLockSizes.addClass( 'BtnUnlocked' );
 
 		//TODO: read styles
@@ -233,4 +323,6 @@
 			readAttribute.apply( this, [ 'advanced', 'title', 'txtGenTitle', imgObject ] );
 		}
+
+		updatePreview( this );
 
 		return false;
@@ -357,5 +449,6 @@
 			this.editObj[ 'image' ] = false;
 			this.editObj[ 'link' ] = false;
-			this.editObj[ 'imageOriginal' ] = false;		//TODO: move it to preview area
+			this.editObj[ 'imageOriginal' ] = false;
+			this.editObj[ 'imagePreview' ] = false;
 			
 			// Default: create a new element.
@@ -368,7 +461,4 @@
 			this.changedAttibutes[ 'image' ] = new Array();
 
-			this.imageDimenstions  = new Array ();
-			this.imageDimenstions['width'] = 0;
-			this.imageDimenstions['height'] = 0;
 			this.imageLockRatio = true;
 
@@ -383,6 +473,9 @@
 			this.editObj[ 'imageOriginal' ] = editor.document.createElement( 'img' );
 			this.editObj[ 'imageOriginal' ].setCustomData( 'isReady', 'false' );
-			
-			
+
+			// Preview
+			this.editObj[ 'imagePreview' ] = CKEDITOR.document.getById( 'previewImage' );
+			this.editObj[ 'linkPreview' ] = CKEDITOR.document.getById( 'previewLink' );
+
 			// Check selection. Fill in all the relevant fields if there's already one link selected.
 			if ( ranges.length == 1 )
@@ -428,7 +521,53 @@
 			if ( editor.config.imageUpload == false )
 				this.hidePage( 'Upload' );		//Hide Upload tab.
+
+			// Activate Reset button
+			var resetButton= CKEDITOR.document.getById( 'btnResetSize' );
+			if ( resetButton )
+			{
+				resetButton.on( 'click', function()
+					{
+						resetSize( this );
+					}, this );
+				resetButton.on( 'mouseover', function()
+					{
+						this.addClass( 'BtnOver' );
+					}, resetButton );
+				resetButton.on( 'mouseout', function()
+					{
+						this.removeClass( 'BtnOver' );
+					}, resetButton );
+			}
+			
+			// Activate (Un)LockRatio button
+			var ratioButton= CKEDITOR.document.getById( 'btnLockSizes' );
+			if ( ratioButton )
+			{
+				ratioButton.on( 'click', function()
+					{
+						var btnLockSizes = CKEDITOR.document.getById( 'btnLockSizes' );
+						if ( switchLockRatio( this ) )
+							btnLockSizes.removeClass( 'BtnUnlocked' );
+						else
+							btnLockSizes.addClass( 'BtnUnlocked' );
+					}, this );
+				ratioButton.on( 'mouseover', function()
+					{
+						this.addClass( 'BtnOver' );
+					}, ratioButton );
+				ratioButton.on( 'mouseout', function()
+					{
+						this.removeClass( 'BtnOver' );
+					}, ratioButton );
+			}
 		},	
 		onHide : function()
 		{
+			if ( this.editObj[ 'imagePreview' ] )
+				this.editObj[ 'imagePreview' ].setAttribute( 'src', '' );
+		
+			this.editObj[ 'imagePreview' ] = false;
+			this.editObj[ 'imageOriginal' ].remove();
+			
 			// Don't call onChange before onShow.
 			this.allowOnChange = false;
@@ -529,6 +668,8 @@
 														validate: function()
 														{
-															var func = CKEDITOR.dialog.validate.integer( editor.lang.dlgImgTypeNumber );
-															var isValid = func.apply( this );
+															// TODO Check content -  integer or percent.
+															//var func = CKEDITOR.dialog.validate.integer( editor.lang.dlgImgTypeNumber );
+															//var isValid = func.apply( this );
+															isValid = true;
 															if ( isValid )
 																addChange( 'width', this, 'image' );
@@ -547,6 +688,8 @@
 														validate: function()
 														{
-															var func = CKEDITOR.dialog.validate.integer( editor.lang.dlgImgTypeNumber );
-															var isValid = func.apply( this );
+															// TODO Check content -  integer or percent.
+															//var func = CKEDITOR.dialog.validate.integer( editor.lang.dlgImgTypeNumber );
+															//var isValid = func.apply( this );
+															isValid = true;
 															if ( isValid )
 																addChange( 'height', this, 'image' );
@@ -560,6 +703,8 @@
 												style : 'position:relative;top:-10px;height:20px',	
 												html : '<div>'+
-													'<div onclick="" title="' + editor.lang.dlgImgLockRatio + '" onmouseout="this.className = (true ? \'BtnLocked\' : \'BtnUnlocked\' );" '+ 'onmouseover="this.className = (true ? \'BtnLocked\' : \'BtnUnlocked\' ) + \' BtnOver\';" class="BtnLocked" id="btnLockSizes"></div>' +
-													'<div onclick="" title="' + editor.lang.dlgBtnResetSize + '" onmouseout="this.className=\'BtnReset\';" onmouseover="this.className=\'BtnReset BtnOver\';" class="BtnReset" id="btnResetSize"></div>'+
+													'<div onclick="" title="' + editor.lang.dlgImgLockRatio + 
+													'" class="BtnLocked" id="btnLockSizes"></div>' +
+													'<div onclick="" title="' + editor.lang.dlgBtnResetSize + 
+													'" class="BtnReset" id="btnResetSize"></div>'+
 													'</div>'
 											}
@@ -576,4 +721,8 @@
 												labelLayout : 'horizontal',
 												label : editor.lang.dlgImgBorder,
+												onChange : function()
+												{
+													onChange( this, 'border' );
+												},
 												validate: function()
 												{
@@ -590,4 +739,8 @@
 												labelLayout : 'horizontal',
 												label : editor.lang.dlgImgHSpace,
+												onChange : function()
+												{
+													onChange( this, 'hspace' );
+												},
 												validate: function()
 												{
@@ -604,4 +757,8 @@
 												labelLayout : 'horizontal',
 												label : editor.lang.dlgImgVSpace,
+												onChange : function()
+												{
+													onChange( this, 'vspace' );
+												},
 												validate: function()
 												{
@@ -633,4 +790,8 @@
 													[ editor.lang.dlgImgAlignTop , 'top']
 												],
+												onChange : function()
+												{
+													onChange( this, 'align' );
+												},
 												validate: function()
 												{
@@ -651,7 +812,5 @@
 										type : 'html',
 										style : 'width:95%;',
-										html: '<div>' + CKEDITOR.tools.htmlEncode( editor.lang.dlgImgPreview ) +
-											'<div id="ImagePreviewBox" style="border: 1px solid black;height:160px"></div>'+
-											'</div>'
+										html : previewAreaHtml
 									}
 								]
Index: /CKEditor/branches/prototype/_source/skins/default/dialog.css
===================================================================
--- /CKEditor/branches/prototype/_source/skins/default/dialog.css	(revision 2812)
+++ /CKEditor/branches/prototype/_source/skins/default/dialog.css	(revision 2813)
@@ -648,4 +648,39 @@
 }
 
+.cke_skin_default .cke_dialog  #ImagePreviewBox
+{
+	white-space : normal;
+	border : 2px ridge black; 
+	overflow : scroll;
+	height : 160px; 
+	width : 230px;
+	padding : 2px;
+	background-color : white;
+}
+.cke_skin_default .cke_dialog  #ImagePreviewLoader
+{
+	position: absolute;
+	white-space : normal;
+	overflow : hidden;
+	height : 160px; 
+	width : 230px;
+	margin : 2px;
+	padding : 2px;
+	opacity : 0.9;
+	filter : alpha(opacity=90);
+
+	background-color : #e4e4e4;
+}
+
+.cke_skin_default .cke_dialog .loading
+{
+	height : 160px;
+	width : 230px;
+	background-image: url(images/dialog.loading30.gif);
+	background-repeat: no-repeat;
+	background-position: 47% 47%;
+
+}
+
 .cke_skin_default .cke_dialog .DarkBackground
 {
