
/**
 * Google Preview
 *
 * @author Ryan Chase
 * @version 1.0
 * @url http://www.blastam.com/blog/index.php/2013/03/how-to-track-downloads-in-google-analytics-v2
 */
document.addEventListener('DOMContentLoaded', function(event) {
  var filetypes = /\.(zip|exe|dmg|pdf|doc.*|xls.*|ppt.*|mp3|txt|rar|wma|mov|avi|wmv|flv|wav)$/i;

  document.querySelector('a').addEventListener('click', function(event) {
    var track = true,
      href = this.href,
      isThisDomain = href.match(document.domain.split('.').reverse()[1] + '.' + document.domain.split('.').reverse()[0]);

    if(!href.match(/^javascript:/i)) {
      var elEv = [];
      elEv.value = 0, elEv.non_i = false;
      if(href.match(/^mailto\:/i)) {
        elEv.category = "email";
        elEv.action = "click";
        elEv.label = href.replace(/^mailto\:/i, '');
        elEv.loc = href;
      } else if(href.match(filetypes)) {
        var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
        elEv.category = "download";
        elEv.action = "click-" + extension[0];
        elEv.label = href.replace(/ /g, "-");
        elEv.loc = href;
      } else if(href.match(/^https?\:/i) && !isThisDomain) {
        elEv.category = "external";
        elEv.action = "click";
        elEv.label = href.replace(/^https?\:\/\//i, '');
        elEv.non_i = true;
        elEv.loc = href;
      } else if(href.match(/^tel\:/i)) {
        elEv.category = "telephone";
        elEv.action = "click";
        elEv.label = href.replace(/^tel\:/i, '');
        elEv.loc = href;
      } else track = false;

      if(track) {
        ga('send', 'event', elEv.category.toLowerCase(), elEv.action.toLowerCase(), elEv.label.toLowerCase(), elEv.value, {'nonInteraction': elEv.non_i});
      }
    }
  });
});

/*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */
;window.matchMedia=window.matchMedia||(function(i,d){var c=i.documentElement,g=c.firstElementChild||c.firstChild,e=i.createElement("body"),a=i.createElement("div");a.id="mq-test-1";a.style.cssText="position:absolute;top:-100em";e.style.background="none";e.appendChild(a);var f=function(k){a.innerHTML='&shy;<style media="'+k+'"> #mq-test-1 { width: 42px; }</style>';c.insertBefore(e,g);bool=a.offsetWidth===42;c.removeChild(e);return{matches:bool,media:k}},h=function(){var m,k=c.body,l=false;a.style.cssText="position:absolute;font-size:1em;width:1em";if(!k){k=l=i.createElement("body");k.style.background="none"}k.appendChild(a);c.insertBefore(k,c.firstChild);if(l){c.removeChild(k)}else{k.removeChild(a)}m=j=parseFloat(a.offsetWidth);return m},j,b=f("(min-width: 0px)").matches;return function(p){if(b){return f(p)}else{var o=p.match(/\(min\-width[\s]*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||""),m=p.match(/\(max\-width[\s]*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||""),q=o===null,l=m===null,k=i.body.offsetWidth,n="em";if(!!o){o=parseFloat(o)*(o.indexOf(n)>-1?(j||h()):1)}if(!!m){m=parseFloat(m)*(m.indexOf(n)>-1?(j||h()):1)}bool=(!q||!l)&&(q||k>=o)&&(l||k<=m);return{matches:bool,media:p}}}}(document));
/*! Picturefill - Responsive Images that work today.
*  Author: Scott Jehl, Filament Group, 2012 ( new proposal implemented by Shawn Jansepar )
*  License: MIT/GPLv2 
*  Spec: http://picture.responsiveimages.org/
*/
;if(picturefillOptions===undefined){var picturefillOptions={}}(function(b,f,e,g){if(b.HTMLPictureElement){b.picturefill=function(){};return}f.createElement("picture");var a=b.picturefill||{};a.userOptions=g;a.ns="picturefill";(function(){a.srcsetSupported="srcset" in e;a.sizesSupported="sizes" in e})();a.trim=function(h){return h.trim?h.trim():h.replace(/^\s+|\s+$/g,"")};a.endsWith=function(i,h){return i.endsWith?i.endsWith(h):i.indexOf(h,i.length-h.length)!==-1};a.restrictsMixedContent=function(){return b.location.protocol==="https:"};a.matchesMedia=function(h){return b.matchMedia&&b.matchMedia(h).matches};a.getDpr=function(){return(b.devicePixelRatio||1)};a.getWidthFromLength=function(i){i=i&&i.indexOf("%")>-1===false&&(parseFloat(i)>0||i.indexOf("calc(")>-1)?i:"100vw";i=i.replace("vw","%");if(!a.lengthEl){a.lengthEl=f.createElement("div");a.lengthEl.style.cssText="border:0;display:block;font-size:1em;left:0;margin:0;padding:0;position:absolute;visibility:hidden"}a.lengthEl.style.width=i;f.body.appendChild(a.lengthEl);a.lengthEl.className="helper-from-picturefill-js";if(a.lengthEl.offsetWidth<=0){a.lengthEl.style.width=f.documentElement.offsetWidth+"px"}var h=a.lengthEl.offsetWidth;f.body.removeChild(a.lengthEl);return h};a.ascendingSort=function(i,h){return i.resolution-h.resolution};a.applyBestCandidate=function(o,j){var l,m,h,n;o.sort(a.ascendingSort);m=o.length;j.currentCandidateIndex=-1;for(var k=0;k<m;k++){l=o[k];if(!n&&l.resolution>=a.getDpr()){n=l;h=k}if(j.currentCandidateIndex<0&&a.endsWith(j.src,l.url)){j.currentCandidateIndex=k}if(n&&j.currentCandidateIndex>=0){break}}if(!n){h=m-1;n=o[m-1]}if(n&&(h>j.currentCandidateIndex||a.userOptions.disableOptimization&&h!=j.currentCandidateIndex)){if(a.restrictsMixedContent()&&n.url.substr(0,"http:".length).toLowerCase()==="http:"){if(window.console!==undefined){console.warn("Blocked mixed content image "+n.url)}}else{j.src=n.url;j.currentSrc=j.src;j.currentCandidateIndex=h;a.backfaceVisibilityFix(j);a.setInherentSize(n.resolution,j)}}};a.dodgeSrcset=function(h){if(h.srcset){h[a.ns].srcset=h.srcset;h.srcset="";h.setAttribute("data-pfsrcset",h[a.ns].srcset)}};a.parseSrcset=function(m){var k=[];while(m!==""){m=m.replace(/^\s+/g,"");var n=m.search(/\s/g),i,l=null;if(n!==-1){i=m.slice(0,n);var j=i.slice(-1);if(j===","||i===""){i=i.replace(/,+$/,"");l=""}m=m.slice(n+1);if(l===null){var h=m.indexOf(",");if(h!==-1){l=m.slice(0,h);m=m.slice(h+1)}else{l=m;m=""}}}else{i=m;m=""}if(i||l){k.push({url:i,descriptor:l})}}return k};a.parseSize=function(i){var h=/(\([^)]+\))?\s*(.+)/g.exec(i);return{media:h&&h[1],length:h&&h[2]}};a.findWidthFromSourceSize=function(p){var o=a.trim(p).split(/\s*,\s*/),q;for(var l=0,n=o.length;l<n;l++){var h=o[l],m=a.parseSize(h),k=m.length,j=m.media;if(!k){continue}if(!j||a.matchesMedia(j)){q=k;break}}return a.getWidthFromLength(q)};a.parseDescriptor=function(h,p){var s=p||"100vw",q=h&&h.replace(/(^\s+|\s+$)/g,""),k=a.findWidthFromSourceSize(s),o;if(q){var j=q.split(" ");for(var l=j.length-1;l>=0;l--){var r=j[l],m=r&&r.slice(r.length-1);if((m==="h"||m==="w")&&!a.sizesSupported){o=parseFloat((parseInt(r,10)/k))}else{if(m==="x"){var n=r&&parseFloat(r,10);o=n&&!isNaN(n)?n:1}}}}return o||1};a.getCandidatesFromSourceSet=function(o,l){var n=a.parseSrcset(o),m=[];for(var j=0,h=n.length;j<h;j++){var k=n[j];m.push({url:k.url,resolution:a.parseDescriptor(k.descriptor,l)})}return m};a.processSourceSet=function(h){var k=h.getAttribute("srcset"),i=h.getAttribute("sizes"),j=[];if(h.nodeName.toUpperCase()==="IMG"&&h[a.ns]&&h[a.ns].srcset){k=h[a.ns].srcset}if(k){j=a.getCandidatesFromSourceSet(k,i)}return j};a.getAllElements=function(){var j=[],m=f.getElementsByTagName("img");for(var k=0,i=m.length;k<i;k++){var l=m[k];if(l.parentNode.nodeName.toUpperCase()==="PICTURE"||(l.getAttribute("srcset")!==null)||l[a.ns]&&l[a.ns].srcset!==null){j.push(l)}}return j};a.detectTypeSupport=function(h,j){var i=new b.Image();i.onerror=function(){a.types[h]=false;c()};i.onload=function(){a.types[h]=i.width===1;c()};i.src=j;return"pending"};a.types=a.types||{};a.types["image/jpeg"]=true;a.types["image/gif"]=true;a.types["image/png"]=true;a.types["image/svg+xml"]=f.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image","1.1");a.types["image/webp"]=a.detectTypeSupport("image/webp","data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=");a.verifyTypeSupport=function(i){var h=i.getAttribute("type");if(h===null||h===""){return true}else{var j=a.types[h];if(typeof j==="string"&&j!=="pending"){a.types[h]=a.detectTypeSupport(h,j);return"pending"}else{if(typeof j==="function"){j();return"pending"}else{return j}}}};a.backfaceVisibilityFix=function(h){var j=h.style||{},k="webkitBackfaceVisibility" in j,i=j.zoom;if(k){j.zoom=".999";k=h.offsetWidth;j.zoom=i}};a.setInherentSize=function(j,i,h){var k=h!==undefined?h:i.complete,m=!k&&i.getAttribute&&i.getAttribute("width")!==null,l=function(p,o){if(o.setAttribute){o.setAttribute("width",o.naturalWidth/p)}},n;if(k&&j&&!m){l(j,i)}if(!k){n=setTimeout(function(){a.setInherentSize(j,i,i.complete)},250)}};a.removeVideoShim=function(k){var i=k.getElementsByTagName("video");if(i.length){var j=i[0],h=j.getElementsByTagName("source");while(h.length){k.insertBefore(h[0],j)}j.parentNode.removeChild(j)}};a.getMatch=function(o,n){var k=n.childNodes,p;for(var m=0,q=k.length;m<q;m++){var i=k[m];if(i.nodeType!==1){continue}if(i===o){return p}if(i.nodeName.toUpperCase()!=="SOURCE"){continue}if(i.getAttribute("src")!==null&&typeof console!==undefined){console.warn("The `src` attribute is invalid on `picture` `source` element; instead, use `srcset`.")}var l=i.getAttribute("media");if(!i.getAttribute("srcset")){continue}if((!l||a.matchesMedia(l))){var h=a.verifyTypeSupport(i);if(h===true){p=i;break}else{if(h==="pending"){return false}}}}return p};function c(j){var h,l,o,q,n,p=j||{};h=p.elements||a.getAllElements();for(var m=0,k=h.length;m<k;m++){l=h[m];o=l.parentNode;q=undefined;n=undefined;if(l.nodeName.toUpperCase()!=="IMG"){continue}if(!l[a.ns]){l[a.ns]={}}if(!p.reevaluate&&l[a.ns].evaluated){continue}if(o&&o.nodeName.toUpperCase()==="PICTURE"){a.removeVideoShim(o);q=a.getMatch(l,o);if(q===false){continue}}else{q=undefined}if((o&&o.nodeName.toUpperCase()==="PICTURE")||(l.srcset&&!a.srcsetSupported)||(!a.sizesSupported&&(l.srcset&&l.srcset.indexOf("w")>-1))){a.dodgeSrcset(l)}if(q){n=a.processSourceSet(q);a.applyBestCandidate(n,l)}else{n=a.processSourceSet(l);if(l.srcset===undefined||l[a.ns].srcset){a.applyBestCandidate(n,l)}}l[a.ns].evaluated=true}}function d(){c();var h=setInterval(function(){c();if(/^loaded|^i|^c/.test(f.readyState)){clearInterval(h);return}},250);function i(){var j;if(!b._picturefillWorking){b._picturefillWorking=true;b.clearTimeout(j);j=b.setTimeout(function(){c({reevaluate:true});b._picturefillWorking=false},60)}}if(b.addEventListener){b.addEventListener("resize",i,false)}else{if(b.attachEvent){b.attachEvent("onresize",i)}}}d();c._=a;if(typeof module==="object"&&typeof module.exports==="object"){module.exports=c}else{if(typeof define==="function"&&define.amd){define(function(){return c})}}if(typeof b==="object"){b.picturefill=c}})(window,window.document,new window.Image(),picturefillOptions);