//__________________________________________________________________________________________measurements
var measurements={ 
  pulse:null,
  matrixDim:{ x:0, y:0 },
  scrollPos:{ x:0, y:0 },
  matrixPos:{ x:0, y:0 },
  windowDim:{ x:0, y:0 },
  windowDimCon:{ x:1000, y:600 },
  windowDimOld:{ x:1000, y:600 },
  start:function() {
    if (measurements.pulse==null) measurements.pulse=setInterval("measurements.heartbeat()",1000)
	measurements.heartbeat()
  },
  freeze:function() { 
    if (measurements.pulse!=null) {
	  clearInterval(measurements.pulse) 
	  measurements.pulse=null
	}
  },
  heartbeat:function() { 
// Test the effective space on the page - and adjust font-size settings accordingly:
    var factor=(Height()*Width()) / (measurements.windowDimOld.x*measurements.windowDimOld.y);
    if (factor!=1) {  
      measurements.windowDimOld.x=Width()
      measurements.windowDimOld.y=Height()
      measurements.adaptStyleSheet()
	  Menu.build()
    }
// Check whether scrolling animation is currently running...
    if (SLIDER.active) return;
// Test the size of our window - rebuild if it has changed
    if (!(Height()==measurements.windowDim.y && Width()==measurements.windowDim.x)) { 
      measurements.windowDim.x=Width()
      measurements.windowDim.y=Height()
      build_xml()
      build()
      cellScroll(measurements.matrixPos.x,measurements.matrixPos.y,true)
// Test the scroll position:
    } else if (!(measurements.scrollPos.y==window.document.body.scrollTop && 
                 measurements.scrollPos.x==window.document.body.scrollLeft)) { 
// Determine scroll direction: 
      if (measurements.scrollPos.y==window.document.body.scrollTop) { // Horizontal movement detected      
         if (measurements.scrollPos.x<window.document.body.scrollLeft) Scroll('E',true); else Scroll('W',true);
      } else {                                                        // Vertical movement detected      
         if (measurements.scrollPos.y<window.document.body.scrollTop) Scroll('S',true); else Scroll('N',true);
      }
    }
  },
  sizeMatters:function() { 
    var styleLines=new Array();
// The (first) stylesheet (only)
    var currentSize='';
    var firstStylesheet=window.document.styleSheets[0];
    this.sizeUp=function(src,tagStr) { 
      if (src.indexOf(tagStr)<0) return 'x';
      var currentSetting='';
      var currentSize=''; 
      currentSetting=src.substring(src.indexOf(tagStr));
      currentSetting=currentSetting.substring(0,(currentSetting.indexOf('px')+2));
      currentSize=currentSetting.substring((tagStr.length-1),(currentSetting.indexOf('px'))); 
      return parseInt(currentSize);     
    }

    if (IE()) { // Internet explorer
      styleLines=firstStylesheet.cssText.split('\n'); 
      for (var i=0;i<styleLines.length-3;i+=3) {
        for (var tag in constants.cssTagsIE) { 
          currentSize=this.sizeUp(styleLines[i+1],constants.cssTagsIE[tag]);
          if (!isNaN(currentSize)) {
            if (!offset[styleLines[i]]) offset[styleLines[i]]=new Array();
            offset[styleLines[i]][constants.cssTagsIE[tag]]=currentSize;
          }
        }
      }
    } else { // Mozilla / Firefox HAZARD
      for (var rule=0;rule<firstStylesheet.cssRules.length;rule++) with (firstStylesheet.cssRules[rule]) {
        for (var tag in constants.cssTagsFF) {
          currentSize=this.sizeUp(cssText,constants.cssTagsFF[tag]); 
          if (!isNaN(currentSize)) { 
            if (!offset[rule]) offset[rule]=new Array();
            offset[rule][constants.cssTagsFF[tag]]=currentSize
          } 
        }
      }
    }
  },
  adaptStyleSheet:function(myFactor) {
    var styleLines=new Array()
    var currentSetting=''
    var newSize=0
    var newStyleSheet=''
    var changesApplied=false
    var firstStylesheet=window.document.styleSheets[0]
  
    if (IE()) {
      styleLines=firstStylesheet.cssText.split('\n'); 
      for (var i=0;i<styleLines.length-3;i+=3) { 
        var middleSection=styleLines[i+1]; 
        for (var tag in constants.cssTagsIE) { 
          if (middleSection.indexOf(constants.cssTagsIE[tag])>=0) {
            currentSetting=styleLines[i+1].substring(styleLines[i+1].indexOf(constants.cssTagsIE[tag])); 
            currentSetting=currentSetting.substring(0,(currentSetting.indexOf('px')+2));
            if (myFactor) newSize=parseInt(offset[styleLines[i]][constants.cssTagsIE[tag]] * myFactor); 
            else newSize=parseInt(offset[styleLines[i]][constants.cssTagsIE[tag]] * Factor()); 
            if (!isNaN(newSize)) middleSection=middleSection.replace(currentSetting,constants.cssTagsIE[tag]+newSize+'px');
          }
        }
        newStyleSheet+=styleLines[i]+middleSection+styleLines[i+2];
      } 
      if (myFactor) return newStyleSheet;
      firstStylesheet.cssText=newStyleSheet;
    } else { 
      for (var rule=0;rule<firstStylesheet.cssRules.length;rule++) if (offset[rule]) {
        with (firstStylesheet.cssRules[rule]) { 
          newStyleSheet=cssText
          for (var tag in constants.cssTagsFF) { 
            currentSetting=cssText.substring(cssText.indexOf(constants.cssTagsFF[tag]))
            currentSetting=currentSetting.substring(0,(currentSetting.indexOf('px')+2))
            newSize=parseInt(offset[rule][constants.cssTagsFF[tag]] * Factor()); 
            if ((!isNaN(newSize)) && (currentSetting!='')) {
              newStyleSheet=newStyleSheet.replace(currentSetting,constants.cssTagsFF[tag]+newSize+'px')
              changesApplied=true
            }
          }
          if (changesApplied) {
            firstStylesheet.deleteRule(rule)
            firstStylesheet.insertRule(newStyleSheet,rule)
          }
        } 
      } 
    }
  },
  adaptImageHeights:function() { 
    for (var image in document.images) {
      if (offset['IMAGE'][document.images[image].id]) document.images[image].height=parseInt(offset['IMAGE'][document.images[image].id] * Factor()); 
      if (document.images[image].name) { 
        if ((offset['IMAGE']['COMPASS']) && (document.images[image].name.charAt(0)=="c")) document.images[image].height=parseInt(offset['IMAGE']['COMPASS'] * Factor()); 
        if ((offset['IMAGE']['DIRECTION']) && (document.images[image].name.charAt(0)=="d")) document.images[image].height=parseInt(offset['IMAGE']['DIRECTION'] * Factor()); 
      }
    }
  }  
}
