/* Get all cookies (in case the site has set more than one */
var cookies = document.cookie.split("; ");

var thiscookie;
var exists = false;

/* Loop through all cookies and search for screenCheck */
for (i=0; i<cookies.length; i++) {
	thiscookie = cookies[i].split("=");
	/* If screenCheck is set to true, we've already determined this is not a mobile device - end execution */
	if(thiscookie[0] == "screenCheck") {
		exists = true;
		break;
	}
}
/* Only run the screen test if no previous cookie could be found */
if(!exists) {
var wid = screen.width;
	/* If screen is large, assume it is not a mobile device */
	if(wid > 640) {
    	document.cookie = "screenCheck=big;path=/";
		setActiveStyleSheet("hld");
	}
	/* Otherwise, assume it is a mobile device */
	else {
		document.cookie = "screenCheck=small;path=/";
	}
}
/* That's it. */


/* The following function is coutesy of Paul Sowden at http://www.alistapart.com/articles/alternate/ */
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}
