﻿$(function() {
    var _li = "<li class='{0}'>{1}：{2}</li>";
    var _A = "<a href='{0}' target='_blank'>{1}</a>";
    var _Option = "<option value='{0}'>{1}</option>";
    var temp = ""; //用于临时存储学习中心的A标签集合

    if (!!SHOOLCITY) {
        for (var i = 0; i < SHOOLCITY.length; i++) {

            //获取校区下所有的学习中心，拼成 A标签的集合
            temp = "";
            if(i==0)
            {
                var shoolItems = GetShoolAddressByCityID(SHOOLCITY[i].PKID);

                $.each(shoolItems, function() {
                    temp += _A.replace("{0}", "/shoolinfo_" + this.PKID + ".htm").
                                       replace("{1}", this.SHOOLNAME);
                });
            }
            if(i + 1 == 2 || i + 1 == 6 || i + 1 == 10 || i + 1 == 14)
            {
                 var shoolItems = GetShoolAddressByCityID(SHOOLCITY[i].PKID, 8);

                $.each(shoolItems, function() {
                    temp += _A.replace("{0}", "/shoolinfo_" + this.PKID + ".htm").
                                      replace("{1}", this.SHOOLNAME);
                });
            }
            if(i + 1 == 3 || i + 1 == 7 || i + 1 == 11 || i + 1 == 15)
            {
                var shoolItems = GetShoolAddressByCityID(SHOOLCITY[i].PKID, 3);

                $.each(shoolItems, function() {
                    temp += _A.replace("{0}", "/shoolinfo_" + this.PKID + ".htm").
                                      replace("{1}", this.SHOOLNAME);
                });
            }
            if(i + 1 == 4 || i + 1 == 8 || i + 1 == 12 || i + 1 == 16)
            {
                 var shoolItems = GetShoolAddressByCityID(SHOOLCITY[i].PKID, 3);

                $.each(shoolItems, function() {
                    temp += _A.replace("{0}", "/shoolinfo_" + this.PKID + ".htm").
                                      replace("{1}", this.SHOOLNAME);
                });
            }
            if(i + 1 == 5 || i + 1 == 9 || i + 1 == 13|| i + 1 == 17)
            {
                 var shoolItems = GetShoolAddressByCityID(SHOOLCITY[i].PKID, 3);

                $.each(shoolItems, function() {
                    temp += _A.replace("{0}", "/shoolinfo_" + this.PKID + ".htm").
                                      replace("{1}", this.SHOOLNAME);
                });
            }


            //拼成所有校区,神奇代码（精通算法可重构）
            $("#showname_m").append("<ul>" +
            _li.replace("{0}", "hm" + (i != 0 ? ((i + 1 == 2 || i + 1 == 6 || i + 1 == 10 || i + 1 == 14) ? 2 : (i + 1 == 3 || i + 1 == 7 || i + 1 == 11 || i + 1 == 15) ? 4 : (i + 1 == 4 || i + 1 == 8 || i + 1 == 12 || i + 1 == 16) ? 5 : (i + 1 == 5 || i + 1 == 9 || i + 1 == 17||i + 1== 20) ? 3 : 0) : 1)).
            replace("{1}", setNbsp(SHOOLCITY[i].CITYNAME)).
            replace("{2}", temp) + "</ul>");

            //绑定校区下拉列表
            $("#dropCity").append(_Option
            .replace("{0}", SHOOLCITY[i].PKID)
            .replace("{1}", SHOOLCITY[i].CITYNAME));
            //校区下拉列表Onhange事件
            $("#dropCity").change(function() {
                $("#dropSchool").empty().append(_Option.replace("{0}", "0").replace("{1}", "请选择学习中心"));
                var shoolArray = GetShoolAddressByCityID(this.options[this.selectedIndex].value);
                $.each(shoolArray, function() {
                    $("#dropSchool").append(_Option.replace("{0}", this.PKID).replace("{1}", this.SHOOLNAME));
                });

            });
        }
    }

    //绑定年级
    if (!!GRADE) {
        $("#dropGrade").append(_Option.replace("{0}", "0").replace("{1}", "请选择年级"));
        $.each(GRADE, function() {
            $("#dropGrade").append(_Option.replace("{0}", this.PKID).replace("{1}", this.GRADENAME));
        });
    }
    //绑定科目
    if (!!SUBJECT) {
        $("#dropSubject").append(_Option.replace("{0}", "0").replace("{1}", "请选择科目"));
        $.each(SUBJECT, function() {
            $("#dropSubject").append(_Option.replace("{0}", this.PKID).replace("{1}", this.SUBJECTNAME));
        });
    }


    var _tagsA = $("#tags a");
    var _tagContext = $("#tagContent");
    var isLoad1 = true, isLoad2 = false, isLoad3 = false, isLoad4 = false, isLoad5 = false
    _tagsA.click(function() {
        if (this.className.indexOf('2') > -1)
            return;
        $.each(_tagsA, function() {
            if (this.className.indexOf('2'))
                this.className = String(this.className).replace('2', '');
        });
        this.className = this.className + "2";
        var html = "";
        switch (_tagsA.index(this)) {
            case 0:
                if (!isLoad1) {
                    html = Solution.YcyMarketing.Index.GetSubjectAssay().value;
                    isLoad1 = true;
                }
                break;
            case 1:
                if (!isLoad2) {
                    html = Solution.YcyMarketing.Index.GetTeacherList().value;
                    isLoad2 = true;
                }
                break;
            case 2:
                if (!isLoad3) {
                    html = Solution.YcyMarketing.Index.GetStudentList().value;
                    isLoad3 = true;
                }
                break;
            case 3:
                if (!isLoad4) {
                    html = Solution.YcyMarketing.Index.GetVideoList().value;
                    isLoad4 = true;
                }
                break;
            case 4:
                if (!isLoad5) {
                    html = Solution.YcyMarketing.Index.GetAbout().value;
                    isLoad5 = true;
                }
                break;
        }
        _tagContext.append(html);
        _tagContext.children().hide();
        $("#tagContent_child" + _tagsA.index(this)).css("display", "block");

        return false;
    });

    $("#btnSeach").click(function() {
        var dropSchool = $("#dropSchool").val();
        var dropGrade = $("#dropGrade").val();
        var dropSubject = $("#dropSubject").val();
        if (dropSchool == "0" || dropGrade == "0" || dropSubject == "0")
{
            return false;
}
        window.open("/subjectAnaly_" + GetSubjectAssay(parseInt($("#dropGrade").val()), parseInt($("#dropSubject").val())) + "_" + $("#dropSchool").val() + ".htm");
        return false;
    });
    //setTimeout("Turnimg()", 1000 * 2.5);
});

function GetSubjectAssay(grade, subject) {
    if (!!SUBJECTASSAY) {
        for (var i = 0; i < SUBJECTASSAY.length; i++) {
            if (SUBJECTASSAY[i].GRADEID == grade && SUBJECTASSAY[i].SUBJECTID)
                return SUBJECTASSAY[i].PKID;
        }
    }
    return "0";
}
function Turnimg() {
    var _imgArray = $("#turn_box > img");
    $.each(_imgArray, function() {
        var _this = $(this);
        if (_this.css("display") == "block") {
            var _next = typeof _this.next().get(0) == "undefined" ? _imgArray.eq(0) : _this.next();
            _this.hide(1000);
            _next.show("slow");


            setTimeout("Turnimg()", 1000 * 3);
            return false;
        }
    });
}


