$(document).ready(function(){
    $.ajaxSetup({
        cache: false
    });
    searchToggle();
    $("#searchtext").focus(searchIn).blur(searchOut);
    $(".mainMenu li .sideNavA, .mainMenu1 li .sideNavA").hover(function(){
        $(this).parent().find(".utilNav").addClass("utilNavHover")
    }, function(){
        $(this).parent().find(".utilNav").removeClass("utilNavHover")
    });
    $(".sideBox .content .menu li:not(.curt)").hover(function(){
        $(this).addClass("curt").find(".arr").addClass("arrHover")
    }, function(){
        $(this).removeClass("curt").find(".arr").removeClass("arrHover")
    });
    if (document.getElementById("whisperCount") != null || document.getElementById("replyCounter") != null) {
        chkAllNewMsg("whisperCount", "replyCounter")
    }
    if (document.getElementById("sideMenuSearchQ") != null && document.getElementById("sideMenuSearchButton") != null) {
        sideSearchCheck()
    }
    $("#zhenailink").remove();
    
    //input框在focus的时候 改变灰色为黑色
    $("input.focus_change").focus(function(){
    	$(this).addClass("focus_on");
    }).blur(function(){
    	$(this).removeClass("focus_on");
    });
});
function searchToggle(){
    var b = $("#menuSearchBtn");
    b.click(function(){
        $("#searchBox").slideToggle(200, function(){
            if ($(this).css("display") == "none") {
                b.css("backgroundPosition", "right 6px")
            }
            else {
                b.css("backgroundPosition", "right -24px")
            }
        });
        return false
    })
}

function createClockBox(){
    var a = new flash({
        classid: "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000",
        codebase: "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0",
        width: "45",
        height: "45"
    }, {
        movie: "http://site.tongxueimg.com/v4/k/images/clock.swf?090708",
        quality: "best",
        wmode: "transparent",
        menu: "false",
        allowscriptaccess: "always"
    }, {
        height: "45",
        width: "45",
        align: "middle",
        allowscriptaccess: "always",
        type: "application/x-shockwave-flash",
        menu: "false",
        wmode: "transparent",
        scale: "showall",
        loop: "true",
        play: "true",
        pluginspage: "http://www.adobe.com/go/getflashplayer_cn",
        quality: "best",
        src: "http://site.tongxueimg.com/v4/k/images/clock.swf?090708"
    });
    $('<div class="clockBox">' + a.str + "</div>").appendTo("#mainWrapper")
}

function searchIn(){
    var a = $("#searchtext");
    if (a.val() == "\u8f93\u5165\u540d\u5b57\u6216\u5e10\u53f7") {
        a.val("")
    }
    a.bind("keydown", onSearchInputKeydown)
}

function searchOut(){
    $("#searchtext").unbind("keydown", onSearchInputKeydown)
}

function onSearchInputKeydown(){
    setTimeout(function(){
        var a = $("#searchtext").val();
        if (a == "" || a == "\u8f93\u5165\u540d\u5b57\u6216\u5e10\u53f7") {
            $("#searchBtn").removeClass("enter")
        }
        else {
            $("#searchBtn").addClass("enter")
        }
    }, 0)
}

function sideSearchCheck(f){
    var a = $("#sideMenuSearchQ");
    var c = $("#sideMenuSearchButton");
    var e;
    function d(){
        var h = a.val();
        if (h == "" || h == "\u641c\u7d22...") {
            c.attr("disabled", true).addClass("disabled")
        }
        else {
            c.attr("disabled", false).removeClass("disabled").attr("title", "\u70b9\u51fb\u641c\u7d22")
        }
    }
    function b(){
        var h = a.val();
        if (h == "\u641c\u7d22...") {
            a.val("")
        }
        e = window.setInterval(d, 100)
    }
    function g(){
        window.clearInterval(e);
        d();
        var h = a.val();
        if (h == "") {
            a.val("\u641c\u7d22...")
        }
    }
    d();
    a.focus(b).blur(g)
}

function flash(d, c, a){
    this.str = "";
    if ($.browser.msie) {
        this.str += "<object ";
        for (var b in d) {
            this.str += b + '="' + d[b] + '" '
        }
        this.str += ">";
        for (var b in c) {
            this.str += '<param name="' + b + '" value="' + c[b] + '" /> '
        }
        this.str += "</object>"
    }
    else {
        this.str += "<embed ";
        for (var b in a) {
            this.str += b + '="' + a[b] + '" '
        }
        this.str += "> </embed>"
    }
}

flash.prototype.append = function(a){
    $("#" + a).html(this.str)
};
function overTxweblist(list_name){
	if(list_name == null){
		list_name = "txweblist";
	}
    $("#" + list_name + " li").hover(function(){
        $(this).addClass("over")
    }, function(){
        $(this).removeClass("over")
    })
}

function rootTips(){
    var h = "rootTipsN";
    var i = getCookie(h);
    var g = [], a = [], c = 0;
    g[0] = ["\u540C\u5B66\u624B\u673A\u5BA2\u6237\u7AEF\u53D1\u5E03\u5566\uFF01\u7ACB\u5373\u4E0B\u8F7D\uFF0C\u514D\u8D39\u62CD\u7167\u53D1\u5230\u540C\u5B66\u4E0A", "http://www.tongxue.com/"];
    g[1] = ["\u65B0\u7248\u540C\u4EAB\u4E0A\u7EBF\u5566\uFF01\u4E00\u5B9A\u8981\u8BD5\u8BD5\u6700\u5F3A\u7684\u201C\u540C\u5B66\u201D\u670D\u52A1\u684C\u9762\u5BA2\u6237\u7AEF", "http://tongxuelink.com/"];
    g[2] = ["\u4e2a\u4eba\u4e3b\u9875\u53ef\u4ee5\u81ea\u5b9a\u4e49\uff01", "http://tongxue.com/themes/"];
    g[3] = ["\u540C\u5B66\u662F\u5168\u5F00\u653E\u5E73\u53F0\uFF0C\u770B\u770B\u6709\u4EC0\u4E48\u9002\u5408\u4F60\u7528\u7684\u540C\u5B66\u63D2\u4EF6\uFF1F", "http://tongxue.com/status/apps.php?ref=top"];
    g[4] = ["\u540C\u5B66\u624B\u673A\u5BA2\u6237\u7AEF\u53D1\u5E03\u5566\uFF01\u7ACB\u5373\u4E0B\u8F7D\uFF0C\u514D\u8D39\u62CD\u7167\u53D1\u5230\u540C\u5B66\u4E0A", "http://www.tongxue.com/"];
    c = b(g.length - 1);
    if (i !== null) {
        if (i.substr(i.length - 1) == ",") {
            var f = i.substr(0, i.length - 1);
            if (f.indexOf(",") > -1) {
                a = f.split(",")
            }
            else {
                a[0] = f
            }
            if (a.length >= g.length) {
                return
            }
            for (var d = 0; d < a.length; d++) {
                g[a[d]] = ""
            }
        }
    }
    var e = '<div id="rootTips"><div id="rootTipsBody"><div id="rootTipsBtn"></div>\u6e29\u99a8\u63d0\u793a\uff1a' + k(c) + "</div></div>";
    if (document.getElementById("rootTips") == null) {
        $("body").prepend(e)
    }
    $("#rootTipsBtn").click(function(){
        $("#rootTips").slideUp("fast", function(){
            setCookie(h, i + c + ",")
        })
    });
    function k(l){
        if (g[l] == "") {
            c++;
            if (c > g.length - 1) {
                c = 0
            }
            return k(c)
        }
        else {
            var j = g[l];
            if (j[1] == "") {
                return j[0]
            }
            else {
                return '<a href="' + j[1] + '" target="_blank">' + j[0] + "</a>"
            }
        }
    }
    function b(j){
        var l = Math.random() * j;
        return Math.ceil(l)
    }
}

function getCookie(d){
    var b = d + "=";
    var f = b.length;
    var a = document.cookie.length;
    var e = 0;
    while (e < a) {
        var c = e + f;
        if (document.cookie.substring(e, c) == b) {
            return getCookieVal(c)
        }
        e = document.cookie.indexOf(" ", e) + 1;
        if (e == 0) {
            break
        }
    }
    return null
}

function getCookieVal(b){
    var a = document.cookie.indexOf(";", b);
    if (a == -1) {
        a = document.cookie.length
    }
    return unescape(document.cookie.substring(b, a))
}

function setCookie(a, b){
    var c = new Date();
    c.setTime(c.getTime() + 3600000000);
    document.cookie = a + "=" + b + ";domain=.tongxue.com; expires=" + c.toGMTString()
}

function getQueryStringRegExp(a){
    var b = new RegExp("(^|\\?|&)" + a + "=([^&]*)(\\s|&|$)", "i");
    if (b.test(location.href)) {
        return unescape(RegExp.$2.replace(/\+/g, " "))
    }
    else {
        return ""
    }
};
