﻿//<![CDATA[
$(
    function () {
        NavigationDL();
        FuImgLoad();
        FuSkinBtnLoad();
    }
);
//统计位置移动
$(window).load(
        function () {
            $("#WebCountText").show();
        }
);
//下拉导航
function NavigationDL() {
    var $NavDl = $("#Navigation dl");
    $("dt a").mouseover(
    function (e) {
        $(this).parent().parent().children("dd").stop(true, true).slideDown("fast");
    });
    $("#Navigation dl").mouseleave(
    function (e) {
        $(this).children("dd").stop(true, true).slideUp("fast");
    });
}
//图片缓冲
function FuImgLoad() {
    $("img:[class=load]").each(
        function () {
            var $img = $(this);
            var $LoadSrc = $img.attr("src");
            $img.attr("src", "/Style/images/loading.gif");
            $img.bind("MyLoad", { "imgsrc": $LoadSrc },
                function (e) {
                    var loadImg = new Image();
                    loadImg.onload = function () {
                        $img.attr("src", loadImg.src);
                        if ($img.attr("mywidth")) {
                            $img.css("width", $img.attr("mywidth"));
                        }
                        if ($img.attr("myheight")) {
                            $img.css("height", $img.attr("myheight"));
                        }
                    }
                    loadImg.onerror = function () {
                        $img.attr("src", "错误图片地址");
                    }
                    loadImg.src = e.data.imgsrc;
                }
            );
        }
    );
    $(window).load(
        function () {
            $("img:[class=load]").trigger("MyLoad");
        }
    );
}
//样式切换功能
function FuSkinBtnLoad() {
    var $SkinBtn = $("#skin a");
    $SkinBtn.click(
                function (e) {
                    var $ThisClick = $(this);
                    var $BtnID = $ThisClick.parent().attr("id");
                    $SkinBtn.removeClass("Selected");
                    $ThisClick.addClass("Selected");
                    $("#LinkStyleHerf").attr("href", "/Style/Skin/" + $BtnID + "/css.css");
                    SetCookie("skin", $BtnID);
                    e.preventDefault();
                }
            );
    var CookieID = GetCookie("skin");
    if (CookieID.length > 0) {
        $("#" + CookieID + " a").click();
    }
    else {
        $("#skin1 a").click();
    }
}
//设置Cookie数值
function SetCookie(name, value) {
    document.cookie = name + "=" + value + ";expires=" + new Date(new Date().getTime() + 31536000000).toGMTString() + ";path=/";
}
//读取Cookie数值
function GetCookie(name) {
    var cookieValue = "";
    var search = name + "=";
    if (document.cookie.length > 0) {
        var offset = document.cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            var end = document.cookie.indexOf(";", offset);
            if (end == -1) {
                end = document.cookie.length;
            }
            cookieValue = unescape(document.cookie.substring(offset, end));
        }
    }
    return cookieValue;
}
//]]>


