/**
 * @author Han Lin Yap < http://zencodez.net/ >
 * @copyright 2011 zencodez.net
 * @license http://creativecommons.org/licenses/by-sa/3.0/
 * @package Css3-Finalize
 * @version 1.29 - 2011-02-07
 * @website https://github.com/codler/jQuery-Css3-Finalize
 *
 * == Description == 
 * Some css3 attributes needs to have a prefix in front 
 * in order to work in different browser. The plugin takes 
 * care of that so you only need to write without the prefix.
 *
 * == Example Usage ==
 * // This will look for all style-tags and parse them.
 * $('style').cssFinalize();
 */
(function(a){if(!a.camelCase){a.camelCase=function(b){return b.replace(/-([a-z])/ig,function(c,d){return d.toUpperCase()})}}a.cssFinalizeSetup={shim:true,node:"style,link",checkMedia:true};a.fn.cssFinalize=function(b){if(!b||typeof b!="object"){b={}}b.node=this;a.cssFinalize(b);return this};a.cssFinalize=function(g){var o=document.createElement("div");if(typeof g=="string"){newoptions=arguments[1]||{};newoptions.node=g;g=newoptions}g=a.extend({},a.cssFinalizeSetup,g);var s=false;if(a.browser.webkit||a.browser.safari){s="webkit"}else{if(a.browser.mozilla){s="moz"}else{if(a.browser.msie){if(a.browser.version<=7&&!g.shim){return true}s="ms"}else{if(a.browser.opera){s="o"}}}}function e(x,y){return function(z){return(s==x)?y:false}}var h="animation animation-delay animation-direction animation-duration animation-iteration-count animation-name animation-timing-function";h+=" backface-visibility";h+=" background-clip background-origin background-size";h+=" border-corner-image border-image border-top-image border-right-image border-bottom-image border-left-image border-top-left-image border-top-right-image border-bottom-left-image border-bottom-right-image border-radius";h+=" box-align box-direction box-flex box-flex-group box-lines box-ordinal-group box-orient box-pack box-shadow box-sizing";h+=" column-count column-gap column-rule column-rule-color column-rule-style column-rule-width column-width columns";h+=" marquee marquee-direction marquee-speed marquee-style";h+=" perspective perspective-origin tab-size text-fill-color text-overflow text-size-adjust";h+=" text-stroke text-stroke-color text-stroke-width";h+=" transform transform-origin transform-style";h+=" transition transition-delay transition-duration transition-property transition-timing-function";h+=" user-modify user-select";h=h.split(" ");var l={"border-top-left-radius":[e("moz","-moz-border-radius-topleft")],"border-top-right-radius":[e("moz","-moz-border-radius-topright")],"border-bottom-right-radius":[e("moz","-moz-border-radius-bottomright")],"border-bottom-left-radius":[e("moz","-moz-border-radius-bottomleft")]};function t(x){x=x.replace(/\/\*((?:[^\*]|\*[^\/])*)\*\//g,"");x=x.replace(/\n/g,"");x=x.replace(/\r/g,"");x=x.replace(/\@import[^;]*;/g,"");return x}function v(A,z){var x=A.match(RegExp(z,"g"));var y=A.replace(new RegExp(z,"g"),"[|]").split("[|]");var B=[];for(i in y){B.push(y[i]);if(x!=null&&x[i]!=undefined){B.push(x[i])}}return B}function w(x,z){if(s=="ms"&&a.browser.version<=7){var y=a('<style class="css-finalized" />');a("head:first").append(y);y[0].styleSheet.cssText=f(z)}else{x.after('<style class="css-finalized">'+f(z)+"</style>")}}function c(y,z){z=t(z);if(a.trim(z)==""){return}var A=d(z);var x=[];a.each(A,function(B,D){if(D.attributes){var C=p(D.attributes);if(!a.isEmptyObject(C)){x.push({selector:k(D.selector),attributes:C})}else{if(k(D.selector)!=D.selector){x.push({selector:k(D.selector),attributes:D.attributes})}}}});y.addClass("css-finalize-read");if(x.length>0){w(y,x)}}function d(E){if(s=="ms"&&a.browser.version<=8){var z=v(E,"({[^{}]*})")}else{var z=E.split(/({[^{}]*})/)}if(z[z.length-1].indexOf("}")==-1){z.pop()}var A=[];var x=false;var F;var C=0;var D;var B=0;while(B<z.length){if(B%2==0){var y=a.trim(z[B]);if(x){if(y.indexOf("}")!=-1){y=y.substr(1);z[B]=y;D=z.splice(C,B-C);D.shift();D.unshift(F[1]);A[A.length-1].attributes=d(D.join(""));x=false;B=C;continue}}else{if(y.indexOf("{")!=-1){F=y.split("{");y=a.trim(F[0]);x=true;C=B}if(y!=""){A.push({selector:y})}}}else{if(!x){A[A.length-1].attributes=u(z[B].substr(1,z[B].length-2))}}B++}return A}function u(z){z=z.replace(/url\(([^)]+)\)/g,function(A){return A.replace(/;/g,"[cssFinalize]")});if(s=="ms"&&a.browser.version<=8){var y=v(z,"(:[^;]*;?)")}else{var y=z.split(/(:[^;]*;?)/)}y.pop();var x={};a.map(y,function(B,A){if(A%2==1){x[a.trim(y[A-1])]=a.trim(B.substr(1).replace(";","").replace(/url\(([^)]+)\)/g,function(C){return C.replace(/\[cssFinalize\]/g,";")}))}});return x}function f(x){var y="";a.each(x,function(z,A){y+=A.selector+"{";if(a.isArray(A.attributes)){y+=f(A.attributes)}else{a.each(A.attributes,function(C,B){y+=C+":"+B+";"})}y+="}"});return y}function p(x){if(a.isArray(x)){return{}}var y={};a.each(x,function(C,B){var z=q(C);if(z){y[z]=B}var D=m(C,B,z);if(D){y[(z)?z:C]=D}var A=r(C,B);if(A){y[A.property]=A.value}});return y}function q(y){if(y in l){for(prefix in l[y]){if(a.isFunction(l[y][prefix])){var x=l[y][prefix](y);if(x){return x}}else{if(s==l[y][prefix]||!s){return"-"+l[y][prefix]+"-"+y}}}}if(a.inArray(y,h)>-1){if(!(a.camelCase(y) in o.style)){if(a.camelCase("-"+s+"-"+y) in o.style){return"-"+s+"-"+y}}}return false}function m(B,A,x){x=x||B;if(B=="background-clip"||B=="background-origin"){o.style.cssText=x+":"+A;if(o.style[a.camelCase(x)]!==undefined&&""+o.style[a.camelCase(x)].indexOf(A)==-1){return A.split("-")[0]}}if(s=="moz"){if(A.indexOf("calc")==0){return"-moz-"+A}}if(B=="background-image"&&A.indexOf("linear-gradient")==0){if(s=="moz"){return"-moz-"+A}else{if(s=="webkit"){var y=A.replace(/^linear-gradient\s?\(\s?(.*?)\s?\)$/,"$1").split(/,\s?/);if(y.length==2){return"-webkit-gradient(linear, 0% 0%, 0% 100%, from("+y[0]+"), to("+y[1]+"));"}}else{if(s=="o"){var y=A.replace(/^linear-gradient\s?\(\s?(.*?)\s?\)$/,"$1").split(/,\s?/);if(y.length==2){var z='<svg xmlns="http://www.w3.org/2000/svg" version="1.0"><defs><linearGradient id="gradient" x1="0" y1="0" x2="0" y2="100%"><stop offset="0%" style="stop-color: '+y[0]+';"/><stop offset="100%" style="stop-color: '+y[1]+';"/></linearGradient></defs><rect x="0" y="0" fill="url(#gradient)" width="100%" height="100%" /></svg>';return"url(data:image/svg+xml,"+escape(z)+")"}}}}}return false}function r(z,y){if(g.shim){if(s=="ms"){if(a.browser.version<=8){if(z.toUpperCase()=="BACKGROUND-COLOR"&&y.indexOf("rgba")==0){y=b(y);return{property:"filter",value:"progid:DXImageTransform.Microsoft.gradient(startColorStr='"+y+"',EndColorStr='"+y+"')"}}if(z.toUpperCase()=="BACKGROUND-IMAGE"&&y.indexOf("linear-gradient")==0){var x=y.replace(/^linear-gradient\s?\(\s?(.*?)\s?\)$/,"$1").split(/,\s?/);if(x.length==2){return{property:"filter",value:"progid:DXImageTransform.Microsoft.gradient(startColorStr='"+x[0]+"',EndColorStr='"+x[1]+"')"}}}}}}return false}function k(x){if(s=="moz"){x=x.replace("::selection","::-moz-selection");x=x.replace("::placeholder",":-moz-placeholder")}else{if(s=="webkit"){x=x.replace("@keyframes","@-webkit-keyframes");x=x.replace("::placeholder","::-webkit-input-placeholder")}}return x}function b(B){var y=B.replace(/^rgba\s?\(\s?(.*?)\s?\)$/,"$1").split(/,\s?/);var x=[];var A;for(var z=0;z<y.length;z++){if(z==3){y[z]*=255}A="0"+parseInt(y[z],10).toString(16);x.push(A.substr(A.length-2,2).toUpperCase())}x.splice(0,0,x.pop());return"#"+x.join("")}if(!(g.node instanceof jQuery)){g.node=a(g.node)}g.node.each(function(x,y){var z=a(this);if(z.hasClass("css-finalize-read")||z.hasClass("css-finalized")){return true}if(this.tagName=="LINK"&&z.attr("rel")=="stylesheet"){if(!g.checkMedia||(z.attr("media").length>0&&media.matchMedium(z.attr("media")))||z.attr("media").length==0){j(this.href,z)}}else{c(z,z.html())}});function j(x,y){var D=document.location,C=D.protocol||"http:";var B=/^(\w+:)\/\/([^\/?#:]+)(?::(\d+))?/.exec(x.toLowerCase());var z=!!(B&&(B[1]!=C||B[2]!=D.hostname||(B[3]||(B[1]==="http:"?80:443))!=(D.port||(C==="http:"?80:443))));if(z){return}try{a("<div />").load(x,function(E){c(y,E)})}catch(A){}}if(a.cssHooks){for(property in l){if((newProperty=q(property))!==false){n(property,newProperty)}}for(property in h){if((newProperty=q(h[property]))!==false){n(h[property],newProperty)}}}function n(y,x){x=a.camelCase(x);if(s=="ms"&&a.browser.version<=8){x=x.charAt(0).toLowerCase()+x.substr(1)}a.cssHooks[a.camelCase(y)]={get:function(B,A,z){return B.style[x]},set:function(z,A){z.style[x]=A}}}};a(function(){if(window.cssFinalize!==false){a.cssFinalize()}})})(jQuery);if(!(window.media&&media.matchMedium)){window.media=window.media||{};media.matchMedium=(function(e,f){var b={},a=e.documentElement,d=e.createElement("body"),c=e.createElement("div");c.setAttribute("id","ejs-qtest");d.appendChild(c);return function(j){if(b[j]===f){var g=e.createElement("style");g.type="text/css";var h="@media "+j+" { #ejs-qtest { position: absolute; } }";if(g.styleSheet){g.styleSheet.cssText=h}else{g.appendChild(e.createTextNode(h))}a.insertBefore(d,a.firstChild);a.insertBefore(g,a.firstChild);b[j]=((window.getComputedStyle?window.getComputedStyle(c,null):c.currentStyle)["position"]=="absolute");a.removeChild(d);a.removeChild(g)}return b[j]}})(document)};
