﻿
var floaterChip = null;

function floaterStart(_n, _w, _h) { floaterChip = new Chip(_n, _w, _h); if (floaterChip) { movechip(); } }
function floaterStop() { if (floaterChip && floaterChip.timer1) { clearTimeout(floaterChip.timer1); } }
var vmin = 2, vmax = 5, vr = 2;
function Chip(chipname, width, height) { this.id = chipname; this.vx = vmin + vmax * Math.random(); this.vy = vmin + vmax * Math.random(); this.w = width; this.h = height; this.xx = 0; this.yy = 400; this.timer1 = null; }
function movechip() {
    var div; if (!floaterChip) return; chip = floaterChip; div = document.getElementById(chip.id); if (!div) return;
    if (window.innerWidth) {
        pageX = window.pageXOffset; pageY = window.pageYOffset; pageW = window.innerWidth; pageH = window.innerHeight;
    } else { pageX = document.body.scrollLeft; pageY = document.body.scrollTop; pageW = document.body.offsetWidth; pageH = document.body.offsetHeight; }
    maxX = pageX + 5; maxY = pageY + 5; maxW = pageX + pageW - chip.w - 25; maxH = pageY + pageH - chip.h - 25; vtot = vmax + vmin;
    chip.xx += chip.vx; chip.yy += chip.vy; chip.vx += vr * (Math.random() - 0.5); chip.vy += vr * (Math.random() - 0.5);
    if (chip.vx > vtot) chip.vx = vtot * 2 - chip.vx; if (chip.vx < (-vtot)) chip.vx = -vtot * 2 - chip.vx;
    if (chip.vy > vtot) chip.vy = vtot * 2 - chip.vy; if (chip.vy < (-vtot)) chip.vy = -vtot * 2 - chip.vy;
    if (chip.xx <= maxX) { chip.xx = maxX; chip.vx = vmin + vmax * Math.random(); } if (chip.xx >= maxW) { chip.xx = maxW; chip.vx = -vmin - vmax * Math.random(); }
    if (chip.yy <= maxY) { chip.yy = maxY; chip.vy = vmin + vmax * Math.random(); } if (chip.yy >= maxH) { chip.yy = maxH; chip.vy = -vmin - vmax * Math.random(); }
    chip.xx = Math.round(chip.xx); chip.yy = Math.round(chip.yy);
    div.style.left = chip.xx + "px";
    div.style.top = chip.yy + "px";
    chip.timer1 = setTimeout("movechip()", 100);
}


