Index: /trunk/src/wp-includes/css/media-views.css
===================================================================
--- /trunk/src/wp-includes/css/media-views.css	(revision 27897)
+++ /trunk/src/wp-includes/css/media-views.css	(revision 27898)
@@ -271,5 +271,6 @@
 }
 
-.media-sidebar h3 {
+.media-sidebar h3,
+.image-details h3 {
 	position: relative;
 	font-weight: bold;
@@ -1604,21 +1605,32 @@
 	top: 0;
 	overflow: visible;
+	padding: 0;
 }
 
 .image-details .column-settings {
-	width: 44%;
-	float: left;
-	margin-right: 20px;
+	background: #f3f3f3;
+	border-right: 1px solid #ddd;
+	min-height: 100%;
+	width: 52%;
+	position: absolute;
+	top: 0;
+	left: 0;
+}
+
+.image-details .column-settings h3 {
+	margin: 20px;
+	padding-top: 20px;
+	border-top: 1px solid #ddd;
 }
 
 .image-details .column-image {
-	width: 53%;
-	float: left;
-}
-
-.image-details .column-image:after {
-    content: '';
-	display: table;
-    clear: both;
+	width: 48%;
+	position: absolute;
+	left: 52%;
+	top: 0;
+}
+
+.image-details .image {
+	margin: 20px;
 }
 
@@ -1628,4 +1640,27 @@
 }
 
+.image-details .advanced-toggle {
+	font-style: italic;
+	color: #666;
+	text-decoration: none;
+	margin: 20px;
+	display: block;
+}
+
+.image-details .advanced-toggle::after {
+	font: normal 20px/1 'dashicons';
+	speak: none;
+	vertical-align: top;
+	-webkit-font-smoothing: antialiased;
+	-moz-osx-font-smoothing: grayscale;
+	content: '\f140';
+	display: inline-block;
+	margin-top: -2px;
+}
+
+.image-details .advanced-visible .advanced-toggle::after {
+	content: '\f142';
+	margin-top: 0;
+}
 
 .media-embed .thumbnail {
@@ -1662,10 +1697,15 @@
 }
 
-.image-details .setting {
+.image-details .embed-media-settings .setting {
 	float: none;
+	width: auto;
 }
 
 .image-details .actions {
 	margin: 10px 0;
+}
+
+.image-details .hidden {
+	display: none;
 }
 
@@ -1678,7 +1718,18 @@
 }
 
-.image-details .setting input[type="text"],
-.image-details .setting textarea {
+.image-details .embed-media-settings .setting input[type="text"],
+.image-details .embed-media-settings .setting textarea {
 	max-width: inherit;
+	width: 70%;
+}
+
+.image-details .embed-media-settings .setting input.link-to-custom,
+.image-details .embed-media-settings .link-target {
+	margin-left: 27%;
+	width: 70%;
+}
+
+.image-details .embed-media-settings .link-target {
+	margin-top: 24px;
 }
 
@@ -1695,4 +1746,12 @@
 }
 
+.image-details .embed-media-settings .setting span {
+	float: left;
+	width: 25%;
+	text-align: right;
+	margin: 8px 1% 0 1%;
+	line-height: 1.1;
+}
+
 .media-embed .setting .button-group {
 	margin: 2px 0;
@@ -1708,8 +1767,4 @@
 .link-settings {
 	margin-top: 10px;
-}
-
-.advanced .hidden {
-	display: none;
 }
 
@@ -1931,4 +1986,26 @@
 	}
 
+	.image-details .embed-media-settings .setting {
+		margin: 20px;
+	}
+
+	.image-details .embed-media-settings .setting span {
+		float: none;
+		text-align: left;
+		width: 100%;
+		margin-bottom: 4px;
+	}
+
+	.image-details .embed-media-settings .setting input.link-to-custom,
+	.image-details .embed-media-settings .setting input[type="text"],
+	.image-details .embed-media-settings .setting textarea {
+		width: 100%;
+		margin-left: 0;
+	}
+
+	.image-details .link-target {
+		width: 100%;
+	}
+
 	.media-selection {
 		min-width: 120px;
@@ -2138,7 +2215,11 @@
 	.image-details .column-settings,
 	.image-details .column-image {
-		float: none;
+		position: relative;
+		padding: 10px 0 20px 0;
+		left: 0;
 		width: 100%;
-	}
+		min-height: inherit;
+	}
+
 
 	/* Gallery */
Index: /trunk/src/wp-includes/js/media-views.js
===================================================================
--- /trunk/src/wp-includes/js/media-views.js	(revision 27897)
+++ /trunk/src/wp-includes/js/media-views.js	(revision 27898)
@@ -6060,13 +6060,11 @@
 			'click .edit-attachment': 'editAttachment',
 			'click .replace-attachment': 'replaceAttachment',
-			'click .show-advanced': 'showAdvanced'
+			'click .advanced-toggle': 'toggleAdvanced'
 		} ),
 		initialize: function() {
 			// used in AttachmentDisplay.prototype.updateLinkTo
 			this.options.attachment = this.model.attachment;
-			if ( this.model.attachment ) {
-				this.listenTo( this.model, 'change:url', this.updateUrl );
-				this.listenTo( this.model, 'change:link', this.toggleLinkSettings );
-			}
+			this.listenTo( this.model, 'change:url', this.updateUrl );
+			this.listenTo( this.model, 'change:link', this.toggleLinkSettings );
 			media.view.Settings.AttachmentDisplay.prototype.initialize.apply( this, arguments );
 		},
@@ -6114,6 +6112,6 @@
 
 		updateUrl: function() {
-			this.$( '.image img' ).attr( 'src', this.model.get('url' ) );
-			this.$( '.url' ).val( this.model.get('url' ) );
+			this.$( '.image img' ).attr( 'src', this.model.get( 'url' ) );
+			this.$( '.url' ).val( this.model.get( 'url' ) );
 		},
 
@@ -6126,9 +6124,14 @@
 		},
 
-		showAdvanced: function( event ) {
+		toggleAdvanced: function( event ) {
+			var $advanced = $( event.target ).closest( '.advanced' );
 			event.preventDefault();
-			$( event.target ).closest('.advanced')
-				.find( '.hidden' ).removeClass( 'hidden' );
-			$( event.target ).remove();
+			if ( $advanced.hasClass('advanced-visible') ) {
+				$advanced.removeClass('advanced-visible');
+				$advanced.find('div').addClass('hidden');
+			} else {
+				$advanced.addClass('advanced-visible');
+				$advanced.find('div').removeClass('hidden');
+			}
 		},
 
Index: /trunk/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js
===================================================================
--- /trunk/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js	(revision 27897)
+++ /trunk/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js	(revision 27898)
@@ -115,5 +115,5 @@
 
 	function extractImageData( imageNode ) {
-		var classes, metadata, captionBlock, caption, link,
+		var classes, extraClasses, metadata, captionBlock, caption, link, width, height,
 			dom = editor.dom;
 
@@ -128,4 +128,5 @@
 			alt: '',
 			align: 'none',
+			extraClasses: '',
 			link: false,
 			linkUrl: '',
@@ -133,6 +134,5 @@
 			linkTargetBlank: false,
 			linkRel: '',
-			title: '',
-			className: ''
+			title: ''
 		};
 
@@ -140,23 +140,29 @@
 		metadata.alt = dom.getAttrib( imageNode, 'alt' );
 		metadata.title = dom.getAttrib( imageNode, 'title' );
-		metadata.width = parseInt( dom.getAttrib( imageNode, 'width' ), 10 );
-		metadata.height = parseInt( dom.getAttrib( imageNode, 'height' ), 10 );
-		metadata.className = imageNode.className;
-
-		classes = metadata.className.split( ' ' );
+
+		width = dom.getAttrib( imageNode, 'width' ) || imageNode.width;
+		height = dom.getAttrib( imageNode, 'height' ) || imageNode.height;
+
+		metadata.width = parseInt( width, 10 );
+		metadata.height = parseInt( height, 10 );
+
+		classes = tinymce.explode( imageNode.className, ' ' );
+		extraClasses = [];
+
 		tinymce.each( classes, function( name ) {
 
 			if ( /^wp-image/.test( name ) ) {
 				metadata.attachment_id = parseInt( name.replace( 'wp-image-', '' ), 10 );
-			}
-
-			if ( /^align/.test( name ) ) {
+			} else if ( /^align/.test( name ) ) {
 				metadata.align = name.replace( 'align', '' );
-			}
-
-			if ( /^size/.test( name ) ) {
+			} else if ( /^size/.test( name ) ) {
 				metadata.size = name.replace( 'size-', '' );
-			}
+			} else {
+				extraClasses.push( name );
+			}
+
 		} );
+
+		metadata.extraClasses = extraClasses.join( ' ' );
 
 		// Extract caption
@@ -195,65 +201,13 @@
 
 	function updateImage( imageNode, imageData ) {
-		var className, width, node, html, captionNode, nodeToReplace, uid, editedImg, id;
-
-		if ( imageData.caption ) {
-
-			html = createImageAndLink( imageData, 'html' );
-
-			width = parseInt( imageData.width, 10 );
-
-			if ( ! editor.getParam( 'wpeditimage_html5_captions' ) ) {
-				width += 10;
-			}
-
-			className = 'align' + imageData.align;
-			id = imageData.attachment_id ? 'id="attachment_'+ imageData.attachment_id +'" ' : '';
-
-			// should create a new function for generating the caption markup
-			html =  '<dl ' + id + 'class="wp-caption '+ className +'" style="width: '+ width +'px">' +
-				'<dt class="wp-caption-dt">'+ html + '</dt><dd class="wp-caption-dd">'+ imageData.caption +'</dd></dl>';
-
-			node = editor.dom.create( 'div', { 'class': 'mceTemp' }, html );
-		} else {
-			node = createImageAndLink( imageData, 'node' );
-		}
-
-		nodeToReplace = imageNode;
-
-		captionNode = editor.dom.getParent( imageNode, '.mceTemp' );
-
-		if ( captionNode ) {
-			nodeToReplace = captionNode;
-		} else {
-			if ( imageNode.parentNode.nodeName === 'A' ) {
-				nodeToReplace = imageNode.parentNode;
-			}
-		}
-
-		uid = editor.dom.uniqueId( 'wp_' );
-		editor.dom.setAttrib( node, 'data-wp-replace-id', uid );
-		editor.dom.replace( node, nodeToReplace );
-
-		// find the updated node
-		node = editor.dom.select( '[data-wp-replace-id="' + uid + '"]' )[0];
-
-		editor.dom.setAttrib( node, 'data-wp-replace-id', '' );
-
-		editor.nodeChanged();
-
-		editedImg = node.nodeName === 'IMG' ? node : editor.dom.select( 'img', node )[0];
-
-		if ( editedImg ) {
-			editor.selection.select( editedImg );
-			// refresh toolbar
-			addToolbar( editedImg );
-		}
-	}
-
-	function createImageAndLink( imageData, mode ) {
-		var classes = [],
-			attrs, linkAttrs;
-
-		mode = mode ? mode : 'node';
+		var classes, className, width, node, html, parent, wrap,
+			captionNode, dd, dl, id, attrs, linkAttrs,
+			dom = editor.dom;
+
+		classes = tinymce.explode( imageData.extraClasses, ' ' );
+
+		if ( ! classes ) {
+			classes = [];
+		}
 
 		if ( ! imageData.caption ) {
@@ -270,43 +224,95 @@
 		attrs = {
 			src: imageData.url,
-			width: imageData.width,
-			height: imageData.height,
+			width: imageData.width || null,
+			height: imageData.height || null,
 			alt: imageData.alt,
-			title: imageData.title || null
+			title: imageData.title || null,
+			'class': classes.join( ' ' ) || null
 		};
 
-		if ( classes.length ) {
-			attrs['class'] = classes.join( ' ' );
-		}
-
-		if ( imageData.linkUrl ) {
-
-			linkAttrs = {
-				href: imageData.linkUrl
-			};
-
-			if ( imageData.linkRel ) {
-				linkAttrs.rel = imageData.linkRel;
-			}
-
-			if ( imageData.linkTargetBlank ) {
-				linkAttrs.target = '_blank';
-			}
-
-			if ( imageData.linkClassName ) {
-				linkAttrs['class'] = imageData.linkClassName;
-			}
-
-			if ( mode === 'node' ) {
-				return editor.dom.create( 'a', linkAttrs, editor.dom.createHTML( 'img', attrs ) );
-			} else if ( mode === 'html' ) {
-				return editor.dom.createHTML( 'a', linkAttrs, editor.dom.createHTML( 'img', attrs ) );
-			}
-
-		} else if ( mode === 'node' ) {
-			return editor.dom.create( 'img', attrs );
-		} else if ( mode === 'html' ) {
-			return editor.dom.createHTML( 'img', attrs );
-		}
+		dom.setAttribs( imageNode, attrs );
+
+		linkAttrs = {
+			href: imageData.linkUrl,
+			rel: imageData.linkRel || null,
+			target: imageData.linkTargetBlank ? '_blank': null,
+			'class': imageData.linkClassName || null
+		};
+
+		if ( imageNode.parentNode.nodeName === 'A' ) {
+			if ( imageData.linkUrl ) {
+				dom.setAttribs( imageNode.parentNode, linkAttrs );
+			} else {
+				dom.remove( imageNode.parentNode, true );
+			}
+		} else if ( imageData.linkUrl ) {
+			html = dom.createHTML( 'a', linkAttrs, dom.getOuterHTML( imageNode ) );
+			dom.outerHTML( imageNode, html );
+		}
+
+		captionNode = editor.dom.getParent( imageNode, '.mceTemp' );
+
+		if ( imageNode.parentNode.nodeName === 'A' ) {
+			node = imageNode.parentNode;
+		} else {
+			node = imageNode;
+		}
+
+		if ( imageData.caption ) {
+			width = parseInt( imageData.width, 10 );
+			id = imageData.attachment_id ? 'attachment_' + imageData.attachment_id : null;
+			className = 'wp-caption align' + imageData.align;
+
+			if ( ! editor.getParam( 'wpeditimage_html5_captions' ) ) {
+				width += 10;
+			}
+
+			if ( captionNode ) {
+				dl = dom.select( 'dl.wp-caption', captionNode );
+
+				if ( dl.length ) {
+					dom.setAttribs( dl, {
+						id: id,
+						'class': className,
+						style: 'width: ' + width + 'px'
+					} );
+				}
+
+				dd = dom.select( '.wp-caption-dd', captionNode );
+
+				if ( dd.length ) {
+					dom.setHTML( dd[0], imageData.caption );
+				}
+
+			} else {
+				id = id ? 'id="'+ id +'" ' : '';
+
+				// should create a new function for generating the caption markup
+				html =  '<dl ' + id + 'class="' + className +'" style="width: '+ width +'px">' +
+					'<dt class="wp-caption-dt">' + dom.getOuterHTML( node ) + '</dt><dd class="wp-caption-dd">'+ imageData.caption +'</dd></dl>';
+
+				if ( parent = dom.getParent( node, 'p' ) ) {
+					wrap = dom.create( 'div', { 'class': 'mceTemp' }, html );
+					dom.insertAfter( wrap, parent );
+					dom.remove( node );
+
+					if ( dom.isEmpty( parent ) ) {
+						dom.remove( parent );
+					}
+				} else {
+					dom.setOuterHTML( node, '<div class="mceTemp">' + html + '</div>' );
+				}
+			}
+		} else if ( captionNode ) {
+			// Remove the caption wrapper and place the image in new paragraph
+			parent = dom.create( 'p' );
+			captionNode.parentNode.insertBefore( parent, captionNode );
+			parent.appendChild( node );
+			dom.remove( captionNode );
+		}
+
+		editor.nodeChanged();
+		// refresh the toolbar
+		addToolbar( imageNode );
 	}
 
Index: /trunk/src/wp-includes/media-template.php
===================================================================
--- /trunk/src/wp-includes/media-template.php	(revision 27897)
+++ /trunk/src/wp-includes/media-template.php	(revision 27898)
@@ -642,4 +642,16 @@
 		<div class="media-embed">
 			<div class="embed-media-settings">
+				<div class="column-image">
+					<div class="image">
+						<img src="{{ data.model.url }}" draggable="false" />
+
+						<# if ( data.attachment && window.imageEdit ) { #>
+							<div class="actions">
+								<input type="button" class="edit-attachment button" value="<?php esc_attr_e( 'Edit Original' ); ?>" />
+								<input type="button" class="replace-attachment button" value="<?php esc_attr_e( 'Replace' ); ?>" />
+							</div>
+						<# } #>
+					</div>
+				</div>
 				<div class="column-settings">
 					<?php
@@ -657,14 +669,5 @@
 					</label>
 
-					<div class="setting advanced">
-						<a class="show-advanced" href="#"><?php _e('show advanced'); ?></a>
-						<div class="hidden">
-							<label class="setting title-text">
-								<span><?php _e('Title Attribute'); ?></span>
-								<input type="text" data-setting="title" value="{{ data.model.title }}" />
-							</label>
-						</div>
-					</div>
-
+					<h3><?php _e( 'Display Settings' ); ?></h3>
 					<div class="setting align">
 						<span><?php _e('Align'); ?></span>
@@ -686,84 +689,83 @@
 
 					<# if ( data.attachment ) { #>
-						<div class="setting size">
-							<span><?php _e('Size'); ?></span>
-							<div class="button-group button-large" data-setting="size">
-							<?php
-								/** This filter is documented in wp-admin/includes/media.php */
-								$sizes = apply_filters( 'image_size_names_choose', array(
-									'thumbnail' => __('Thumbnail'),
-									'medium'    => __('Medium'),
-									'large'     => __('Large'),
-									'full'      => __('Full Size'),
-								) );
-
-								foreach ( $sizes as $value => $name ) : ?>
-									<# var size = data.attachment.sizes['<?php echo esc_js( $value ); ?>'];
-									if ( size ) { #>
-										<button class="button" value="<?php echo esc_attr( $value ); ?>">
-											<?php echo esc_html( $name ); ?>
-											</button>
-									<# } #>
-								<?php endforeach; ?>
-							</div>
-						</div>
+						<# if ( 'undefined' !== typeof data.attachment.sizes ) { #>
+							<label class="setting">
+								<span><?php _e('Size'); ?></span>
+								<select class="size" name="size"
+									data-setting="size"
+									<# if ( data.userSettings ) { #>
+										data-user-setting="imgsize"
+									<# } #>>
+									<?php
+									/** This filter is documented in wp-admin/includes/media.php */
+									$sizes = apply_filters( 'image_size_names_choose', array(
+										'thumbnail' => __('Thumbnail'),
+										'medium'    => __('Medium'),
+										'large'     => __('Large'),
+										'full'      => __('Full Size'),
+									) );
+
+									foreach ( $sizes as $value => $name ) : ?>
+										<#
+										var size = data.sizes['<?php echo esc_js( $value ); ?>'];
+										if ( size ) { #>
+											<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $value, 'full' ); ?>>
+												<?php echo esc_html( $name ); ?> &ndash; {{ size.width }} &times; {{ size.height }}
+											</option>
+										<# } #>
+									<?php endforeach; ?>
+								</select>
+							</label>
+						<# } #>
 					<# } #>
 
 					<div class="setting link-to">
 						<span><?php _e('Link To'); ?></span>
-						<div class="button-group button-large" data-setting="link">
+						<select data-setting="link">
 						<# if ( data.attachment ) { #>
-							<button class="button" value="file">
+							<option value="file">
 								<?php esc_attr_e('Media File'); ?>
-							</button>
-							<button class="button" value="post">
+							</option>
+							<option value="post">
 								<?php esc_attr_e('Attachment Page'); ?>
-							</button>
+							</option>
 						<# } else { #>
-							<button class="button" value="file">
+							<option value="file">
 								<?php esc_attr_e('Image URL'); ?>
-							</button>
+							</option>
 						<# } #>
-							<button class="button" value="custom">
+							<option value="custom">
 								<?php esc_attr_e('Custom URL'); ?>
-							</button>
-							<button class="button active" value="none">
+							</option>
+							<option value="none">
 								<?php esc_attr_e('None'); ?>
-							</button>
-						</div>
+							</option>
+						</select>
 						<input type="text" class="link-to-custom" data-setting="linkUrl" />
 					</div>
-
-
-					<div class="setting link-settings">
-						<div class="setting link-target">
-							<label><input type="checkbox" data-setting="linkTargetBlank" value="_blank" <# if ( data.model.linkTargetBlank ) { #>checked="checked"<# } #>><?php _e( 'Open link in a new window/tab' ); ?></label>
-						</div>
-						<div class="advanced">
-							<a class="show-advanced" href="#"><?php _e('show advanced'); ?></a>
-							<div class="hidden">
-								<label class="setting link-rel">
-									<span><?php _e('Link Rel'); ?></span>
-									<input type="text" data-setting="linkRel" value="{{ data.model.linkClassName }}" />
-								</label>
-								<label class="setting link-class-name">
-									<span><?php _e('CSS Class'); ?></span>
-									<input type="text" data-setting="linkClassName" value="{{ data.model.linkClassName }}" />
-								</label>
+					<div class="advanced">
+						<a class="advanced-toggle" href="#"><?php _e('Show advanced options'); ?></a>
+						<div class="hidden">
+							<label class="setting title-text">
+								<span><?php _e('Image Title Attribute'); ?></span>
+								<input type="text" data-setting="title" value="{{ data.model.title }}" />
+							</label>
+							<label class="setting extra-classes">
+								<span><?php _e('Image CSS Class'); ?></span>
+								<input type="text" data-setting="extraClasses" value="{{ data.model.extraClasses }}" />
+							</label>
+							<div class="setting link-target">
+								<label><input type="checkbox" data-setting="linkTargetBlank" value="_blank" <# if ( data.model.linkTargetBlank ) { #>checked="checked"<# } #>><?php _e( 'Open link in a new window/tab' ); ?></label>
 							</div>
+							<label class="setting link-rel">
+								<span><?php _e('Link Rel'); ?></span>
+								<input type="text" data-setting="linkRel" value="{{ data.model.linkClassName }}" />
+							</label>
+							<label class="setting link-class-name">
+								<span><?php _e('Link CSS Class'); ?></span>
+								<input type="text" data-setting="linkClassName" value="{{ data.model.linkClassName }}" />
+							</label>
 						</div>
 					</div>
-
-				</div>
-				<div class="column-image">
-					<div class="image">
-						<img src="{{ data.model.url }}" draggable="false" />
-					</div>
-					<# if ( data.attachment && window.imageEdit ) { #>
-						<div class="actions">
-							<input type="button" class="edit-attachment button" value="<?php esc_attr_e( 'Edit Original' ); ?>" />
-							<input type="button" class="replace-attachment button" value="<?php esc_attr_e( 'Replace' ); ?>" />
-						</div>
-					<# } #>
 				</div>
 			</div>
