﻿SJ = {
    Init: function () {
        $(".menubox").children().each(function () {
            $(this).hover(function () {
                var xs = $(this).find("li").size() / 4;
                var zs = parseInt($(this).find("li").size() / 4);
                if (xs > zs)
                { zs = zs + 1; }
                if (zs > 1) {
                    $(this).find(".menuchildUl").css("width", 450);
                }
                else {
                    var licount = $(this).find(".menuchildUl").find("li").size();
                    $(this).find(".menuchildUl").css("width", licount * 110);
                }
                $(this).find(".menuchildUl").css("height", zs * 30);
                $(this).find(".childMenuUl").slideDown();
            }, function () {
                $(this).find(".childMenuUl").slideUp();
            });
        });

        $('.menubox li').mousemove(function () {
            $(this).find('ul').show(); //you can give it a speed
        });
        $('.menubox li').mouseleave(function () {
            $(this).find('ul').hide();
        });
        $("#flink").change(function () {
            var val = $(this).val();
            window.open(val);
        });
        //菜单初始化
        $(".indexlist").find("a").each(function () {
            $(this).text(CommFun.CuteString($(this).text(), 27));
        });
        $(".newslist").find("a").each(function () {
            $(this).text(CommFun.CuteString($(this).text(), 40));
        });
        $(".rightbottonlist").find("a").each(function () {
            $(this).text(CommFun.CuteString($(this).text(), 35));
        });
        $(".imageshowli").find("span").each(function () {
            $(this).text(CommFun.CuteString($(this).text(), 25));
        });
        //信息初始化
        $("#CompanyDescription_a").text(CommFun.CuteString($("#CompanyDescription_a").text(), 400));
        $("#CompanyCulture_a").text(CommFun.CuteString($("#CompanyCulture_a").text(), 400));
        //        $("#CompanyCultureDiv").mouseover(function () {
        //            $("#CompanyDescription_a").hide();
        //            $("#CompanyCulture_a").show();
        //        });
        //        $("#CompanyDescriptionDiv").mouseover(function () {
        //            $("#CompanyCulture_a").hide();
        //            $("#CompanyDescription_a").show();
        //        });
        $(".companyInfo").hover(function () {
            $(this).find("img").attr("src", "/Content/Font/images/kabgred.gif");
        }, function () { $(this).find("img").attr("src", "/Content/Font/images/kabg.gif"); });
        //ImageShow
        $('.tip').mouseover(function () {
            var $tip = $('<div id="tip"><div class="t_box"><div><s><i></i></s><img src="' + this.src + '" /></div></div></div>');
            $('body').append($tip);
            $('#tip').show('fast');
        }).mouseout(function () {
            $('#tip').remove();
        }).mousemove(function (e) {
            $('#tip').css({ "top": (e.pageY - 60) + "px", "left": (e.pageX + 30) + "px" })
        })
    },
    LeaveMessage: function () {
        var title = $(".msgTitle").val();
        var content = $(".msgContent").val();
        if (title.length == 0 || content.length == 0) {
            alert("标题或内容不能为空");
            return;
        }
        else {
            $.post("/AsynHandle/LeaveMessage", { title: title, content: content, type: 1 }, function (data) {
                if (data == "s") {
                    alert("留言成功提交！");
                }
            });
        }
    }
}
CommFun = {
    CuteString: function (str, len) {
        var str_length = 0;
        var str_len = 0;
        str_cut = new String();
        str_len = str.length;
        for (var i = 0; i < str_len; i++) {
            a = str.charAt(i);
            str_length++;
            if (escape(a).length > 4) {
                str_length++;
            }
            str_cut = str_cut.concat(a);
            if (str_length > len) {
                str_cut = str_cut.substring(0, str_cut.length - 1).concat("...");
                return str_cut;
            }
        }
        if (str_length < len) {
            return str;
        }
    }
},
MyImage = {
    BindEvent: function (titleId, countId, listId) {
        var titleObj = $("#" + titleId);
        var listObj = $("#" + listId);
        var countObj = $("#" + countId);
        countObj.find("li").each(function () {
            $(this).bind("click", function () {
                listObj.find("img").hide();
                countObj.find("li").removeClass("on");
                $(this).attr("class", "on");
                var nowCount = $(this).text() - 1; //获取Li元素内的值，即1，2，3，4
                var nowImg = $(listObj.find("img")[nowCount]);
                titleObj.html(nowImg.attr("title"));
                nowImg.fadeIn(500);

            });

        });
    },
    ImagePlay: function (titleId, countId, listId, n) {
        var titleObj = $("#" + titleId);
        var listObj = $("#" + listId);
        var countObj = $("#" + countId);
        var allCount = listObj.find("img").size();
        var nowImg = $(listObj.find("img")[n]);
        if (countObj.find("li").size() > 0) {
            countObj.find("li").removeClass("on");
            $(countObj.find("li")[n]).attr("class", "on");
        }
        titleObj.html(nowImg.attr("title"));
        listObj.find("img").fadeOut(1000);
        nowImg.fadeIn(4500);
    }
}

