// jquery文本框类css控制
$(document).ready(function () {

    $("input,textarea").focus(function () {
        $(this).addClass("sffocus");
    });
    $("input,textarea").blur(function () {
        $(this).removeClass("sffocus");
    });

});

//打印
function Print() {
    bdhtml = window.document.body.innerHTML;
    sprnstr = "<!--startprint-->";
    eprnstr = "<!--endprint-->";
    prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
    prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
    window.document.body.innerHTML = prnhtml;
    window.print();
}

//添加收藏夹
function AddFavorite(sURL, sTitle) {
    try {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e) {
        try {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

//设为首页
function SetHome(obj, vrl) {
    try {
        obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vrl);
    }
    catch (e) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', vrl);
        }
    }
}

$(function () {
    //获取当前浏览器的宽度
    var winWidth = $(window).width();
    //获取当前浏览器的高度
    var winHeight = $(window).height();
    //标题层的高度--提示打开或关闭
    var titHeight = $("#ditTitle").height();
    //内容层的高度
    var conHeight = $("#divContent").height();
    //临时变量,存储内容层的高度
    var temp = conHeight;
    //alert(conHeight);
    //加载时设置层的位置
    $("#msgDiv").css({ top: $(window).height() - $("#ditTitle").height(), left: $(window).width() - $("#ditTitle").width() - 16 });
    //窗体改变大小时,重新设置
    $(window).resize(function () {
        //重新获取窗口的宽高
        winWidth = $(window).width();
        winHeight = $(window).height();
        $("#msgDiv").css({ top: winHeight - $("#ditTitle").height() - conHeight, left: winWidth - $("#ditTitle").width() - 16 });
    });
    $(window).scroll(function () {
        //重新获取窗口的宽高
        winWidth = $(window).width();
        winHeight = $(window).height();
        $("#msgDiv").css({ top: winHeight - $("#ditTitle").height() - conHeight + $(window).scrollTop() });
    });
    //打开过关闭
    $("#close").toggle(function () {
        //改变提示
        $("#close").text("关闭");
        //还原内容层的高度
        //alert(titHeight+conHeight);
        //return;
        $("#divContent").height(temp);
        conHeight = temp;
        //动画--一秒内消息层高度增加,top增加
        //$("#msgDiv").height($(this).height()+temp);
        $("#msgDiv").animate({ top: winHeight - titHeight - conHeight + $(window).scrollTop(), height: titHeight + conHeight }, 1000, function () {
            //展开后执行的函数
        });
    }, function () {
        //改变提示 
        $("#close").text("打开");
        //alert(temp+" "+titHeight);
        $("#msgDiv").animate({ top: winHeight - titHeight + $(window).scrollTop(), height: titHeight }, 1000, function () {
            //关闭后执行的函数
            conHeight = 0;
            //设置内容层的高度为0
            $("#divContent").height(0);
        });
    })
    //执行
    var myTimer, i = 0;
    function starFun() {
        //触发click事件,显示
        if (i == 2) {
            $("#close").click();
        }
        //清除timeout,触发click事件,关闭层
        if (i == 22) {
            i = -15;
            window.clearTimeout(myTimer);
            if ($("#close").text() != "打开")
                $("#close").click();            
        }
        myTimer = window.setTimeout(starFun, 1000);
        i = i + 1;
    }
    starFun();
});
