﻿(function(window){
    var document = window.document;
    var floatWindow = (function(){
        var floatWindow = function(_src,_url,_width,_height,_alt) {
            return new floatWindow.fn.init(_src,_url,_width,_height,_alt);
        };
        var step = 1; 
        //速度----[值越大速度越慢]
        var delay = 5;                          
        var browserWidth;
        var browserHeight;
        floatWindow.hbcms_changePos = function(){
            this.Hoffset = this.obj.offsetHeight; 
            this.Woffset = this.obj.offsetWidth; 
            this.obj.style.left = this.xPos + (document.body.scrollLeft||document.documentElement.scrollLeft); 
            this.obj.style.top = this.yPos + (document.body.scrollTop||document.documentElement.scrollTop); 
            if (this.yon) { 
                this.yPos = this.yPos + step; 
            } 
            else { 
                this.yPos = this.yPos - step; 
            } 
            if (this.yPos < 0) { 
                this.yon = 1; 
                this.yPos = 0; 
            } 
            if (this.yPos >= (browserHeight - this.Hoffset)) { 
                this.yon = 0; 
                this.yPos = (browserHeight - this.Hoffset); 
            } 
            if (this.xon) { 
                this.xPos = this.xPos + step; 
            } 
            else { 
                this.xPos = this.xPos - step; 
            } 
            if (this.xPos < 0) { 
                this.xon = 1; 
                this.xPos = 0; 
            } 
            if (this.xPos >= (browserWidth - this.Woffset)) { 
                this.xon = 0; 
                this.xPos = (browserWidth - this.Woffset); 
            } 
        };
        floatWindow.pause_resume = function() { 
            var that = this;
            if(this.pause) {
                window.clearInterval(this.interval);
                this.pause = false;
            } 
            else {
                this.interval = window.setInterval(function(){floatWindow.hbcms_changePos.apply(that)},delay);
                this.pause = true;
            } 
        };
        floatWindow.close = function(id,interval) {
            var obj = document.getElementById(id);
            obj.style.display = "none";
            window.clearInterval(interval);
        };
        floatWindow.hbcms_start_pp = function() {
            var that = this;
            this.obj.style.display = "block";
            this.interval = window.setInterval(function(){floatWindow.hbcms_changePos.apply(that)}, delay); 
        };
        floatWindow.fn = floatWindow.prototype = {
            constructor:"floatWindow",
            init : function(_src,_url,_width,_height,_alt) {
                browserWidth = document.body.clientWidth||document.documentElement.clientWidth;
                browserHeight = document.body.clientHeight||document.documentElement.clientHeight;  
                            
                this.id = "float" + Date.prototype.getMilliseconds()+""+ Math.floor(Math.random()*100000);
                this.src = _src || "";
                this.url = _url || "";
                this.width = _width || "";
                this.height = _height || "";
                this.alt = _alt || "";
                
                this.xPos;
                this.yPos;                    
                this.pause = true; 
                this.interval; 
                this.Hoffset = 0; 
                this.Woffset = 0; 
                this.yon = 0; 
                this.xon = 0; 
                this.obj;
            },
            LeftBottom2RightTop:function() {
                document.writeln('<div id="'+this.id+'" style="left:2px;position:absolute;top:80px; width:'+this.width+'px; height:'+(this.height+20)+'px; z-index:9;"> ');
                document.writeln('  <div onclick="floatWindow.close(\''+this.id+'\',\''+this.interval+'\');" style="font-weight:bolder; font-size:13px;height:20px; color:#000; width:'+this.width+'px;cursor:pointer;text-align:right;padding-right:10px;">关闭</div>');
                document.writeln('  <div><a href="'+this.url+'" target="_blank"><img src="'+this.src+'" width="'+this.width+'" height="'+this.height+'" border="0" alt="'+this.alt+'" ></a></div> ');
                document.writeln('</div>'); 
                
                this.xPos = 0;
                this.yPos = browserHeight-(this.height+20);  
                              
                this.obj = document.getElementById(this.id);
                this.obj.style.left = this.xPos;
                this.obj.style.top = this.yPos;
                
                var that = this;
                this.obj.onmouseover = function(){
                    floatWindow.pause_resume.apply(that);
                }
                this.obj.onmouseout = function(){
                    floatWindow.pause_resume.apply(that);
                }
                
                floatWindow.hbcms_start_pp.apply(this);
            },
            LeftTop2RightBottom:function() {
                document.writeln('<div id="'+this.id+'" style="left:2px;position:absolute;top:80px; width:'+this.width+'px; height:'+(this.height+20)+'px; z-index:9;"> ');
                document.writeln('  <div onclick="floatWindow.close(\''+this.id+'\',\''+this.interval+'\');" style="font-weight:bolder; font-size:13px;height:20px; color:#000; width:'+this.width+'px;cursor:pointer;text-align:right;padding-right:10px;">关闭</div>');
                document.writeln('  <div><a href="'+this.url+'" target="_blank"><img src="'+this.src+'" width="'+this.width+'" height="'+this.height+'" border="0" alt="'+this.alt+'" ></a></div> ');
                document.writeln('</div>'); 
                
                this.xPos = 0;
                this.yPos = 0;  
                              
                this.obj = document.getElementById(this.id);
                this.obj.style.left = this.xPos;
                this.obj.style.top = this.yPos;
                
                var that = this;
                this.obj.onmouseover = function(){
                    floatWindow.pause_resume.apply(that);
                }
                this.obj.onmouseout = function(){
                    floatWindow.pause_resume.apply(that);
                }
                
                floatWindow.hbcms_start_pp.apply(this);            
            },
            RightBottom2LeftTop:function() {
                document.writeln('<div id="'+this.id+'" style="left:2px;position:absolute;top:80px; width:'+this.width+'px; height:'+(this.height+20)+'px; z-index:9;"> ');
                document.writeln('  <div onclick="floatWindow.close(\''+this.id+'\',\''+this.interval+'\');" style="font-weight:bolder; font-size:13px;height:20px; color:#000; width:'+this.width+'px;cursor:pointer;text-align:right;padding-right:10px;">关闭</div>');
                document.writeln('  <div><a href="'+this.url+'" target="_blank"><img src="'+this.src+'" width="'+this.width+'" height="'+this.height+'" border="0" alt="'+this.alt+'" ></a></div> ');
                document.writeln('</div>'); 
                
                this.xPos = browserWidth-this.width;
                this.yPos = browserHeight-(this.height+20);  
                              
                this.obj = document.getElementById(this.id);
                this.obj.style.left = this.xPos;
                this.obj.style.top = this.yPos;
                
                var that = this;
                this.obj.onmouseover = function(){
                    floatWindow.pause_resume.apply(that);
                }
                this.obj.onmouseout = function(){
                    floatWindow.pause_resume.apply(that);
                }
                
                floatWindow.hbcms_start_pp.apply(this);              
            },
            RightTop2LeftBottom:function() {
                document.writeln('<div id="'+this.id+'" style="left:2px;position:absolute;top:80px; width:'+this.width+'px; height:'+(this.height+20)+'px; z-index:9;"> ');
                document.writeln('  <div onclick="floatWindow.close(\''+this.id+'\',\''+this.interval+'\');" style="font-weight:bolder; font-size:13px;height:20px; color:#000; width:'+this.width+'px;cursor:pointer;text-align:right;padding-right:10px;">关闭</div>');
                document.writeln('  <div><a href="'+this.url+'" target="_blank"><img src="'+this.src+'" width="'+this.width+'" height="'+this.height+'" border="0" alt="'+this.alt+'" ></a></div> ');
                document.writeln('</div>'); 

                this.xPos = browserWidth-this.width;
                this.yPos = 0;  
                              
                this.obj = document.getElementById(this.id);
                this.obj.style.left = this.xPos;
                this.obj.style.top = this.yPos;
                
                var that = this;
                this.obj.onmouseover = function(){
                    floatWindow.pause_resume.apply(that);
                }
                this.obj.onmouseout = function(){
                    floatWindow.pause_resume.apply(that);
                }
                
                floatWindow.hbcms_start_pp.apply(this);              
            }
        };
        floatWindow.fn.init.prototype = floatWindow.fn;
        
        return floatWindow;
    })(); 
    window.floatWindow = floatWindow; 
})(window);      


