var Effect = new Object();
Effect.Float = {
    "items" : new Object,
    "params" :{width:"100px",height:"100px",left:"50px",top:"50px",interval:50,dirV:true,dirH:true},
    "init" : function(inner,params){
        Object.extend(this.params,params);
        var box = TPageElement.element("div",{innerHTML:inner},
        									{position:"absolute",zIndex:"999999",overflow:"hidden"
        									,backgroundColor:"white"
        									,left:this.params.left
        									,top:this.params.top
        									,width:this.params.width
        									,height:this.params.height});
        box.DirV = this.params.dirV;
        box.DirH = this.params.dirH;
        box.AutoMove = true;
        box.Seed = Math.random();
        box.Timer = setInterval("Effect.Float.execute(" + box.Seed + ")", this.params.interval);
        box.onmouseover = function(){this.AutoMove = false;}
        box.onmouseout = function(){this.AutoMove = true;}
        document.body.appendChild(box);
        
        //添加关闭按钮
        var btnClose = TPageElement.element("div",{innerHTML:"&nbsp;X&nbsp;"},{cursor:"pointer",position:"absolute",right:"0px",bottom:"0px"});
        btnClose.onclick = function(){
            this.parentNode.removeNode(box);
        }
        box.appendChild(btnClose);
        
        this.items[box.Seed] = box;
        return box;
    },
    "execute" : function(floatId){
        var ad = this.items[floatId];
        if(ad.AutoMove){
            var curLeft = parseInt(ad.style.left);
            var curTop = parseInt(ad.style.top);
            if(ad.offsetWidth + curLeft > document.body.clientWidth + document.body.scrollLeft - 1){
                curLeft = document.body.scrollLeft + document.body.clientWidth - ad.offsetWidth;
                ad.DirH = false;
            }
            if(ad.offsetHeight + curTop > document.body.clientHeight + document.body.scrollTop - 1){
                curTop = document.body.scrollTop + document.body.clientHeight - ad.offsetHeight;
                ad.DirV = false;
            }
            if(curLeft < document.body.scrollLeft){
                curLeft = document.body.scrollLeft;
                ad.DirH = true;
            }
            if(curTop < document.body.scrollTop){
                curTop = document.body.scrollTop;
                ad.DirV = true;
            }
            ad.style.left = curLeft + (ad.DirH ? 1 : -1) + "px";
            ad.style.top = curTop + (ad.DirV ? 1 : -1) + "px";
        }
    }
}

Effect.Float2 = {
    "items" : new Object,
    "params" :{width:"100px",height:"100px",left:"50px",top:"50px",interval:50,dirV:true,dirH:true},
    "init" : function(inner,params){
        Object.extend(this.params,params);
        var box = TPageElement.element("div",{innerHTML:inner},
        									{position:"absolute",zIndex:"999999",overflow:"hidden"
        									,backgroundColor:"white"
        									,left:this.params.left
        									,top:this.params.top
        									,width:this.params.width
        									,height:this.params.height});
        box.DirV = this.params.dirV;
        box.DirH = this.params.dirH;
        box.AutoMove = true;
        box.Seed = Math.random();
        box.Timer = setInterval("Effect.Float.execute(" + box.Seed + ")", this.params.interval);
        box.onmouseover = function(){this.AutoMove = false;}
        box.onmouseout = function(){this.AutoMove = true;}
        document.body.appendChild(box);
        this.items[box.Seed] = box;
        return box;
    },
    "execute" : function(floatId){
        var ad = this.items[floatId];
        if(ad.AutoMove){
            var curLeft = parseInt(ad.style.left);
            var curTop = parseInt(ad.style.top);
            if(ad.offsetWidth + curLeft > document.body.clientWidth + document.body.scrollLeft - 1){
                curLeft = document.body.scrollLeft + document.body.clientWidth - ad.offsetWidth;
                ad.DirH = false;
            }
            if(ad.offsetHeight + curTop > document.body.clientHeight + document.body.scrollTop - 1){
                curTop = document.body.scrollTop + document.body.clientHeight - ad.offsetHeight;
                ad.DirV = false;
            }
            if(curLeft < document.body.scrollLeft){
                curLeft = document.body.scrollLeft;
                ad.DirH = true;
            }
            if(curTop < document.body.scrollTop){
                curTop = document.body.scrollTop;
                ad.DirV = true;
            }
            ad.style.left = curLeft + (ad.DirH ? 1 : -1) + "px";
            ad.style.top = curTop + (ad.DirV ? 1 : -1) + "px";
        }
    }
}
