/**
* Name: groundwork.js (formerly prime.js)
* Version: 2.1
* Modified: Dec 5, 2011, Oct 25,2011, Oct 12,2011
* Author(s): Chris LaChance
* URI: http://chrislachance.com
* 
* Description: Small file to add useragent tags to HTML, collect URL queries, and detects if the browser is a mobile/tablet/desktop device. Used by permission of author.
**/

function browser(s,ua){return ua.slice(ua.indexOf(s)+s.length+1,ua.indexOf(".",ua.indexOf(s)));}
function urlQuery(s){query(s);}
function query(s){
  var loc=window.location.search.substring(1),qa=loc.split("&"),ql=qa.length,qv,i;
  for(i=0;i<ql;i++){
    qv=qa[i].split("=");
    if(qv[0]===s){return qv[1];}
  }
}

/* Begin Groundwork */
(function(ua,dc,ppi){
  /* Remove .no-js on #root */
  if(!!dc&&dc==='no-js'){dc='';}
  /* A/B Test Check */
  if(!!query("ab")){dc+=' '+query("ab");}
  /* Pixel Per Inch Ratio Class */
  if(!!ppi){dc+=' ppi'+String(ppi).replace('.','-');}else{dc+=' ppi-fail ppi1';ppi=1;}
  /* OS Detect */
    if (ua.indexOf("win") != -1) {dc+=" win";
    } else if (ua.indexOf("mac") != -1) {dc+=" mac";
    } else if (ua.indexOf("linux") != -1) {dc+=" linux";
    } else if (ua.indexOf("x11") != -1) {dc+=" unix";
    } else {dc+=" unknown_os";}
  /* Browser Detect */
  if (ua.match(/firefox/i)){dc+=" ff ff"+browser("fox",ua);
  }else if(ua.match(/msie/i)){dc+=" ie ie"+browser("msie",ua);
  }else if(ua.match(/chrome/i)){dc+=" chr chr"+browser("chrome",ua);
  }else if(ua.match(/opera/i)){dc+=" op op"+browser("opera",ua);
  }else if(ua.match(/safari/i)){dc+=" saf saf"+browser("safari",ua);}
  /* Mobile Detect */
  if(window.innerWidth/ppi<720&&window.innerHeight/ppi<720&&ua.match(/(phone)|(ipod)|(android)|(mobile)/i)){
    dc+=" mobile";
    addEventListener("load",function(){window.scrollTo(0, 1);});
  }else{
    if(ua.match(/(ipad)|(android)|(kindle)/i)){
      dc+=" tablet";
    }else{
      dc+=" desktop";
    }
  }
  /* Write Root Class */
document.getElementsByTagName("html")[0].className=dc;
}(navigator.userAgent.toLowerCase(),document.getElementsByTagName("html")[0].className,window.devicePixelRatio));
