<!--
/* This script available from TMacD http://staff.eivia.com/~tmacd/ */

var ie = document.all;
var ns6 = document.getElementById && !document.all;
var prof_floatLyr;
var rem_floatLyr;
var pageWidth;
var pageWidth;
var prof_findHt;
var rem_findHt;
var topMargin = 200;
var slideTime = 1200;
var prof_count = 0;
var rem_count = 0;
var dragok=false;
var action="profile";
var x, y, z;
var temp1, temp2;
var prof_div;
var rem_div;

document.onmousedown=drags;

document.onmouseup=stop_drag;

function stop_drag() {
  if (action == "profile") {
    if (dragok) {
      if (ns6) {
	z.style.cursor = 'pointer'
      } else {
	document.all.profileForm.style.cursor = 'hand';
      }
    }
  } else if (action == "reminder") {
    if (dragok) {
      if (ns6) {
	z.style.cursor = 'pointer'
      } else {
	document.all.reminderForm.style.cursor = 'hand';
      }
    }
  }
  dragok=false;
}

function move(e) {
  if (dragok) {
    z.style.left = temp1 + (ns6 ? e.clientX : event.clientX) - x;
    z.style.top = temp2 + (ns6 ? e.clientY : event.clientY) - y;
    return false;
  }
}

function drags(e) {
  if (!ie && !ns6) {
    return;
  }
  var looking_for = (action == "profile" ? "prof_drag" : "rem_drag");
    
  var firedobj = ns6 ? e.target : event.srcElement;
  var topelement = ns6 ? "HTML" : "BODY";
  while (firedobj.tagName != topelement && firedobj.className != looking_for) {
    firedobj = ns6 ? firedobj.parentNode : firedobj.parentElement;
  }
  if (firedobj.className == looking_for) {
    if (ns6) {
      firedobj.style.cursor = "move";
    } else if (looking_for == "prof_drag") {
      document.all.profileForm.style.cursor = "move";
    } else {
      document.all.reminderForm.style.cursor = "move";
    }
    dragok = true;
    z = firedobj;
    temp1 = parseInt(z.style.left+0);
    temp2 = parseInt(z.style.top+0);
    x = ns6 ? e.clientX : event.clientX;
    y = ns6 ? e.clientY : event.clientY;
    document.onmousemove=move;
    return false;
  }
}

function prof_layerObject(id, left) {
  if (ns6) {
    var d = document.getElementById("profileForm").style;
    d.display = "block";
    this.obj = document.getElementById(id).style;
    this.obj.display = "block";
  } else if (ie) {
    document.all["profileForm"].style.display = "block";
    document.all["profileForm"].style.filter = "alpha(opacity=95)";
    this.obj = document.all[id].style;
    this.obj.display = "block";
  } else {
    alert("This browser is not supported");
  }
  this.obj.left = left;
  return this.obj;
}

function rem_layerObject(id, left) {
  if (ns6) {
    var d = document.getElementById("reminderForm").style;
    d.display = "block";
    this.obj = document.getElementById(id).style;
    this.obj.display = "block";
  } else if (ie) {
    document.all["reminderForm"].style.display = "block";
    document.all["reminderForm"].style.filter = "alpha(opacity=95)";
    this.obj = document.all[id].style;
    this.obj.display = "block";
  } else {
    alert("This browser is not supported");
  }
  this.obj.left = left;
  return this.obj;
}

function prof_floatStart() {
  var now = new Date();
  this.A = this.targetY - this.currentY;
  this.B = Math.PI / ( 2 * this.slideTime );
  this.C = now.getTime();
  if (Math.abs(this.A) > this.findHt) {
    this.D = this.A > 0 ? this.targetY-this.findHt : this.targetY+this.findHt;
    this.A = this.A > 0 ? this.findHt : -this.findHt;
  } else {
    this.D = this.currentY;
  }
}

function rem_floatStart() {
  var now = new Date();
  this.E = this.targetY - this.currentY;
  this.F = Math.PI / ( 2 * this.slideTime );
  this.G = now.getTime();
  if (Math.abs(this.E) > this.rem_findHt) {
    this.H = this.E > 0 ? this.targetY-this.rem_findHt : this.targetY+this.rem_findHt;
    this.E = this.E > 0 ? this.rem_findHt : -this.rem_findHt;
  } else {
    this.G = this.currentY;
  }
}

function prof_animator() {
  var now = new Date();
  var newY = this.A * Math.sin( this.B * ( now.getTime() - this.C ) ) + this.D;
  newY = Math.round(newY);
  if ((this.A > 0 && newY > this.currentY) ||
      (this.A < 0 && newY < this.currentY)) {
    if ( ie ) {
      document.all.createProfile.style.pixelTop = newY;
    } else if ( ns6 ) {
      document.getElementById('createProfile').style.top = newY + "px";
    }
  }
}

function rem_animator() {
  var now = new Date();
  var newY = this.E * Math.sin( this.F * ( now.getTime() - this.G ) ) + this.H;
  newY = Math.round(newY);
  if ((this.E > 0 && newY > this.currentY) ||
      (this.E < 0 && newY < this.currentY)) {
    if ( ie ) {
      document.all.passwordReminder.style.pixelTop = newY;
    } else if ( ns6 ) {
      document.getElementById('passwordReminder').style.top = newY + "px";
    }
  }
}

function prof_mainTrigger() {
  var newTargetY = (ns6 ? window.innerHeight : document.body.clientHeight) * .2;
  if ( this.currentY != newTargetY ) {
    if ( newTargetY != this.targetY ) {
      this.targetY = newTargetY;
      prof_floatStart();
    }
    prof_animator();
  }
}

function rem_mainTrigger() {
  var newTargetY = (ns6 ? window.innerHeight : document.body.clientHeight) * .2;

/* +++
  if (rem_count % 20 == 0 && rem_count < 200) {
    alert("rem_mainTrigger: newTargetY="+newTargetY+", this.currentY="+this.currentY+", this.targetY=" +this.targetY);
  }
 **/

  if ( this.currentY != newTargetY ) {
    if ( newTargetY != this.targetY ) {
      this.targetY = newTargetY;
      rem_floatStart();
    }
    rem_animator();
  }
}

function prof_main() {
  if (prof_count++ > 200) {
    clearInterval(prof_div);
    return;   // only want it to scroll down once.
  }
  if (ns6) {
    this.currentY = parseInt(document.getElementById('createProfile').style.top);
    this.scrollTop = 0;   // use top of page as the scroll start point.
  } else if (ie) {
    this.currentY = createProfile.style.pixelTop;
    this.scrollTop = document.body.scrollTop;
  }
  prof_mainTrigger();
}

function rem_main() {
  if (rem_count++ > 200) {
    clearInterval(rem_div);
    return;   // only want it to scroll down once.
  }
  if (ns6) {
    this.currentY = parseInt(document.getElementById('passwordReminder').style.top);
    this.scrollTop = 0;   // use top of page as the scroll start point.

/* +++
    if (rem_count % 20 == 0 && rem_count < 200) {
      alert("rem_count="+rem_count+", this.currentY="+this.currentY);
    }
 **/

  } else if (ie) {
    this.currentY = passwordReminder.style.pixelTop;
    this.scrollTop = document.body.scrollTop;
  }
  rem_mainTrigger();
}

function prof_layerSetup() {
  prof_floatLyr = new prof_layerObject('createProfile', pageWidth * .5);
  prof_div = window.setInterval("prof_main()", 10)
}

function rem_layerSetup() {
  rem_floatLyr = new rem_layerObject('passwordReminder', pageWidth * .5);
//alert("rem_layerSetup");
  rem_div = window.setInterval("rem_main()", 10)
}

function floatObject() {
  if (ns6) {
    prof_findHt = window.innerHeight;
  } else if (ie) {
    prof_findHt = document.body.clientHeight;
  }
}

function initSimple(thing) {
  if (ns6) {
    pageWidth = window.innerWidth;
    pageHeight = window.innerHeight;
  } else if (ie) {
    pageWidth = document.body.clientWidth;
    pageHeight = document.body.clientHeight;
  }
  if (thing == "profile") {
    action = "profile";
    prof_layerSetup();
  } else if (thing == "reminder") {
    action = "reminder";
    rem_layerSetup();
  } else {
    alert("ERROR: unkown thing:  " + thing);
  }
  floatObject();
}

function about() {
  msg = "TMacD Football Pool\n============\n\n";
  msg += "Developed by TMacD\nhttp://staff.eivia.com/~tmacd/";
  alert(msg);
}

function closeProfile() {
  document.getElementById("profileForm").style.display = "none";
}

function closeRem() {
  document.getElementById("reminderForm").style.display = "none";
}

// -->
