// This script based on Paul Snowden's work described on A List Apart
//  <http://www.alistapart.com/stories/alternate/>
// Certain modifications (setFontSize and related) by Eric Meyer
//  <http://www.meyerweb.com/eric/>

function setActiveStyleSheet(title) {
	var i, a, main;
  	if (title) {
    	for (i=0; (a = document.getElementsByTagName('link')[i]); i++) {
      		// ig - only switch between screen media stylesheets
			if ((a.getAttribute('rel').indexOf('style') != -1) && ((a.getAttribute('title')) && (a.getAttribute('title').indexOf('default') == -1)) && ((a.getAttribute('media').indexOf('screen') != -1) || (a.getAttribute('media').indexOf('all') != -1))) {
	        	a.disabled = true;
    	    	if (a.getAttribute('title') == title) {
					a.disabled = false;
					createCookie('iankgrant-web-theme', title, 365);
				}
      		}
    	}
  	}
}

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;
}

// find out what theme they were using...
var cookie = readCookie('iankgrant-web-theme');
if (cookie != null) {
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
}

