﻿// JScript 文件

//跟着屏幕滚动的层
/*
默认为alertdiv,confirmdiv
    需要滚动的DIV可添加scroll样式，即可随屏幕动。
    建议将DIV增加一个defaultheight这样的属性，方便第一次调用时候显示的高度，
其他则调用方法scrollById();

*/
$(document).ready(function(){
    scrollById("alertdiv");
    scrollById("confirmdiv");
    scrollById("addfdiv");
    scrollById("logindiv1");
    scrollById("photoDiv");
    
    $(".scroll").each(function(i,n){
        scrollById(n.id,$(n).attr("defaultheight"));
    });
});

function scrollById(id,defaultheight)
{
    toscroll(id,defaultheight);
    $(window).scroll(function(){
        toscroll(id,defaultheight);
    });
}

function toscroll(id,defaultheight)
{
    try
    {
        var con = document.getElementById(id);
        if(con)
        {
            //var height = 0;
            var height = window.screen.availHeight - 150;/*屏幕可用高度，150的工具栏高度*/
            var scrolltop = document.documentElement.scrollTop + document.body.scrollTop;/*滚动条高度*/
            //var scrolltop = document.documentElement.scrollTop;
            var conheight = $("#"+id).height();/*内容的高度*/
            
            if(defaultheight==null)
                conheight= conheight<20?300:conheight;
            else
                conheight=defaultheight;
            
            
            var settop = $("#"+id).attr("settop");
            if(settop==null || settop == "")
            {
                $("#"+id).css("top",height/2 + scrolltop - conheight/2);
            }
            else
            {
                //alert(parseInt(settop)+scrolltop);
                $("#"+id).css("top",parseInt(settop)+scrolltop);
            }
        }
    }catch (e) {
	}
}
