/* This javascript is a modification of the one described in
 * http://www.alistapart.com/stories/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;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function getWidth() {
// Try all sorts of methods to find the width of the canvas.
	var w;
	if (window.innerWidth) {
	// For Netscape and Mozilla
		w = window.innerWidth;
		return w;
	}
	else if (document.body.clientWidth) {
	// For Internet Explorer
		w = document.body.clientWidth;
		return w;
	}
	else if (screen.width) {
	// Else use the resolution (should work in IE)
		w = screen.width;
		return w;
	}
	else {
	// Just guess a resonable value
		w = 750;
		document.write("Couldn't detect resolution.<BR>");
	}
}

window.onload = function(e) {
	var w = getWidth();
	if (w > 1420) {
		setActiveStyleSheet("hi-res");
	}
	else if (w < 990) {
		setActiveStyleSheet("lo-res");
	}
	else {
		setActiveStyleSheet("mid-res");
	}
}

window.onresize = function(e) {
	var w = getWidth();
	if (w > 1420) {
		setActiveStyleSheet("hi-res");
	}
	else if (w < 990) {
		setActiveStyleSheet("lo-res");
	}
	else {
		setActiveStyleSheet("mid-res");
	}
}

/*var title = "";
setActiveStyleSheet(title);*/
