starField_q.html Source Code

Site Navigation 
<html>
<head>
<title></title>
<style type="text/css">
BODY {
    background-image:url(images/starField.gif);
    background-color:#000000;
    color:#FFFFFF;
}
</style>
</head>
<body>
<script type="text/javascript">
(function(){
  var numberOfStars = 30;
  var global = this;
  var starObjs, accelMod, starHTML;
  var posMod, sy, sx, windowCenterY, windowCenterX, bgcolor;
  var globalName = 'starField';
  if((document.layers)&&(this.Layer)){
    bgcolor = 'bgColor';
    starHTML = [
    '<layer id=\"stars','',
    '\" left=\"0\" top=\"0\" ',
    'width=\"1\" height=\"1" bgColor=\"',
    '#FFFFFF\"><\/layer>'];
  }else{
    bgcolor = 'backgroundColor';
    starHTML = [
    '<div id="stars','',
    '" style="position:absolute;width:1px;overflow:hidden;',
    'height:1px;background-color:#FFFFFF;font-size:',
    '1px"><\/div>'];
  }
  function compatModeTest(obj){
    if((document.compatMode)&&
       (document.compatMode.indexOf('CSS') != -1)&&
       (document.documentElement)){
      return document.documentElement;
    }else if(document.body){
      return document.body;
    }else{
      return obj;
    }
  }
  function getWindowState(){
    var global = this;
    var readScroll = {scrollLeft:NaN,scrollTop:NaN};
    var readSizeC = {clientWidth:NaN,clientHeight:NaN};
    var readSizeI = {innerWidth:NaN,innerHeight:NaN};
    var readScrollX = 'scrollLeft';
    var readScrollY = 'scrollTop';
    function getWidthI(){return readSizeI.innerWidth;}
    function getWidthC(){return readSizeC.clientWidth|0;}
    function getHeightI(){return readSizeI.innerHeight;}
    function getHeightC(){return readSizeC.clientHeight|0;}
    function getHeightSmart(){
      return retSmaller(getHeightI(), getHeightC());
    }
    function getWidthSmart(){
      return retSmaller(getWidthI(), getWidthC());
    }
    function setInnerWH(){
      theOne.getWidth = getWidthI;
      theOne.getHeight = getHeightI;
    }
    function retSmaller(inr, other){
      if(other > inr){
        setInnerWH();
        return inr;
      }else{
        return other;
      }
    }
    var theOne = {
      getScrollX:function(){return readScroll[readScrollX]|0;},
      getScrollY:function(){return readScroll[readScrollY]|0;},
      getWidth:getWidthC,
      getHeight:getHeightC
    };
    function main(){return theOne;}
    function rankObj(testObj){
      var dv,dhN;
      if(testObj&&(typeof testObj.clientWidth == 'number')&&
        (typeof testObj.clientHeight == 'number')){
        if(((dv = global.innerHeight - testObj.clientHeight) >= 0)&&
           ((dh = global.innerWidth - testObj.clientWidth) >= 0)){
          if(dh == dv){
            return 0;
          }else if((dh&&!dv)||(dv&&!dh)){
            return (dh+dv);
          }
        }
      }
      return NaN;
    }
    if((typeof global.innerHeight == 'number')&&
       (typeof global.innerWidth == 'number')){
      readSizeI = global;
      var bodyRank = rankObj(document.body);
      var rankDocEl = rankObj(document.documentElement);
      var selEl = null;
      if(!isNaN(bodyRank)){
        if(!isNaN(rankDocEl)){
          if(bodyRank < rankDocEl){
            selEl = document.body;
          }else if(bodyRank > rankDocEl){
            selEl = document.documentElement;
          }else{
            selEl = compatModeTest(document.body);
          }
        }else{
          selEl = document.body;
        }
      }else if(!isNaN(rankDocEl)){
        selEl = document.documentElement;
      }
      if(selEl){
        readSizeC = selEl
        theOne.getWidth = getWidthSmart;
        theOne.getHeight = getHeightSmart;
      }else{
        setInnerWH();
      }
    }else{
      readSizeC = compatModeTest(readSizeC);
    }
    if((typeof global.pageYOffset == 'number')&&
       (typeof global.pageXOffset == 'number')){
      readScroll = global;
      readScrollY = 'pageYOffset';
      readScrollX = 'pageXOffset';
    }else{
      readScroll = compatModeTest(readScroll);
    }
    return (getWindowState = main)();
  }
  var windowState = getWindowState();
  function readWindow(){
    windowCenterY = windowState.getHeight() >> 1;
    windowCenterX = windowState.getWidth() >> 1;
    sy = windowCenterY + windowState.getScrollY();
    sx = windowCenterX +windowState.getScrollX();
    accelMod = ((accelMod = (windowCenterX +
             windowCenterY))*accelMod);
  }
  function getStyleObj(id){
    var obj = null;
    if(document.getElementById){
      obj = document.getElementById(id);
    }else if(document.all){
      obj = document.all[id];
    }else if(document.layers){
      obj = document.layers[id];
    }
    return (obj && obj.style) || obj;
  }
  function starObj(id, parent, prv){
    var next, nosX2 = (numberOfStars << 1);
    var divDimension,delay,
        divClip, div = getStyleObj("stars"+id);
    var y,x,ddw,bx,by,v,px,py,tmp,dx,dy,dm;
    (this.reset = function(){
      px = Math.random()<0.5 ? +1 : -1;
      py = Math.random()<0.5 ? +1 : -1;
      y = ((Math.random()*Math.random()*
             (windowCenterY-8))+4)|0;
      x = ((Math.random()*Math.random()*
             (windowCenterX-8))+4)|0;
      tmp = (((windowCenterY - y)*
          (windowCenterX - x))/(accelMod)) ;
      bx = (x*tmp)/200;
      by = (y*tmp)/200;
      v = 1+ tmp;
      ddw = ((tmp/3))+1
      delay = ((Math.random() * nosX2)|1);
      div[bgcolor] = '#888888';
      return (divDimension = 0.4);
    })();
    if(div){
      if(!posMod){
        posMod = (typeof div.top == 'string')?'px':0;
      }
      divClip =  (div &&
             (typeof div.clip != 'string') &&
                        div.clip)||div;
      this.position = function(){
        if(delay-- <= 0){
          dm = ((divDimension *= ddw)|0);
          dy = (y += (by *= v))|0;
          dx = (x += (bx *= v))|0;
          if(((dy+dm) >= windowCenterY)||
             ((dx+dm) >= windowCenterX)){
            dm = this.reset();
            dy = y;
            dx = x;
          }
          div.top = (sy+(py*dy)-dm)+posMod;
          div.left = (sx+(px*dx)-dm)+posMod;
          divClip.width = 
               (divClip.height = 
               ((dm<<1)||1) + posMod);
        }else if(delay <= 1){
          div[bgcolor] = '#FFFFFF';
        }
        next.position();
      };
    }else{
      this.position = function(){return;};
    }
    if(++id < numberOfStars){
      next = new starObj(id, parent)
    }else{
      next = parent
    }
  }
  function init(){
    if(!getStyleObj("stars"+(numberOfStars-1))){
      setTimeout(starField, 200);
    }else{
      readWindow();
      starObjs = new starObj(0, init);
      init.act();
    }
  };
  init.position = function(){return;}
  init.act = function(){
    readWindow();
    starObjs.position();
    setTimeout(init.act,40);
  };
  init.act.toString = function(){return globalName+'.act()';};
  init.toString = function(){
    while(global[globalName])globalName += globalName;
    global[globalName] = this; //this - is the init function.
    return globalName+'()';
  };
  for(var c = numberOfStars;c--;){
    starHTML[1] = c;
    document.write(starHTML.join(''));
  }
  setTimeout(init, 200);
})();
</script>
</body>
</html>
© Richard Cornford 2004