 
 # requires the image mixin
 module.exports =
-
-  sizes: [
-    ['small', { width: 200, height: 200}]
-    ['tall', { width: 260, height: 800}]
-    ['medium', { width: Infinity, height: 260}]
-    ['large', { width: 640, height: 640}]
-    ['larger', { width: 1024, height: 1024}]
-  ]
+  sizes:
+    small: width: 200, height: 200
+    tall: width: 260, height: 800
+    medium: width: Infinity, height: 260
+    large: width: 640, height: 640
+    larger: width: 1024, height: 1024
 
   publicVersions: ->
     _.without(@get('image_versions'), 'normalized')
 
   # Given a desired width and height, return the image url that won't pixelate
   imageUrlFor: (width, height) ->
-    size = @imageSizeForDimensions width, height
-    if size
+    if size = @imageSizeForDimensions width, height
       return @imageUrl size
     @imageUrlForMaxSize()
 
   imageSizeForDimensions: (width, height) ->
-    for size in @sizes
-      if width <= size[1].width && height <= size[1].height
-        return size[0] if _.indexOf(@get('image_versions'), size[0]) >= 0
+    for key, size of @sizes
+      if width <= size.width and height <= size.height
+        return key if _.contains @get('image_versions'), key
 
   imageSizeForHeight: (height) ->
     @imageSizeForDimensions height * @aspectRatio(), height

      return @imageUrl(size) if _.contains(sizes, size)
    null

  resizeDimensionsFor: ({ width, height }) ->
    ratios = _.compact _.map { width: width, height: height }, (value, dimension) =>
      value / @get("original_#{dimension}") if value


  maxHeightForWidth: (width, maxDimension) ->
    aspectRatio = @aspectRatio()
    maxDimension = maxDimension or @get 'original_height'
    if aspectRatio?
      height = Math.round width / @aspectRatio()
      if height > maxDimension then maxDimension else Math.floor(height)
