     static let keyGaps: CGFloat = 6
     static let keyGapsSmall: CGFloat = 5
     static let keyGapsSmallThreshhold: CGFloat = 10
+    
+    static func sideEdgesPortrait(width: CGFloat) -> CGFloat { return self.findThreshhold(self.sideEdgesPortraitArray, threshholds: self.sideEdgesPortraitWidthThreshholds, measurement: width) }
+    static func topEdgePortrait(width: CGFloat) -> CGFloat { return self.findThreshhold(self.topEdgePortraitArray, threshholds: self.topEdgePortraitWidthThreshholds, measurement: width) }
+    
+    static func findThreshhold(elements: [CGFloat], threshholds: [CGFloat], measurement: CGFloat) -> CGFloat {
+        assert(elements.count == threshholds.count + 1, "elements and threshholds do not match")
+        for (i, threshhold) in enumerate(reverse(threshholds)) {
+            if measurement >= threshhold {
+                let actualIndex = threshholds.count - i
+                return elements[actualIndex]
+            }
+        }
+        return elements[0]
+    }
 }
-
-
-
 
 let globalLayout: [String:Double] = [
     "leftGap": 3,

            }()
            
            // measurement
            let sideEdges = layoutConstants.sideEdges

            // measurement
            let topEdge: CGFloat = ((isLandscape ? layoutConstants.topEdgeLandscape : layoutConstants.topEdgePortrait) + self.topBanner)
            
            // measurement
            let rowGaps: CGFloat = (isLandscape ? layoutConstants.rowGapsLandscape : layoutConstants.rowGapsPortrait)

// TODO: create class from layout dictionary?

struct layoutConstants {
    static let landscapeRatio: CGFloat = 2
    
    static let sideEdgesPortraitArray: [CGFloat] = [3, 4]
    static let sideEdgesPortraitWidthThreshholds: [CGFloat] = [700]
    static let sideEdgesLandscape: CGFloat = 3
    static let topEdgePortraitArray: [CGFloat] = [12, 10, 8]
    static let topEdgePortraitWidthThreshholds: [CGFloat] = [350, 400]
    static let topEdgeLandscape: CGFloat = 6
    
    static let rowGapsPortrait: CGFloat = 15
