/**
Elastic CSS Framework JavaScript Runtime
Released under the MIT, BSD, and GPL Licenses.
More information http://www.elasticss.com
@file         'elastic.js
@author       'Fernando Trasviña (@azendal)
@collaborator 'Sergio de la Garza (@sgarza)
@collaborator 'Javier Ayala (@javi_ayala)
@copyright    '2010 Elastic CSS framework
@version      '2.1.0 RC
**/

var Elastic=function Elastic(c,a){var b,f,e,g,i,h,c=c||document;h=$(c);f=Elastic.querySelectorAll(".columns",c);if(a!==!1&&Elastic.configuration.includeContext===!0){i=[];h.hasClass("columns")&&i.push(c);e=0;for(g=f.length;e<g;e++)i.push(f[e]);f=i}g=f.length;i=Elastic.columnsIterator;for(e=0;e<g;e++)i(f[e]);for(b in Elastic.helpers)if(Elastic.helpers.hasOwnProperty(b))Elastic.helpers[b](h)};Elastic.VERSION="2.1.0 RC2";Elastic.COLUMNS_PER_ROW_EXPRESSION=/(^|\s+)on\-(\d+)(\s+|$)/;
Elastic.COLUMN_SPAN_EXPRESSION=/(^|\s+)span\-(\d+)(\s+|$)/;Elastic.FIXED_COLUMN_EXPRESSION=/(^|\s+)fixed(\s+|$)/;Elastic.ELASTIC_COLUMN_EXPRESSION=/(^|\s+)elastic(\s+|$)/;Elastic.ADAPTIVE_COLUMNS_EXPRESSION=/(^|\s+)adaptive\-(\d+)\-(\d+)(\s+|$)/;Elastic.FINAL_COLUMN_EXPRESSION=/(^|\s+)final(\s+|$)/;Elastic.DISPLAY_LAYOUT_EXPRESSION=/(^|\s+)display\s+([\w\_\-\d]+)(\s+|$)/;Elastic.configuration={refreshOnResize:!0,includeContext:!0};
Elastic.columnsIterator=function(d){var c,a,b,f,e,g,i,h,j,m,n,k;a=Elastic.querySelectorAll("> .container",d)[0]||d;b=Elastic.querySelectorAll("> .column",a);if(b.length!==0){f=b[b.length-1];e=Elastic.getColumnsPerRow(d,b);a=Elastic.getInnerWidth(a);g=Elastic.round(a,e);if(Elastic.ADAPTIVE_COLUMNS_EXPRESSION.test(d.className)){d=Number(RegExp.$2);c=Number(RegExp.$3);if(g[0].width>c)for(;g[0].width>c;)if(e+=1,g=Elastic.round(a,e),g[0].width<d)break;if(g[0].width<d)for(;g[0].width<d;)if(e-=1,g=Elastic.round(a,
e),g[0].width>c)break}i=[];h=[];d=n=j=0;for(c=b.length;d<c;d++){k=b[d];Elastic.FIXED_COLUMN_EXPRESSION.test(k.className)?(m=Elastic.getOuterWidth(k),k.columnWidth=m,k.isFixed=!0,n+=m):Elastic.ELASTIC_COLUMN_EXPRESSION.test(k.className)?(k.isElastic=!0,i.push(k)):k.isRegular=!0;if(Elastic.FINAL_COLUMN_EXPRESSION.test(k.className))k.isFinal=!0;m=j+k.spanWidth;m>=e||k===f||k.isFinal?(h.push(k),Elastic.processRow(h,a,n,i,g),j=n=0,i=[],h=[]):(h.push(k),j+=k.spanWidth)}return this}};
Elastic.getColumnsPerRow=function(d,c){var a,b,f,e;f=c.length;e=!1;Elastic.COLUMNS_PER_ROW_EXPRESSION.test(d.className)&&(f=Number(RegExp.$2),e=!0);a=0;for(b=c.length;a<b;a++)Elastic.COLUMN_SPAN_EXPRESSION.test(c[a].className)?(c[a].spanWidth=Number(RegExp.$2),e!==!0&&(f+=c[a].spanWidth-1)):c[a].spanWidth=1;return f};
Elastic.processRow=function(d,c,a,b,f){var e,g,i,h,j,m,n,k;if(!(a>=c)){i=g=0;h=d[d.length-1];h.className.indexOf("elastic-row-last")==-1&&(h.className+=" elastic-row-last");j=0;for(n=d.length;j<n;j++)if(e=d[j],e.isRegular)if(e.spanWidth>=f.length)e.style.width=c+"px";else{for(m=i;m<i+e.spanWidth;m++)g+=f[m].width;a+=g;i+=e.spanWidth;e.style.width=g+"px";g=0}if(b.length>0){k=0;d=Elastic.round(c-a,b.length);j=0;for(n=b.length;j<n;j++)k+=d[j].width,b[j].style.width=d[j].width+"px"}if(h.isFinal)h.style.marginRight=
c-a-(k||0)+"px"}};Elastic.round=function(d,c){var a,b,f,e,g,i,h,j,m;a=Elastic.round.cache;if(a[d]&&a[d][c])return a[d][c];e=[];g=Math.round(d*(100/c/100));f=g*c;for(b=0;b<c;b++)e.push({width:g});i=d-f;h=c/(Math.abs(i)+1);j=i>0;m=-1;if(i!==0)for(b=1;b<=Math.abs(i);b++)f=m==-1?e[e.length-Math.floor(h*Math.round(b/2))]:e[Math.floor(h*Math.round(b/2))-1],f.width=j?g+1:g-1,m*=-1;a[d]||(a[d]={});return a[d][c]=e};Elastic.round.cache={};
Elastic.helpers={"full-width":function(d,c){var a,b,f,e;f=d.find(".full-width");if(c!==!1&&Elastic.configuration.includeContext===!0){b=[];d.hasClass("full-width")&&b.push(d[0]);a=0;for(l=f.length;a<l;a++)b.push(f[a]);f=b}e=f.length;for(a=0;a<e;a++)b=$(f[a]),b.width(b.parent().width()-(b.outerWidth(!0)-b.width()));return this},"same-height":function(d,c){var a,b,f,e,g,i,h,j;h=d.find(".same-height");if(c!==!1&&Elastic.configuration.includeContext===!0){b=[];d.hasClass("same-height")&&b.push(d[0]);
a=0;for(l=h.length;a<l;a++)b.push(h[a]);h=b}j=h.length;for(a=0;a<j;a++){g=$(h[a]).find("> *");i=g.length;for(b=e=0;b<i;b++)f=$(g[b]).outerHeight(!0),e=e>f?e:f;for(b=0;b<i;b++)$(g[b]).css("height",e)}return this},"same-row-height":function(d,c){var a,b,f,e,g,i,h,j;h=d.find(".same-row-height");if(c!==!1&&Elastic.configuration.includeContext===!0){b=[];d.hasClass("same-row-height")&&b.push(d[0]);a=0;for(l=h.length;a<l;a++)b.push(h[a]);h=b}j=h.length;for(a=0;a<j;a++){g=$(h[a]).find("> *");i=g.length;
e=0;var m=[];for(b=0;b<i;b++)if(f=$(g[b]).outerHeight(!0),e=e>f?e:f,m.push(g[b]),$(g[b]).hasClass("elastic-row-last")){for(f=0;f<m.length;f++)$(m[f]).css("height",e);e=0;m=[]}}return this},"same-min-height":function(d,c){var a,b,f,e,g,i,h,j;h=d.find(".same-min-height");if(c!==!1&&Elastic.configuration.includeContext===!0){b=[];d.hasClass("same-min-height")&&b.push(d[0]);a=0;for(l=h.length;a<l;a++)b.push(h[a]);h=b}j=h.length;for(a=0;a<j;a++){g=$(h[a]).find("> *");i=g.length;for(b=e=0;b<i;b++)f=$(g[b]).outerHeight(!0),
e=e>f?e:f;for(b=0;b<i;b++)$(g[b]).css("min-height",e)}return this},"full-height":function(d,c){var a,b,f,e,g;e=d.find(".full-height");if(c!==!1&&Elastic.configuration.includeContext===!0){b=[];d.hasClass("full-height")&&b.push(d[0]);a=0;for(l=e.length;a<l;a++)b.push(e[a]);e=b}g=e.length;for(a=0;a<g;a++)b=$(e[a]),f=b.parent().height()-(b.outerHeight(!0)-b.height()),f<0||isNaN(Number(f))||b.css("height",f);return this},"full-min-height":function(d,c){var a,b,f,e,g;e=d.find(".full-min-height");if(c!==
!1&&Elastic.configuration.includeContext===!0){b=[];d.hasClass("full-min-height")&&b.push(d[0]);a=0;for(l=e.length;a<l;a++)b.push(e[a]);e=b}g=e.length;for(a=0;a<g;a++)b=$(e[a]),f=b.parent().height()-(b.outerHeight(!0)-b.height()),f<0||isNaN(Number(f))||b.css("min-height",f);return this},"elastic-height":function(d,c){var a,b,f,e,g,i,h;f=d.find(".elastic-height");if(c!==!1&&Elastic.configuration.includeContext===!0){b=[];d.hasClass("elastic-height")&&b.push(d[0]);a=0;for(l=f.length;a<l;a++)b.push(f[a]);
f=b}h=f.length;for(a=0;a<h;a++){$element=$(f[a]);e=$element.parent().find("> *:not(.elastic-height)");g=e.length;for(b=i=0;b<g;b++)i+=$(e[b]).outerHeight(!0);i<0||isNaN(Number(i))||$element.css("height",$element.parent().height()-i)}return this},center:function(d,c){var a,b,f,e,g;b=d.find(".vertical-center, .center");if(c!==!1&&Elastic.configuration.includeContext===!0){f=[];(d.hasClass("vertical-center")||d.hasClass("center"))&&f.push(d[0]);a=0;for(l=b.length;a<l;a++)f.push(b[a]);b=f}f=b.length;
for(a=0;a<f;a++)e=$(b[a]),g=$(b[a]).parent(),e=Math.round((g.height()-e.outerHeight(!0))/2),e<0||isNaN(Number(e))||g.css({paddingTop:e+"px",height:g.css("height")?g.outerHeight()-e:""});return this},bottom:function(d,c){var a,b,f,e,g;b=d.find(".bottom");if(c!==!1&&Elastic.configuration.includeContext===!0){f=[];d.hasClass("bottom")&&f.push(d[0]);a=0;for(l=b.length;a<l;a++)f.push(b[a]);b=f}f=b.length;for(a=0;a<f;a++)e=$(b[a]),g=$(b[a]).parent(),e=Math.round(g.height()-e.outerHeight(!0)),e<0||isNaN(Number(e))||
g.css({paddingTop:e+"px",height:g.css("height")?g.outerHeight()-e:""});return this}};Elastic.$window=$(window);Elastic.$documentElement=$(document);
Elastic.reset=function(d,c){var a,b,f,e,g,i,h,j;j=Elastic.$documentElement;$context=$(d||document);j.trigger("elastic:beforeReset");e=$context.find(".same-height > *, same-row-height > *, .full-height, .elastic-height");i=$context.find(".same-min-height > *, .full-min-height");f=$context.find(".vertical-center, .center, .bottom");b=$context.find(".column:not(.fixed), .full-width");h=$context.find(".column.final");$context.find(".same-row-height > .elastic-row-last").removeClass("elastic-row-last");
c!==!1&&Elastic.configuration.includeContext===!0&&(($context.hasClass("same-height")||$context.hasClass("same-row-height"))&&$context.find("> *").each(function(){this.style.height=""}),($context.hasClass("full-height")||$context.hasClass("elastic-height"))&&$context.css("height",""));a=0;for(g=e.length;a<g;a++)e[a].style.height="";c!==!1&&Elastic.configuration.includeContext===!0&&($context.hasClass("same-min-height")&&$context.find("> *").each(function(){this.style.minHeight=""}),$context.hasClass("full-min-height")&&
$context.css("minHeight",""));a=0;for(e=i.length;a<e;a++)i[a].style.minHeight="";if(c!==!1&&Elastic.configuration.includeContext===!0&&($context.hasClass("vertical-center")||$context.hasClass("center")||$context.hasClass("bottom")))$context.parent().css("paddingTop",""),$context.parent().css("height","");a=0;for(i=f.length;a<i;a++)f[a].parentNode.style.paddingTop="",f[a].parentNode.style.height="";c!==!1&&Elastic.configuration.includeContext===!0&&($context.hasClass("column")&&!$context.hasClass("fixed")||
$context.hasClass("full-width"))&&$context.css("width","");a=0;for(f=b.length;a<f;a++)b[a].style.width="";c!==!1&&Elastic.configuration.includeContext===!0&&$context.hasClass("column")&&$context.hasClass("final")&&($context.css("marginLeft",""),$context.css("marginRight",""));a=0;for(b=h.length;a<b;a++)h[a].style.marginLeft="",h[a].style.marginRight="";j.trigger("elastic:reset");return this};
Elastic.refresh=function(d){var c=Elastic.$documentElement;c.trigger("elastic:beforeRefresh",d);Elastic.reset(d)(d);c.trigger("elastic:refresh",d);return this};Elastic.getComputedStyle=function(d){if(d.currentStyle)return Elastic.getComputedStyle=function(c){return c.currentStyle},d.currentStyle;Elastic.getComputedStyle=function(c){return window.getComputedStyle(c,!0)};return window.getComputedStyle(d,!0)};
Elastic.getInnerWidth=function(d){var c,a;c=Elastic.getComputedStyle(d);a=parseFloat(c.width=="auto"?d.clientWidth:c.width.replace("px",""));c.width=="auto"?a=a-parseFloat(c.paddingLeft.replace("px",""))-parseFloat(c.paddingRight.replace("px",""))-parseFloat(c.borderLeftWidth.replace("px",""))-parseFloat(c.borderRightWidth.replace("px","")):c.boxSizing=="border-box"&&!c.MozBoxSizing&&!c.MsBoxSizing&&(a=a-parseFloat(c.borderLeftWidth.replace("px",""))-parseFloat(c.borderRightWidth.replace("px","")));
isNaN(a)&&(a=$(d).width());return Math.floor(a)};
Elastic.getOuterWidth=function(d){var c,a;c=Elastic.getComputedStyle(d);a=parseFloat(c.width=="auto"?d.clientWidth:c.width.replace("px",""));c.width=="auto"&&(a=a-parseFloat(c.paddingLeft.replace("px",""))-parseFloat(c.paddingRight.replace("px",""))-parseFloat(c.borderLeftWidth.replace("px",""))-parseFloat(c.borderRightWidth.replace("px","")));c=a+parseFloat(c.marginLeft.replace("px",""))+parseFloat(c.marginRight.replace("px",""));isNaN(c)&&(c=$(d).outerWidth(!0));return Math.ceil(c)};
Elastic.querySelectorAll=function(d,c){var a;document.querySelectorAll?c?d.substr(0,1)==">"?c.id?a=document.querySelectorAll("#"+c.id+d):(c.id="___elastic_temporal_id___",a=document.querySelectorAll("#"+c.id+d),c.id=""):a=c.querySelectorAll(d):a=document.querySelectorAll(d):a=c?$(c).find(d):$(d);return a};
Elastic.$documentElement.bind("elastic:beforeInitialize",function(){var d=Elastic.DISPLAY_LAYOUT_EXPRESSION;$(".display").each(function(){var c;d.test(this.className)&&(c=".position-"+RegExp.$2,$(c).removeClass(c).appendTo(this))});return null});
jQuery.fn.ready(function(){var d=Elastic.$documentElement,c=document.body.clientWidth;d.trigger("elastic:beforeInitialize");Elastic();if(c!=document.body.clientWidth)document.body.style.overflow="hidden",Elastic.refresh(),document.body.style.overflow="";jQuery(window).bind("resize",function(){Elastic.configuration.refreshOnResize&&Elastic.refresh()});d.bind("elastic",Elastic.refresh);d.trigger("elastic:initialize");return null});
