﻿var screenwidths = (window.screen.width - 920)/2;
//alert(screenwidths);
document.write('<div id=\"AllPageScrollTop\" style=\"width:21px; height:12px;Z-INDEX:2000; Right:' + screenwidths + 'px;position:absolute;top:600px;\"><a href=\"#top\"><IMG  height=12 src=\"/images/top.gif\" width=21 border=0 alt=\"返回顶部\"></A></div>');
var bluebutterfly = function() { }
bluebutterfly.Floater = function(option) {
    this.divobj = document.getElementById(option.divid); //控件ID
    this.lrsize = option.lrsize || 0; //控件右间距
    this.direction = option.direction || "right"; //控件方向
    this.speed = option.speed || 10; //飘动速度，最小为1毫秒
    this.step = option.step || 0.1; //飘动步长，最小为0.1倍
    //====系统变量=====
    this.lastScrollX = this.lastScrollY = 0;
    this.flyObj = null
};
//飘动
bluebutterfly.Floater.prototype.fly = function() {
    var self = this;
    if (self.divobj) {
        if (self.speed < 1) {
            self.speed = 1;
        }
        if (self.direction == "right") {
            self.divobj.style.right = self.lrsize;
        }
        else {
            self.divobj.style.left = self.lrsize;
        }
        self.flyObj = window.setInterval(function() { self.flying(); }, self.speed);
    }
};
//飘动中
bluebutterfly.Floater.prototype.flying = function() {
    var self = this, percent = diffY = diffX = 0;
    diffY = document.documentElement.scrollTop;
    diffX = document.documentElement.scrollLeft;
    if (diffY != self.lastScrollY) {
        percent = self.step * (diffY - self.lastScrollY);
        if (percent > 0) {
            percent = Math.ceil(percent);
        }
        else {
            percent = Math.floor(percent);
        }
        self.divobj.style.top = (parseInt(bluebutterfly.getStyle(self.divobj, "top")) + percent) + "px";
        self.lastScrollY = self.lastScrollY + percent;
    }
    if (diffX != self.lastScrollX) {
        percent = self.step * (diffX - self.lastScrollX);
        if (percent > 0) {
            percent = Math.ceil(percent);
        }
        else {
            percent = Math.floor(percent);
        }
        self.divobj.style.left = (parseInt(bluebutterfly.getStyle(self.divobj, "left")) + percent) + "px";
        self.lastScrollX = self.lastScrollX + percent;
    }
};
//停止飘动
bluebutterfly.Floater.prototype.stop = function() {
    if (this.flyObj) {
        window.clearInterval(this.flyObj);
        this.flyObj = null;
    }
};
bluebutterfly.getStyle = function(target, stylename) {
    var curVal = "";
    if (typeof (target) != "object") {
        target = bluebutterfly.getElementById(target);
    }
    if (target.currentStyle) {
        curVal = target.currentStyle[stylename]
    }
    else {
        curVal = document.defaultView.getComputedStyle(target, null)[stylename];
    }
    return curVal;
};
var t1 = new bluebutterfly.Floater({
    "divid": "AllPageScrollTop",
    "lrsize": "98px",
    "direction": "right",
    "speed": "10",
    "step": "0.1"
});
t1.fly();
//var t2 = new bluebutterfly.Floater({
//    "divid": "floater2",
//    "lrsize": "2px",
//    "direction": "right",
//    "speed": "10",
//    "step": "0.5"
//});
//t2.fly();
//var t3 = new bluebutterfly.Floater({
//    "divid": "floater3",
//    "lrsize": "2px",
//    "direction": "left",
//    "speed": "10",
//    "step": "0.5"
//});
//t3.fly();
//t3.stop();