/* 
========================================================================================================= CREDITS
Copyright 	: Copyright (c) 2008 JPL Productions & SPANCO. All Rights Reserved.
Author(s) 	: Jason Beck - jbeck@jplprod.com
			: Larry Daughenbaugh - ldaugh@jplprod.com
Date      	: 08/01/2008 
Notes    	: JavaScript file for loading in stylesheet based on browser window width
			: Used to load new styles so that the content fits safely within 800x600 screen resolutions
			: This js file should be loaded into the page after the initial stylesheet is loaded so that
			: it replaces the appropriate styles.
========================================================================================================= CHANGE LOG
Date		Name			Desc
---			---				---
========================================================================================================= BEGIN JAVASCRIPT
*/
function GetWindowWidth() {
     if (self.innerWidth) {
          return self.innerWidth;
     }
     else if (document.documentElement && document.documentElement.clientWidth) {
          return document.documentElement.clientWidth;
     }
     else if (document.body) {
          return document.body.clientWidth;
     }
}

function loadStylesheet(file) {
     var head = document.getElementsByTagName('head').item(0);
 
     if (document.getElementById('style' + file)) {
          //no reload or action needed - possibly remove old files in the future (memory hogs?)
          sheet = document.getElementById('style' + file);
     } else {
          sheet = document.createElement('link');
          sheet.id = 'style' + file;
          sheet.href= file;
          sheet.type = 'text/css';
          sheet.rel = 'stylesheet';
          head.appendChild(sheet);
          //head.insertBefore(sheet,head.lastChild);
     }
     return sheet;
}

// IF BROWSER WINDOW <= 800 THEN LOAD IN NEW STYLESHEET
if (GetWindowWidth()<=849) {
	loadStylesheet('/lib/css/base800-600.css');
}
