﻿//页面加载
function window.onload()   
{       
    //在当前页面创建一个div
    var dvName=document.createElement("div");
    dvName.id="dvFloat";
    dvName.onclick=function(){OpenWindow()};
    dvName.style.position="absolute";
    dvName.style.Zindex="10000";//样式设置
    dvName.style.cursor="hand";//光标为手形

    //添加图片
    image="<img src='http://www.724kf.com/images/ico/"+style["size"]+"/"+style["color"]+".gif'/>";
//image="<img src='images/"+style["color"]+".gif'/>";
    dvName.innerHTML=image;
    //加载到body上
    document.body.appendChild(dvName); 
    //设置位置
    SetPicPosition();
}
//窗体改变大小之后
function window.onresize()
{
    //设置位置
    SetPicPosition();
}
//点击图标之后出现对话框
 function OpenWindow() 
{
    open("http://www.724kf.com/OpenWindow.aspx?lasturl="+document.URL+"&username="+style["user"]+"","_media","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=600,height=515");
    //如果在index.aspx页面测试时可以去掉../ 不然会路径错误
//    open("OpenWindow.aspx?lasturl="+document.URL+"&username="+style["user"]+"","_media","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=620,height=411");
}
//根据可视窗口的宽和高设置浮动图标的位置
function SetPicPosition()
{
     //存放图标在可视区域的宽和高s
    var viewWidth =0;
	var viewHeight =0;
    if(style["type"]=="float")
    { 
        //设置浮动标签的位置和样式
        if(style["position"]=="left")
        {
            viewWidth=10;
            viewHeight=getViewHeight()/3;
        }
        else
        {
            viewWidth=getViewWidth()-120;
            viewHeight=getViewHeight()/3;
        }
        //调用滚动事件
        FloatTop(viewWidth,viewHeight);
    }
    else
    {        
        //将标签固定在某个位置
        if(style["position"]=="left")
        {
            document.getElementById("dvFloat").style.clear="both";
            document.getElementById("dvFloat").style.left="10px";
            document.getElementById("dvFloat").style.top=getViewHeight()/2+"px";
        }
        else
        {
            document.getElementById("dvFloat").style.clear="both";
            document.getElementById("dvFloat").style.right="10px";
            document.getElementById("dvFloat").style.top=getViewHeight()/2+"px";
        }
    } 
}
//获得可视窗口的高度
function getViewHeight()
{
    var height=0;
    if(window.innerWidth)//除IE之外的所有浏览器
    {
        height=window.innerHeight;
    }
    else if(document.documentElement&&document.documentElement.clientWidth)//IE6并存在DOCTYPE
    {
        height=document.documentElement.clientHeight;
    }
    else if(document.body.clientWidth)//IE4,IE5,IE6 without a DOCTYPE
    {
        height=document.body.clientHeight; 
    }
    return height;
}
//获得可视窗口的宽度
function getViewWidth()
{
    var width=0;
    if(window.innerWidth)//除IE之外的所有浏览器
    {
        width=window.innerWidth;
    }
    else if(document.documentElement&&document.documentElement.clientWidth)//IE6并存在DOCTYPE
    {
        width=document.documentElement.clientWidth;
    }
    else if(document.body.clientWidth)//IE4,IE5,IE6 without a DOCTYPE
    {
        width=document.body.clientWidth; 
    }
    return width;
}
//滚动事件的具体实现
 function FloatTop(viewWidth,viewHeight)
{
	function SetPosition(idName,imgCurrWidth,imgCurrHeight,direct)
	{
	    //当前对象相对于电脑屏幕的x坐标，y坐标         
		document.getElementById(idName).sP=function(x,y){this.style.left=x;this.style.top=y;};		
		//当前对象在可视区域的X坐标
        document.getElementById(idName).x=imgCurrWidth;
		//当前对象在可视区域的Y坐标
		document.getElementById(idName).y = imgCurrHeight;//打开网页时的高度
		//返回当前对象div
		
		return document.getElementById(idName);
	}
	//刷新时从何处出发
	if(style["position"]=="left")
	    var imgObj = SetPosition("dvFloat",10,getViewHeight()/3);
	else
	    var imgObj=SetPosition("dvFloat",getViewWidth()-120,getViewHeight()/3);
	window.stayTopLeft=function()
	{
		var currHeight=getScrollTop();//获取滚动条的高度
		var currWidth=getScrollLeft();//获取滚动条的宽度
		imgObj.x += (currWidth + viewWidth - imgObj.x)/10;
		imgObj.y += (currHeight + viewHeight - imgObj.y)/10;
		imgObj.sP(imgObj.x, imgObj.y);
		setTimeout("stayTopLeft()", 30);
	}            
	stayTopLeft();	
	//获取滚动条的高度
	function getScrollTop()
    {
        var scrollTop=0;
        if(window.innerWidth)
        {
            scrollTop=window.pageYOffset;
        }
        else if(document.documentElement&&document.documentElement.scrollTop)
        {
            scrollTop=document.documentElement.scrollTop;
        }
        else if(document.body)
        {
            scrollTop=document.body.scrollTop;
        }
        return scrollTop;
    }
    //获取滚动条的宽度
	function getScrollLeft()
    {
        var scrollLeft=0;
        if(window.innerWidth)
        {
            scrollLeft=window.pageXOffset;
        }
        else if(document.documentElement&&document.documentElement.scrollLeft)
        {
            scrollLeft=document.documentElement.scrollLeft;
        }
        else if(document.body)
        {
            scrollLeft=document.body.scrollLeft;
        }
        return scrollLeft;
    }
}