// JavaScript Document
//全局变量
var prevBtn, prevItem4Btn, clicked = null, clicked2 = null, tag, mid;
var obj_list_cache = new Array();
//初始变量
var init_var = function() {
    prevBtn = $("#yh"); prevItem4Btn = $(".item4Over");
    if (!clicked) { clicked = null; }
    if (!clicked2) { clicked2 = null; }
}
var init = function() {
    //   prevBtn = $("#yh");
    //   prevItem4Btn = $(".item4Over")
    //	clicked = null
    $(".liOut, .liOver").mouseover(function() {
        $(this).parent().children().attr("class", "liOut")
        $(this).attr("class", "liOver");
        showContent($(this))
    })

    $(".infoList").mouseover(function() {
        $(this).css("background", "url(http://i2.ssimg.cn/images/school/icon_g.gif) no-repeat 5px 3px;");
        $(this).css("font-weight", "bold");
    }).mouseout(function() {
        $(this).css("background", "url(http://i2.ssimg.cn/images/school/icon_ga.gif) no-repeat 5px 3px;");
        $(this).css("font-weight", "normal");
    })

    $(".listOver, .listOut").mouseover(function() {
        $(this).attr("class", "listOver");
        prevBtn.attr("class", "listOut");
        /*加载数据
        var thisObj = $(this);
        var lid = $(this).attr("id");
        obj_list_cache[0] = "yh";
        var isa=false;
        for(var i=0;i<=obj_list_cache.length;i++){
        if(obj_list_cache[i]==lid) {isa =true;break;}
        }
        if(!isa){
        $.post("xml_"+lid+".aspx","",function(data){
        thisObj.parent().parent().children("."+lid).html(data);
        obj_list_cache[obj_list_cache.length] = lid;
        })}//加载结束*/
        showContent2($(this))
        prevBtn = $(this);
    })

    $(".item4Over, .item4Out").mouseover(function() {
        $(this).attr("class", "item4Over");
        prevItem4Btn.attr("class", "item4Out");
        prevItem4Btn = $(this);
        //		if(prevItem4Btn && prevItem4Btn != $(this)){
        //			prevItem4Btn.attr("class", "item4Out")	
        //		}
        //		this.prevItem4Btn = $(this)
    })

    //List page menu mouse event
    $(".menuOver, .menuOut").mouseover(function() {
        $(this).attr("class", "menuOver");
    }).mouseout(function() {
        if (clicked) {
            if (clicked.html() != $(this).html()) {
                $(this).attr("class", "menuOut");
            }
        } else {
            $(this).attr("class", "menuOut");
        }
    }).mousedown(function() {
        showSubMenu($(this))
    })

    function showSubMenu(thisBtn) {
        if (clicked == null || clicked.html() != thisBtn.html()) {
            var btnToMenu = $("." + thisBtn.attr("id"))
            btnToMenu.slideDown("slow");
            if (clicked) {
                var clickedMenu = $("." + clicked.attr("id"))
                clicked.attr("class", "menuOut");
                clickedMenu.slideUp("slow");
            }
            clicked = thisBtn;
        } else {
            $("." + clicked.attr("id")).slideUp("slow"); clicked = null;
        }
    }

    //list page submenu
    /*
    $(".bottomListOver, .bottomListOut").mouseover(function(){
    if(clicked2==$(this)){$(this).attr("class", "bottomListOver");}														
    }).mouseout(function(){
    if(clicked2==$(this)){$(this).attr("class", "bottomListOut");}
    })
    */
    //list page content
    $(".infoTitle").mouseover(function() {
        $(this).attr("class", "infoTitle titleOver")
        //$(this).find("a").css("background", "url(http://i2.ssimg.cn/images/school/open_hover.gif) no-repeat")
    }).mouseout(function() {
        $(this).attr("class", "infoTitle titleOut")
        //$(this).find("a").css("background", "url(http://i2.ssimg.cn/images/school/open.gif) no-repeat")
    })
    $(".infoTitle").children().not(".subInfoTitle").mousedown(function() {
        listContent($(this).parent())
    })


    function listContent(thisTitle) {

        //显示数据
        var isa = false;
        var lid = thisTitle.attr("id");
        for (var i = 0; i <= obj_list_cache.length; i++) {
            if (obj_list_cache[i] == lid) { isa = true; break; }
        }
        if (!isa) {
            $.post("http://school.stockstar.com/school/action.aspx?act=content&id=" + lid, "", function(data) {
                thisTitle.next().children(".my").html(data);
                obj_list_cache[obj_list_cache.length] = lid;
            })
        } //请求数据
        if (thisTitle.next().css("display") == "none") {
            thisTitle.find("a").eq(0).css("background", "url(http://i2.ssimg.cn/images/school/close.gif) no-repeat");
            thisTitle.find("span").css("background", "url(http://i2.ssimg.cn/images/school/icon_aa.gif) no-repeat 0px 8px");
        } else {
            thisTitle.find("a").eq(0).css("background", "url(http://i2.ssimg.cn/images/school/open.gif) no-repeat");
            thisTitle.find("span").css("background", "url(http://i2.ssimg.cn/images/school/icon_a.gif) no-repeat 0px 8px");
        }
        thisTitle.next().slideToggle("normal");
    }
}
//初始栏目
var init_col = function(showTitle) {
    $("#listPageContent .title").css("background", "url(http://i2.ssimg.cn/images/school/title_" + tag + ".jpg) no-repeat");
    var title = "";
    switch (tag) {
        case "gp":
            $("#mpos").html(" - <a href=\"/list/4067.shtml\">股票学堂</a>");
            title = " - 股票学堂";
            break;
        case "jj":
            $("#mpos").html(" - <a href=\"/list/4139.shtml\">基金学堂</a>");
            title = " - 基金学堂";
            break;
        case "zq":
            $("#mpos").html(" - <a href=\"/list/4137.shtml\">债券学堂</a>");
            title = " - 债券学堂";
            break;
        case "yh":
            $("#mpos").html(" - <a href=\"/list/4187.shtml\">银行学堂</a>");
            title = " - 银行学堂";
            break;
        case "qqz":
            $("#mpos").html(" - <a href=\"/list/4089.shtml\">权证学堂</a>");
            title = " - 权证学堂";
            break;
        case "gg":
            $("#mpos").html(" - <a href=\"/list/4189.shtml\">港股学堂</a>");
            title = " - 港股学堂";
            break;
        case "wh":
            $("#mpos").html(" - <a href=\"/list/4115.shtml\">外汇学堂</a>");
            title = " - 外汇学堂";
            break;
        case "gz":
            $("#mpos").html(" - <a href=\"/list/4103.shtml\">期指学堂</a>");
            title = " - 期指学堂";
            break;
        case "qh":
            $("#mpos").html(" - <a href=\"/list/4123.shtml\">期货学堂</a>");
            title = " - 期货学堂";
            break;
        case "hj":
            $("#mpos").html(" - <a href=\"/list/4107.shtml\">黄金学堂</a>");
            title = " - 黄金学堂";
            break;
        case "day":
            $("#mpos").html(" - <a href=\"/list/4397.shtml\">每日一招</a>");
            title = "";
            break;
        case "licai":
            $("#mpos").html(" - <a href=\"/list/4401.shtml\">理财小贴士</a>");
            title = "";
            break;
        default:
            $("#mpos").html(" - <a href=\"/list/4067.shtml\">股票学堂</a>");
            $(".title").css("background", "url(http://i2.ssimg.cn/images/school/title_gp.jpg) no-repeat");
            title = " - 股票学堂";
            break;
    }
    if (title != "") {
        title = title.replace(" - ", "");
        if (showTitle != null) document.title = document.title.substr(0, document.title.indexOf('-')) + " - " + title + " - 证券之星";
    }
}
var init_col_teacher = function(showTitle) {
    var title = "";
    switch (mid) {
        case "4075":
            $("#mpos").html(" - <a href=\"/list/people_4075.shtml\">沃伦&middot;巴菲特</a>");
            title = " - 沃伦·巴菲特";
            break;
        case "4077":
            $("#mpos").html(" - <a href=\"/list/people_4077.shtml\">詹姆斯&middot;罗杰斯</a>");
            title = " - 詹姆斯·罗杰斯";
            break;
        case "4079":
            $("#mpos").html(" - <a href=\"/list/people_4079.shtml\">彼得&middot;林奇</a>");
            title = " - 彼得·林奇";
            break;
        case "4081":
            $("#mpos").html(" - <a href=\"/list/people_4081.shtml\">乔治&middot;索罗斯</a>");
            title = " - 乔治·索罗斯";
            break;
        case "4083":
            $("#mpos").html(" - <a href=\"/list/people_4083.shtml\">格雷厄姆</a>");
            title = " - 格雷厄姆";
            break;
        case "4085":
            $("#mpos").html(" - <a href=\"/list/people_4085.shtml\">林园</a>");
            title = " - 林园";
            break;
        case "4087":
            $("#mpos").html(" - <a href=\"/list/people_4087.shtml\">杨百万</a>");
            title = " - 杨百万";
            break;
        default:
            $("#mpos").html(" - <a href=\"/list/people_4075.shtml\">沃伦&middot;巴菲特</a>");
            title = " - 沃伦·巴菲特";
            break;
    }
    if (showTitle != null) document.title = title.replace(" - ", "") + " - " + document.title;
}
//onload
var loadinit = $(document).ready(init);
$(document).ready(init_var);


function showContent(thisBtn) {
    var btnToSpace = $("." + thisBtn.attr("id"))
    btnToSpace.parent().children().hide();
    btnToSpace.show();
}
function showContent2(thisBtn) {
    var btnToSpace = $("." + thisBtn.attr("id"))
    btnToSpace.parent().children(".rightContent").hide();
    btnToSpace.show();
}


//得到url中指定参数值
function getUrlByParm(fieldName) {
    var urlString = document.location.search;
    if (urlString != null) {
        var typeQu = fieldName + "=";
        var urlEnd = urlString.indexOf(typeQu);
        if (urlEnd != -1) {
            var paramsUrl = urlString.substring(urlEnd + typeQu.length);
            var isEnd = paramsUrl.indexOf('&');
            if (isEnd != -1) {
                return paramsUrl.substring(0, isEnd);
            }
            else {
                return paramsUrl;
            }
        }
        else {
            return null;
        }
    }
    else {
        return null;
    }
}


var cutstr = function(text, length) { if (text.replace(/[^\x00-\xff]/g, "**").length > length) { return text.substring(0, length) + "..." } else { return text; } }
