Index: /CKEditor/trunk/_source/plugins/styles/plugin.js
===================================================================
--- /CKEditor/trunk/_source/plugins/styles/plugin.js	(revision 3377)
+++ /CKEditor/trunk/_source/plugins/styles/plugin.js	(revision 3378)
@@ -183,29 +183,35 @@
 				attribs;
 
-			// If no attributes are defined in the element.
-			if ( !fullMatch && !element.hasAttributes() )
-				return true;
-
-			attribs = getAttributesForComparison( def );
-
-			if ( attribs._length )
-			{
-				for ( var attName in attribs )
-				{
-					if ( attName == '_length' )
-						continue;
-
-					if ( compareAttributeValues( attName, attribs[ attName ], element.getAttribute( attName ) ) )
+			// If the element name is the same as the style name.
+			if ( element.getName() == this.element ) 
+			{
+				// If no attributes are defined in the element.
+				if ( !fullMatch && !element.hasAttributes() ) 
+					return true;
+				
+				attribs = getAttributesForComparison( def );
+				
+				if ( attribs._length ) 
+				{
+					for ( var attName in attribs ) 
 					{
-						if ( !fullMatch )
-							return true;
+						if ( attName == '_length' ) 
+							continue;
+						
+						if ( compareAttributeValues(attName, attribs[attName], element.getAttribute( attName ) ) ) 
+						{
+							if ( !fullMatch ) 
+								return true;
+						}
+						else if ( fullMatch ) 
+								return false;
 					}
-					else if ( fullMatch )
-						return false;
-				}
-			}
-	
+				}
+				else
+					return true;
+			}
+
 			// Check if the element can be somehow overriden.
-			var override = this.getOverrides()[ element.getName() ] ;
+			var override = getOverrides( this )[ element.getName() ] ;
 			if ( override )
 			{
@@ -214,5 +220,5 @@
 					return true;
 	
-				for ( var i = 0; i < attribs.length; i++ )
+				for ( var i = 0 ; i < attribs.length ; i++ )
 				{
 					var attName = attribs[i][0], actualAttrValue;
@@ -234,70 +240,6 @@
 				}
 			}
-			
-		},
-
-		/**
-		 * Get the the collection used to compare the elements and attributes,
-		 * defined in this style overrides, with other element. All information in
-		 * it is lowercased.
-		 */
-		getOverrides: function()
-		{
-			var overrides = {}, 
-				definition = this._.definition.overrides;
-	
-			if ( definition )
-			{
-				// The override description can be a string, object or array.
-				// Internally, well handle arrays only, so transform it if needed.
-				if ( !CKEDITOR.tools.isArray( definition ) )
-					definition = [ definition ];
-	
-				// Loop through all override definitions.
-				for ( var i = 0; i < definition.length; i++ )
-				{
-					var override = definition[i];
-					var elementName;
-					var overrideEl;
-					var attrs;
-	
-					// If can be a string with the element name.
-					if ( typeof override == 'string' )
-						elementName = override.toLowerCase();
-					// Or an object.
-					else
-					{
-						elementName = override.element ? override.element.toLowerCase() : this.element;
-						attrs = override.attributes;
-					}
-	
-					// We can have more than one override definition for the same
-					// element name, so we attempt to simply append information to
-					// it if it already exists.
-					overrideEl = overrides[ elementName ] || ( overrides[ elementName ] = {} );
-	
-					if ( attrs )
-					{
-						// The returning attributes list is an array, because we
-						// could have different override definitions for the same
-						// attribute name.
-						var overrideAttrs = ( overrideEl.attributes = overrideEl.attributes || new Array() );
-						for ( var attName in attrs )
-						{
-							// Each item in the attributes array is also an array,
-							// where [0] is the attribute name and [1] is the
-							// override value.
-							overrideAttrs.push( [ attName.toLowerCase(), attrs[ attName ] ] );
-						}
-					}
-				}
-			}
-			
-			// Cache the overrides resolution.
-			return ( this.getOverrides = function(){
-				return overrides;
-			} )();
-		}
-		
+			return false;
+		}
 	};
 
@@ -576,5 +518,5 @@
 			 */
 			var startPath = new CKEDITOR.dom.elementPath( startNode.getParent() );
-			for ( var i = 0, element; i < startPath.elements.length && ( element = startPath.elements[i] ) ; i++ )
+			for ( var i = 0, element ; i < startPath.elements.length && ( element = startPath.elements[i] ) ; i++ )
 			{
 				if ( element == startPath.block || element == startPath.blockLimit )
@@ -613,5 +555,5 @@
 					breakStart = null,
 					breakEnd = null;
-				for ( var i = 0; i < startPath.elements.length; i++ )
+				for ( var i = 0 ; i < startPath.elements.length ; i++ )
 				{
 					var element = startPath.elements[ i ];
@@ -623,5 +565,5 @@
 						breakStart = element;
 				}
-				for ( i = 0; i < endPath.elements.length; i++ )
+				for ( i = 0 ; i < endPath.elements.length ; i++ )
 				{
 					element = endPath.elements[ i ];
@@ -656,5 +598,5 @@
 						removeFromElement( this, currentNode );
 					else	
-						removeOverrides( currentNode, this.getOverrides()[ currentNode.getName() ] );
+						removeOverrides( currentNode, getOverrides( this )[ currentNode.getName() ] );
 
 					/*
@@ -717,9 +659,9 @@
 //			{
 //				if ( previousPreBlock )
-//					this._CheckAndMergePre( previousPreBlock, newBlock );	// Merge successive <pre> blocks.
+//					this._CheckAndMergePre( previousPreBlock, newBlock ) ;	// Merge successive <pre> blocks.
 //				previousPreBlock = newBlock;
 //			}
 //			else if ( fromPre )
-//				this._CheckAndSplitPre( newBlock );	// Split <br><br> in successive <pre>s.
+//				this._CheckAndSplitPre( newBlock ) ;	// Split <br><br> in successive <pre>s.
 		}
 
@@ -733,22 +675,9 @@
 			attributes = def.attributes,
 			styles = def.styles,
-			overrides = style.getOverrides();
-		
-		for ( var attName in attributes )
-		{
-			// The 'class' element value must match (#1318).
-			if ( attName == 'class' && element.getAttribute( attName ) != attributes[ attName ] )
-				continue;
-			element.removeAttribute( attName );
-		}
-
-		for ( var styleName in styles )
-			element.removeStyle( styleName );
-
-		// Now scan override styles on the element.
-		attributes = overrides[ element.getName() ];
-		if( attributes )
-		{
-			for( attName in attributes )
+			overrides = getOverrides( style );
+
+		function removeAttrs()
+		{
+			for ( var attName in attributes )
 			{
 				// The 'class' element value must match (#1318).
@@ -758,4 +687,14 @@
 			}
 		}
+		
+		// Remove definition attributes/style from the elemnt.		
+		removeAttrs();
+		for ( var styleName in styles )
+			element.removeStyle( styleName );
+
+		// Now remove override styles on the element.
+		attributes = overrides[ element.getName() ];
+		if( attributes )
+			removeAttrs();
 		removeNoAttribsElement( element );
 	}
@@ -767,9 +706,9 @@
 			attribs = def.attributes,
 			styles = def.styles,
-			overrides = style.getOverrides();
+			overrides = getOverrides( style );
 
 		var innerElements = element.getElementsByTag( style.element );
 
-		for ( var i = innerElements.count(); --i >= 0; )
+		for ( var i = innerElements.count(); --i >= 0 ; )
 			removeFromElement( style,  innerElements.getItem( i ) );
 
@@ -781,5 +720,5 @@
 			{
 				var innerElements = element.getElementsByTag( overrideElement ) ;
-				for ( var i = innerElements.count() - 1; i >= 0 ; i-- )
+				for ( var i = innerElements.count() - 1 ; i >= 0 ; i-- )
 				{
 					var innerElement = innerElements.getItem( i );
@@ -985,4 +924,68 @@
 		return ( styleDefinition._AC = attribs );
 	}
+
+	/**
+	 * Get the the collection used to compare the elements and attributes,
+	 * defined in this style overrides, with other element. All information in
+	 * it is lowercased.
+	 * @param {CKEDITOR.style} style
+	 */
+	function getOverrides( style )
+	{
+		if( style._.overrides )
+			return style._.overrides;
+
+		var overrides = ( style._.overrides = {} ), 
+			definition = style._.definition.overrides;
+		
+		if ( definition )
+		{
+			// The override description can be a string, object or array.
+			// Internally, well handle arrays only, so transform it if needed.
+			if ( !CKEDITOR.tools.isArray( definition ) )
+				definition = [ definition ];
+
+			// Loop through all override definitions.
+			for ( var i = 0 ; i < definition.length ; i++ )
+			{
+				var override = definition[i];
+				var elementName;
+				var overrideEl;
+				var attrs;
+
+				// If can be a string with the element name.
+				if ( typeof override == 'string' )
+					elementName = override.toLowerCase();
+				// Or an object.
+				else
+				{
+					elementName = override.element ? override.element.toLowerCase() : style.element;
+					attrs = override.attributes;
+				}
+
+				// We can have more than one override definition for the same
+				// element name, so we attempt to simply append information to
+				// it if it already exists.
+				overrideEl = overrides[ elementName ] || ( overrides[ elementName ] = {} );
+
+				if ( attrs )
+				{
+					// The returning attributes list is an array, because we
+					// could have different override definitions for the same
+					// attribute name.
+					var overrideAttrs = ( overrideEl.attributes = overrideEl.attributes || new Array() );
+					for ( var attName in attrs )
+					{
+						// Each item in the attributes array is also an array,
+						// where [0] is the attribute name and [1] is the
+						// override value.
+						overrideAttrs.push( [ attName.toLowerCase(), attrs[ attName ] ] );
+					}
+				}
+			}
+		}
+		
+		return overrides;
+	}
 	
 	function normalizeCssText( unparsedCssText )
@@ -1025,5 +1028,5 @@
 
 		// Apply the style to the ranges.
-		for ( var i = 0; i < ranges.length; i++ )
+		for ( var i = 0 ; i < ranges.length ; i++ )
 			func.call( this, ranges[ i ] );
 
