﻿/*******************************************
Floating div code that works in IE & Firefox
with and without a DOCTYPE declaration
     
Main mods by Tim Doherty:
1) Additional/modified evaluation of height/width/scroll position
for different browers and with/without doctype
2) Parameters for div id, x & y positioning, boolean x= from right?
        
From: The JavaScript Source!! http://javascript.internet.com
Original: http://www.codelifter.com/
*******************************************/
var dD = document, dB = dD.body, px = dD.layers ? '' : 'px', w = window, dE = dD.documentElement;

function floatDiv(iX, iY, id, right) {


    var L = dD.getElementById ? dD.getElementById(id) : dD.all ? dD.all[id] : dD.layers[id];
    if(null == L)
        return;
        
    this[id + 'O'] = L;
    if (dD.layers) L.style = L;
    L.nX = L.iX = iX;
    L.nY = L.iY = iY;
    L.P = function(x, y) {
        if (right)
            this.style.right = x + px;
        else
            this.style.left = x + px;
        this.style.top = y + px;
    };

    L.Fm = function() {
        var pX, pY;
        pX = (this.iX >= 0) ? 0 : w.innerWidth ? w.innerWidth : dB.clientWidth;
        pY = w.pageYOffset ? w.pageYOffset : dE.scrollTop > 0 ? dE.scrollTop : dB.scrollTop;
        if (this.iY < 0) pY += w.innerHeight ? w.innerHeight : dE.clientHeight > 0 ? dE.clientHeight : dB.clientHeight;
        this.nX += .1 * (pX + this.iX - this.nX);

        this.nY += .1 * (pY + this.iY - this.nY);

        this.P(this.nX, this.nY);
        setTimeout(this.id + 'O.Fm()', 33);
    };
    L.Fm();
}

floatDiv(0, 200, 'FloatDiv', false);
floatDiv(0, 200, 'FloatDivRight', true);

