/* Autodetect browser type; sets browser var to 'IE', 'Safari', 'Firefox' or empty string. */
function hackGetBrowser() {
  var name = navigator.appName;
  var agent = navigator.userAgent.toLowerCase();

  if (name.indexOf('Microsoft') != -1) {
    if (agent.indexOf('mac') == -1) {
      return 'IE';
      // note that Mac IE is considered to be uncategorized
    }
  } else if (agent.indexOf('safari') != -1) {
    return 'Safari';
  } else if (agent.indexOf('firefox') != -1) {
    return 'Firefox';
  } else if (agent.indexOf('chrome') != -1) {
	return 'Chrome';
  }
};

function hackIsIE() {
  return (hackGetBrowser() == 'IE');
};

function hackIsIE6() {
  return navigator.userAgent.toLowerCase().indexOf('msie 6.0') != -1;
}

// Browser Window Size and Position
// Copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
function hackPageWidth() {
  return window.innerWidth != null ? window.innerWidth :
         document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth :
         document.body != null ? document.body.clientWidth : null;
}

function hackPageHeight() {
  return window.innerHeight != null ? window.innerHeight :
	     document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight :
	     document.body != null? document.body.clientHeight : null;
}

function hackPosLeft() {
  return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :
         document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft :
         document.body.scrollLeft ? document.body.scrollLeft : 0;
}

function hackPosTop() {
  return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset :
	     document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop :
         document.body.scrollTop ? document.body.scrollTop : 0;
}

function hackPosRight() {
  return posLeft()+pageWidth();
}

function hackPosBottom() {
  return posTop()+pageHeight();
}
                 
function hackGetById(id) {
  if (document.getElementById) {
    var returnVar = document.getElementById(id);
  } else if (document.all) {
    var returnVar = document.all[id];
  } else if (document.layers) {
    var returnVar = document.layers[id];
  }
  return returnVar;
}

function hackLoadCss(url) {
  var head = document.getElementsByTagName("head")[0];
  var cssNode = document.createElement('link');
  cssNode.type = 'text/css';
  cssNode.rel = 'stylesheet';
  cssNode.href = url;
  cssNode.media = 'all';
  cssNode.title = 'dynamicLoadedSheet';
  head.appendChild(cssNode);
};

function hackFixIE6() {
  var img = theme_uri+"images/logo.png";
  var style = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img+"',sizingMethod='scale');";
  $('main-logo-link').innerHTML = "<img class='logo' src='"+img+"' alt='Logo' style='"+style+"'/>";
}

/***************************************************************************************************
 * Hacks.
 **************************************************************************************************/

if (hackPageWidth() < 1200) {
  hackLoadCss(theme_uri + 'hacks-small.css');
} else if (hackPageWidth() < 1300) {
  hackLoadCss(theme_uri + 'hacks-medium.css');
}

if (hackIsIE()) {
  if (hackIsIE6()) {
    hackFixIE6();
    hackLoadCss(theme_uri + 'hacks-ie6.css');
  }
  hackLoadCss(theme_uri + 'hacks-ie.css');
}
