//  =======================================================================
//  University of Minnesota Nanotechnology Coordinating Office
//  http://www.nano.umn.edu
//  University of Minnesota Institute of Technology
//  http://www.itdean.umn.edu
//
//  /scripts/umn_nano_resolution.js
//
//  Javascript utilities for inclusion in html pages to change stylesheet.
//
//
//  Programmer:  John Schafer   jschafer :at: umn.edu
//
//  =======================================================================
//  Copyright (C) 2006 University of Minnesota
//  All rights reserved.
//  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR 
//  PURPOSE.
//  =======================================================================


/*

  Resolution functions
  
  These functions set the stylsheet used depending upon browser width.
  Needs to be used in conjuction with umn_nano_init.js so check is run 
  on initial page load.

*/

function checkBrowserWidth()  {
   var theWidth = getBrowserWidth();

   if (theWidth > 850)  {
      setStylesheet("Liquid layout");
      // setColumnHeights();
      }
   else  {
      setStylesheet("Gelled layout");
      // setColumnHeights("auto");
      }
   return true;
   }


function getBrowserWidth()  {
   if (window.innerWidth)  {
      return window.innerWidth;
      }
   else if (document.documentElement && document.documentElement.clientWidth != 0)  {
      return document.documentElement.clientWidth;
      }
   else if (document.body)  {
      return document.body.clientWidth;
      }
   return 0;
   }


function setColumnHeights(auto)  {
   var theFeature2 = document.getElementById("feature2Inner");
   var theFeature3 = document.getElementById("feature3Inner");
   var theFeature4 = document.getElementById("feature4Inner");
   var theHeight = "auto";

   if (!auto)  {
      theHeight = parseInt(theFeature2.scrollHeight);
      if (theFeature3 && theFeature3.scrollHeight > theHeight)  {
         theHeight = parseInt(theFeature3.scrollHeight);
         }
      if (theFeature4 && theFeature4.scrollHeight > theHeight)  {
         theHeight = parseInt(theFeature4.scrollHeight);
         }
      theHeight += "px";
      }

   theFeature2.style.height = theHeight;
   theFeature3.style.height = theHeight;
   theFeature4.style.height = theHeight;
   
   return true;
   }


function setStylesheet(styleTitle)  {
   var currTag;

   if (document.getElementsByTagName)  {
      for (var i = 0; (currTag = document.getElementsByTagName("link")[i]); i++)  {
         if (currTag.getAttribute("rel").indexOf("style") != -1 && currTag.getAttribute("title"))  {
            currTag.disabled = true;
            if(currTag.getAttribute("title") == styleTitle)  {
               currTag.disabled = false;
               }
            }  //  end if (currTag.getAttribute("rel")
         }
      }  //  end if (document.
  
   return true;
   }
