//addEvent() by John Resig
function addEvent( obj, type, fn ){
   if (obj.addEventListener){
      obj.addEventListener( type, fn, false );
   }
   else if (obj.attachEvent){
      obj["e"+type+fn] = fn;
      obj[type+fn] = function(){ obj["e"+type+fn]( window.event ); }
      obj.attachEvent( "on"+type, obj[type+fn] );
   }
}

//Run makeSpace function when page loads and when it resizes.
addEvent(window, 'load', makeSpace);
addEvent(window, 'resize', makeSpace);

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 makeSpace(){

   /* This function sets the size of the spacing div according to how wide the
    * browser window is. There are some literals in here, but it all works out
    * with the layout of the site.
    */

   var space = document.getElementById("spaceForNextProduction");
   var browserWidth = getBrowserWidth();


   var spaceNeeded =  (960 - browserWidth)/2;

   if (browserWidth < 810) {
      spaceNeeded =  spaceNeeded - (browserWidth - 810)/2;
   }

   if (spaceNeeded < 1){
      space.style.width = "0px";
   } else {
      space.style.width = spaceNeeded + "px";
   }   
   return true;
}

/* This function is to change the CSS class of the "nextProduction" div.
 * 
 * The reason is that I want to use a PNG with alpha channels for
 * rounded edges and a shadow, for the background image. 
 * This can't really be done with a GIF as the background is not constant.
 *
 * MS Internet Explorer 6 and below do not support PNG transparency,
 * so different background styles are needed.
 */


function setNextProdStyle(){
   var nVer = navigator.appVersion;
   var nAgt = navigator.userAgent;
   var browserName  = '';
   var majorVersion = 0;
   var decentBrowser = true;
	
   // In Internet Explorer, the true version is after "MSIE" in userAgent
   if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
      browserName  = "Microsoft Internet Explorer";
      fullVersion  = parseFloat(nAgt.substring(verOffset+5));
      majorVersion = parseInt(''+fullVersion)
	  if (majorVersion <= 6) {
		 //browser is IE 6 or lower
		 decentBrowser = false;
	  }
	  if (majorVersion <= 5) {
		  // display a message to users of older IE versions
		 alert("You appear to be using an old version of Microsoft Internet Explorer. Please note that the SCMTC website was produced for more modern browsers and may not display correctly.");
	  }
   }
   
   if (decentBrowser){
	   // change CSS class
	   document.getElementById("nextProduction").className = "nextProductionShadow";
	   // hide shadow image in content div
	   document.getElementById("spaceForNextProduction").style.background = "#FFFFFF"; 	   
   }
   
   
}
