﻿var org = new Object();
var maxTrace = 13;
function $(element) { return document.getElementById(element); }

var currentTrace = 0;
function Trace (arg) {
    var traceBox = $("traceBox");
    if (traceBox) {
        if (currentTrace >= maxTrace) {
            traceBox.innerHTML = "";
            currentTrace = 0;
        }
        traceBox.innerHTML += "[Framework]：" + arg + "<br/>";
        currentTrace++;
    }
}

org.framework = {
    Initialize: function () {
        if (document.all) {
            Trace("你正在使用IE浏览器");
            this.IsIE = true;
        } else {
            Trace("你正在使用非IE浏览器");
        }
    },

    IsIE: false,
    AlphaIn: 100,
    AlphaOut: 0,
    FadeInVal: 0,
    FadeOutVal: 0,

    GetPosition: function (element) {
        var top = 0, left = 0;
        do {
            top += element.offsetTop;
            left += element.offsetLeft;
        }
        while (element = element.offsetParent);

        return { Top: top, Left: left };
    },


    FadeIn: function (pic,callback) {
        if (this.AlphaIn <= 0) {
            if (this.FadeInVal > 0) {
                clearTimeout(this.FadeInVal);
                if (callback) {
                    callback();
                }
                return;
            }
        }
        Trace(pic);


        this.AlphaIn -= 10;

        if (this.IsIE) {
            pic.style.filters = "alpha(opacity=50)";
        } else {
            pic.style.MozOpacity = this.AlphaIn / 100;
        }
        var self = this;
        this.FadeInVal = setTimeout(function () {
            self.FadeIn(pic);
        }, 50);

        Trace(this.AlphaIn);
    },

    FadeOut: function (pic, callback) {
        if (this.AlphaOut >= 100) {
            if (this.FadeOutVal > 0) {
                clearTimeout(this.FadeOutVal);
                if (callback) {
                    callback();
                }
                return;
            }
        }
        Trace(pic);


        this.AlphaOut += 10;

        if (this.IsIE) {
            pic.style.filters = "alpha(opacity=50)";
        } else {
            pic.style.MozOpacity = this.AlphaOut / 100;
        }
        var self = this;
        this.FadeOutVal = setTimeout(function () {
            self.FadeOut(pic);
        }, 50);

        Trace(this.AlphaOut);
    }
}
