// on loading the page this function is replaced by an instance
function NavFx()
{
        function maxDiff(c1, c2)
        {
                mx = 0
                for (i in c1)
                {
                        d = c1[i]-c2[i]
                        if (d<0) d = -d
                        if (d > mx) mx = d
                }
                return mx
        }

        function c2n(color1)
        {
                if (color1.substring(0,4)=="rgb(") {
                        c =color1.substring(4, color1.length-1).split(",")
                        for (k=0; k<3; k++) {
                                c[k] = Number(c[k])
                        }
                } else {
                        c = []
                        for (i=0; i<3; i++) {
                                c[i] = Number("0x"+color1.substring(1+2*i, 3+2*i))
                        }
                }
                return c
        }

        function grad(liC, inC, k, n)
        {
                c = []
                for (i=0; i<3; i++) {
                        a = k * inC[i]
                        b = (n-k) * liC[i]
                        c[i] = Math.round( (a+b) / n)
                }
                return c
        }


        this.fadeIndex = 0
        this.outFader =  false
        this.style = document.styleSheets[0].cssRules[5].style
//        inactiveColor = document.styleSheets[0].cssRules[6].style.color
//        linkColor = this.style.color
        linkColor = "#000060"
        inactiveColor = "#808080"
        this.millis = 5 * 1000
        n = Math.round(this.millis * 5 / 1000)
        inC = c2n(inactiveColor)
        liC = c2n(linkColor)
        mx = maxDiff(inC,liC)
        if (n>mx) n = mx
        this.ncolors = n
        this.fadeColor = []
        for (j=0; j<=n; j++) {
                color = "rgb(" + grad(liC, inC, j, n) + ")"
                this.fadeColor[j] = color
        }

        this.enter = function navFx_enter()
        {
                if (this.outFader) {
                        clearInterval(this.outFader)
                        this.outFader = false
                }
                this.fadeIndex = 0
                this.style.color = this.fadeColor[this.fadeIndex]
        }

        this.leave = function navFx_leave()
        {
                if (this.outFader) return
                this.outFader = setInterval("navFx.fadeOut()", this.millis / n)
        }

        this.fadeOut = function navFx_fadeOut()
        {
                this.fadeIndex++
                if (this.fadeIndex<0 || this.fadeIndex > this.ncolors) {
                        clearInterval(this.outFader)
                        this.outFader = false
                } else {
                        color = this.fadeColor[this.fadeIndex]
// //                       document.getElementById("dbg").innerHTML = color + " xxx " + this.fadeIndex
                        this.style.color = color
                }
        }

        // initial appearance is regular link, fading out
        this.style.color = this.fadeColor[this.fadeIndex]
        this.leave()
 }



