
var fixedStars = true; // let them be fixed.

// determine browser and version.
function Is() {
  var agent = navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);
  this.ns  = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
  this.ns4 = (this.ns && (this.major >= 4));
  this.ie   = (agent.indexOf("msie") != -1);
  this.ie4  = (this.ie && (this.major >= 4));
}

var is = new Is()
if (is.ns4) {
  doc = "document";
  sty = "";
  htm = ".document";
  xpos = "evnt.pageX";
  ypos = "evnt.pageY";
}
else if (is.ie4) {
  doc = "document.all";
  sty = ".style";
  htm = "";
  xpos = "event.x";
  ypos = "event.y";
}

// put all object at right places before make them visible. 
// called when onLoad.
function layerSetup() {
  A_Lyr = eval(doc + '["LayerA"]' + sty);
  A_Lyr.left = (available_width)/2;
  A_Lyr.top = (available_height-145)/2;
  B_Lyr = eval(doc + '["LayerB"]' + sty);
  B_Lyr.left = (available_width)/2;
  B_Lyr.top = (available_height-145)/2;
  C_Lyr = eval(doc + '["LayerC"]' + sty);
  C_Lyr.left = (available_width)/2;
  C_Lyr.top = (available_height-145)/2;
  D_Lyr = eval(doc + '["LayerD"]' + sty);
  D_Lyr.left = (available_width)/2;
  D_Lyr.top = (available_height-145)/2;
  E_Lyr = eval(doc + '["LayerE"]' + sty);
  E_Lyr.left = (available_width)/2;
  E_Lyr.top = (available_height-145)/2;
  F_Lyr = eval(doc + '["LayerF"]' + sty);
  F_Lyr.left = (available_width)/2;
  F_Lyr.top = (available_height-145)/2;
  G_Lyr = eval(doc + '["LayerG"]' + sty);
  G_Lyr.left = (available_width)/2;
  G_Lyr.top = (available_height-145)/2;

  pathLyr = eval(doc + '["pathLayer"]' + sty);
  pathLyr.left = 3;
  pathLyr.top = 0;

  visibilitySetup();
}

// make all objects visible.
function visibilitySetup() {
  A_Lyr.visibility = "visible";
  B_Lyr.visibility = "visible";
  C_Lyr.visibility = "visible";
  D_Lyr.visibility = "visible";
  E_Lyr.visibility = "visible";
  F_Lyr.visibility = "visible";
  G_Lyr.visibility = "visible";
  pathLyr.visibility = "visible";

  xPosition = parseInt(A_Lyr.left);
  yPosition = parseInt(A_Lyr.top);

  eventSetup();
  moveStar();
}

var delay = 10;
var step = 0.2;
var currStep = 0;
var xPosition = 150;
var yPosition = 150;
// var xFix = 0;
// var yFix = 0;
var xFix = 150;
var yFix = 150;

// if (is.ns4) {
//   window.captureEvents(Event.MOUSEMOVE || Event.MOUSEDOWN);
// }

// function MoveHandler(evnt) {
//  if (is.ns4) {
//     if (fixedStars) {
//       xPosition = evnt.pageX;
//       yPosition = evnt.pageY;
//           }
//       else {
      xPosition = xFix;
      yPosition = yFix;
//     }
//   }
// }

// function DownHandler(evnt) {
//   if (is.ns4) {
//      xFix = eval(xpos); 
//     yFix = eval(ypos);
//   }
// }

// if (is.ns4) window.onMouseMove = MoveHandler;
// if (is.ns4) window.onMouseDown = DownHandler;

// path of star movement.
function moveStar() {
  var j = 0;
  xBase = available_width/2;
  yBase = available_height/2;
  A_Lyr.top  = yPosition + Math.cos((20*Math.sin(currStep/20))+j*70)*yBase*(Math.sin(10+currStep/10)+0.2)*Math.cos((currStep+j*25)/10);
  A_Lyr.left = xPosition + Math.sin((20*Math.sin(currStep/20))+j*70)*xBase*(Math.sin(10+currStep/10)+0.2)*Math.cos((currStep+j*25)/10);
  j++;
  B_Lyr.top  = yPosition + Math.cos((20*Math.sin(currStep/20))+j*70)*yBase*(Math.sin(10+currStep/10)+0.2)*Math.cos((currStep+j*25)/10);
  B_Lyr.left = xPosition + Math.sin((20*Math.sin(currStep/20))+j*70)*xBase*(Math.sin(10+currStep/10)+0.2)*Math.cos((currStep+j*25)/10);
  j++;
  C_Lyr.top  = yPosition + Math.cos((20*Math.sin(currStep/20))+j*70)*yBase*(Math.sin(10+currStep/10)+0.2)*Math.cos((currStep+j*25)/10);
  C_Lyr.left = xPosition + Math.sin((20*Math.sin(currStep/20))+j*70)*xBase*(Math.sin(10+currStep/10)+0.2)*Math.cos((currStep+j*25)/10);
  j++;
  D_Lyr.top  = yPosition + Math.cos((20*Math.sin(currStep/20))+j*70)*yBase*(Math.sin(10+currStep/10)+0.2)*Math.cos((currStep+j*25)/10);
  D_Lyr.left = xPosition + Math.sin((20*Math.sin(currStep/20))+j*70)*xBase*(Math.sin(10+currStep/10)+0.2)*Math.cos((currStep+j*25)/10);
  j++;
  E_Lyr.top  = yPosition + Math.cos((20*Math.sin(currStep/20))+j*70)*yBase*(Math.sin(10+currStep/10)+0.2)*Math.cos((currStep+j*25)/10);
  E_Lyr.left = xPosition + Math.sin((20*Math.sin(currStep/20))+j*70)*xBase*(Math.sin(10+currStep/10)+0.2)*Math.cos((currStep+j*25)/10);
  j++;
  F_Lyr.top  = yPosition + Math.cos((20*Math.sin(currStep/20))+j*70)*yBase*(Math.sin(10+currStep/10)+0.2)*Math.cos((currStep+j*25)/10);
  F_Lyr.left = xPosition + Math.sin((20*Math.sin(currStep/20))+j*70)*xBase*(Math.sin(10+currStep/10)+0.2)*Math.cos((currStep+j*25)/10);
  j++;
  G_Lyr.top  = yPosition + Math.cos((20*Math.sin(currStep/20))+j*70)*yBase*(Math.sin(10+currStep/10)+0.2)*Math.cos((currStep+j*25)/10);
  G_Lyr.left = xPosition + Math.sin((20*Math.sin(currStep/20))+j*70)*xBase*(Math.sin(10+currStep/10)+0.2)*Math.cos((currStep+j*25)/10);
  j = 0;
  currStep += step;
  setTimeout("moveStar()", delay);  // recursive call
}

function eventSetup() {
    pathArea = eval(doc + '["pathLayer"]' + htm);
//    pathArea.onmousemove = mouseMove;
//    pathArea.onmousedown = mouseDown;
//    if (is.ns4) pathArea.captureEvents(Event.MOUSEMOVE);
//    if (is.ns4) pathArea.captureEvents(Event.MOUSEDOWN);
}

// get the position when mouse move.
function mouseMove(evnt) {
//   if (fixedStars) {
//     xPosition = eval(xpos);
//     yPosition = eval(ypos);
//   }
//   else {
    xPosition = xFix; 
    yPosition = yFix;
//   }
}

// get the position when mouse down.
function mouseDown(evnt){
  xFix = eval(xpos); yFix = eval(ypos);
}

// change the speed.
function chngitsspeed() {
  if (isNumber(document.formular.chngspeed.value) == 1) 
    delay = document.formular.chngspeed.value;
}

// check if the input is a positive number.
function isNumber(inptVal) {
  inptStr = "" + inptVal;
  var oneChar;
  for (var i = 0; i < inptStr.length; i++) {
    oneChar = inptStr.charAt(i);
    if (oneChar < "0" || oneChar > "9") return 0;
  }
  return 1;
}

// let stars fixed or fly.
function chngf(v) {
  if (v == 'starfix') {
    fixedStars = false; 
     xFix = xPosition; 
     yFix = yPosition;
  }
  else  fixedStars = true;
}


