
	//可以打包为js文件;
	var x0=0,y0=0,x1=0,y1=0;
	var offx=6,offy=6;
	var moveable=false;
	var hover='orange',normal='slategray';//color;
	var index=10000;//z-index;
	var operationStr="click";//drag、click
	var xx;
	//窗口初始化top位置
	var win_style_top="162px";
	var ddest=document.documentElement.scrollTop;
	var ddesl=document.documentElement.scrollLeft;
	var picHeight=135;
	var picWidth=96;
	//开始拖动;
	function startDrag(obj){				
	        if(event.button==1){
	                //锁定标题栏;
	                obj.setCapture();
	                //定义对象;
	                var win=obj.parentNode.parentNode;
	                //记录鼠标和层位置;
	                x0 = event.clientX;
	                y0 = event.clientY;
	                x1 = parseInt(win.style.left);
	                y1 = parseInt(win.style.top);
	                //改变风格;
	                moveable = true;
	        }
	}
	//拖动;
	function drag(obj){
	        if(moveable){
	                var win=obj.parentNode.parentNode;
	                var availWidth = window.screen.availWidth;
	                //保证左右只能在当前看的见得页面移动
	                var dragX=event.clientX - x0;//鼠标拖动距离
	                var leftX=x1+dragX;//拖动前的位置+鼠标拖动的距离=拖动后的实际距离             
	                if(
	                	leftX>(0+document.documentElement.scrollLeft)//当滚动条像左滚动的距离
	                	&& leftX<document.body.clientWidth-picWidth+document.documentElement.scrollLeft){ 	
						win.style.left=leftX;
	                }else{
	                	if( leftX>=document.body.clientWidth-picWidth+document.documentElement.scrollLeft){
	                		win.style.left=document.body.clientWidth-picWidth+document.documentElement.scrollLeft;
	                	}else{
	                		win.style.left = document.documentElement.scrollLeft+"px";
	                	}
	                }
	                
	                //保证只能在工作区间移动
	               //如果不是全屏页面那么需要减掉
	                var dragY=event.clientY - y0;//鼠标拖动距离
	                var topY=y1+dragY;//拖动前的位置+鼠标拖动的距离=拖动后的实际距离 
	                if (topY>(0+document.documentElement.scrollTop) 
	                    && topY<(document.documentElement.offsetHeight-picHeight+document.documentElement.scrollTop)){
	                	win.style.top  = topY;
	                }else{
	                	if( topY>=document.documentElement.offsetHeight-picHeight+document.documentElement.scrollTop){
	                		win.style.top=document.documentElement.offsetHeight-picHeight+document.documentElement.scrollTop;
	                	}else{
	                		win.style.top = document.documentElement.scrollTop+"px";
	                	}
	                }
					operationStr="drag";
	        }
	}
	//停止拖动;
	function stopDrag(obj){
	        if(moveable){
	            
	            obj.releaseCapture();
	            moveable = false;
	        }
			if(operationStr=='click'){
				openServicePage();
			}
			operationStr="click";
			//判断如果有移动，那么就不打开窗口	
	}
	window.onload = initialize;
	window.onresize=resizeEvent;
	window.onscroll=scrollEvent;
	var pageHeight;
	var pageWidth;
	 function initialize(){
       new xWin("1",picWidth,picHeight,0,0,"","");
       pageHeight=document.documentElement.offsetHeight;
	   pageWidth=document.documentElement.offsetWidth;
       initWinPosition();
       	//printStr();
       	
    }
    var timer=null;
	function scrollEvent(){
			if(timer!=null){
				clearTimeout(timer);
			}
			timer = setTimeout("locationWin()",50);	
	}
	
	 
	function locationWin(){
		var win = document.getElementById("serviceWin");
		var offsetT=document.documentElement.scrollTop-ddest;
		var offsetL=document.documentElement.scrollLeft-ddesl;
		if(parseInt(win.style.top)+offsetT<=0){
			win.style.top=document.documentElement.scrollTop+"px";
		}else{
			win.style.top=(parseInt(win.style.top)+offsetT)+"px";
		}
		if(parseInt(win.style.left)+offsetL<=0){
    		win.style.left=document.documentElement.scrollLeft+"px";
    	}else{
    		win.style.left=(parseInt(win.style.left)+offsetL)+"px";
    	}
    	ddest=document.documentElement.scrollTop;
	    ddesl=document.documentElement.scrollLeft; 
	}
	
	function initWinPosition(){
		//计算屏幕的高度，然后定位div的位置
       var win = document.getElementById("serviceWin");
       //162图片离屏幕的顶部的高度
       //alert(win_style_top+picHeight);
       //alert(document.documentElement.offsetHeight);
       if(parseInt(win_style_top)+picHeight>document.documentElement.offsetHeight){//如果win_style_top加上图片的高度>大于页面高度，那么就直接定位在底部
       	  win.style.top = document.documentElement.scrollTop+"0px";
       }else{
       	  win.style.top = win_style_top;
       }
       //屏幕可见区域的宽
	   var cw=document.body.offsetWidth;//包括边线和滚动条的宽
	   //96 图片的宽度
	   //if(cw-picWidth<0){
	   	win.style.left = ((cw-picWidth)+document.documentElement.scrollLeft)+"px";
	   //}
	   //printStr();
	}
	
	function setObjePosi(){
		var win = document.getElementById("serviceWin");
		var currentPageHeight=document.documentElement.offsetHeight;
	    var currentPageWidth=document.documentElement.offsetWidth;
	    var offsetHeight=currentPageHeight-pageHeight;
	    var offsetWidth=currentPageWidth-pageWidth;
	    //alert("top:"+(parseInt(win.style.top)+offsetHeight));
	    //alert("left:"+(parseInt(win.style.left)+offsetWidth));
	    if(parseInt(win.style.top)+offsetHeight<document.documentElement.scrollTop){
	    	win.style.top=document.documentElement.scrollTop+"px";
	    }else{
	    	 win.style.top=parseInt(win.style.top)+offsetHeight;
	    }
	    if(parseInt(win.style.left)+offsetWidth<document.documentElement.scrollLeft){
	    	win.style.left=document.documentElement.scrollLeft+"px";
	    }else{
	    	win.style.left=parseInt(win.style.left)+offsetWidth;
	    }
	    pageHeight=currentPageHeight;
	    pageWidth=currentPageWidth;
	   //printStr();
	}
	var resizeFlag=false;
	function resizeEvent(){
		//alert(event.clientX)
		if(resizeFlag || true){
			flag=true;
			setObjePosi();
			resizeFlag=false;
			//printStr();
		}else{
			resizeFlag=true;
		}
	}
	
	
	//创建一个对象;
function xWin(id,w,h,l,t,tit,msg)
{
        index = index+2;
        this.id      = id;
        this.width   = w;
        this.height  = h;
        this.left    = l;
        this.top     = t;
        this.zIndex  = index;
        this.title   = tit;
        this.message = msg;
        this.obj     = null;
        this.bulid   = bulid;
        this.bulid();
        xx = document.getElementById('allx');
        xx.style.visibility = "visible";

}
//初始化;
function bulid(){
        var str = ""
                + "<div id='allx' style='cursor:pointer;'><div id='xMsg'" + this.id + " "
                + "style='"
                + "z-index:" + this.zIndex + ";"
                + "width:" + this.width + ";"
                + "height:" + this.height + ";"
                + "left:" + this.left + ";"
                + "top:" + this.top + ";"
                + "cursor:pointer;"
                + "color:" + normal + ";"
                + "font-size:11px;"
                + "font-family:Verdana;"
                + "position:absolute;"
                + "border:0px solid " + normal + ";"
                + "' "
                + "onmousedown='startDrag(this)' onmouseup='stopDrag(this)' onmousemove='drag(this)'>"
                +"<img src='/liantuo/images/currency-ico/service_0902.jpg'/>"
                + "</div>"
                +"</div>";
        document.getElementById('serviceWin').innerHTML = str;              
}
function openServicePage(){
	window.open("http://b.qq.com/webc.htm?new=0&sid=938076018&o=www.51book.com&q=7', '_blank', 'height=544, width=644,toolbar=no,scrollbars=no,menubar=no,status=no")
}
	function printStr(){
       	var       s   =   "";   
				  s   +=   "\r\n网页可见区域宽document.body.clientWidth："+   document.body.clientWidth;   
				  s   +=   "\r\n网页可见区域高document.body.clientHeight："+   document.body.clientHeight;   
				  s   +=   "\r\n网页可见区域宽document.body.offsetWidth："+   document.body.offsetWidth     +"   (包括边线和滚动条的宽)";   
				  s   +=   "\r\n网页可见区域高document.body.offsetHeight："+   document.body.offsetHeight   +"   (包括边线的高)"; 
				  s   +=   "\r\n网页可见区域高document.documentElement.clientHeight："+   document.documentElement.clientHeight   +" ";  
				  s   +=   "\r\n网页可见区域高document.documentElement.offsetHeight："+   document.documentElement.offsetHeight   +" ";
				  s   +=   "\r\n网页正文全文宽document.body.scrollWidth："+   document.body.scrollWidth;   
				  s   +=   "\r\n网页正文全文高document.body.scrollHeight："+   document.body.scrollHeight;   
				  s   +=   "\r\n网页被卷去的高document.body.scrollTop："+   document.body.scrollTop;   
				  s   +=   "\r\n网页被卷去的左document.body.scrollLeft："+   document.body.scrollLeft;   
				  s   +=   "\r\n网页正文部分上window.screenTop："+   window.screenTop;   
				  s   +=   "\r\n网页正文部分左window.screenLeft："+   window.screenLeft;   
				  s   +=   "\r\n屏幕分辨率的高window.screen.height："+   window.screen.height;   
				  s   +=   "\r\n屏幕分辨率的宽window.screen.width："+   window.screen.width;   
				  s   +=   "\r\n屏幕可用工作区高度window.screen.availHeight："+   window.screen.availHeight;   
				  s   +=   "\r\n屏幕可用工作区宽度window.screen.availWidth："+   window.screen.availWidth;
				  s   +=   "\r\n屏幕可用工作区宽度window.height："+   window.screenBottom;
				  s   +=   "\r\n你的屏幕设置是window.screen.colorDepth   "+   window.screen.colorDepth   +"   位彩色";   
				  s   +=   "\r\n你的屏幕设置 window.screen.deviceXDPI  "+   window.screen.deviceXDPI   +"   像素/英寸";   
				  alert(s);   
    }

