﻿var ay = ["\u8BF7\u8F93\u5165\u5173\u952E\u5B57\u6309\u56DE\u8F66\u641C\u7D22..", "/images/default.gif"];
function SearchEvent() {
    if (!$$("query")) { return false; };
    var obj = $$("query");
	if(obj.value == "")
		obj.value = config.keywords == "" ? ay[0] : config.keywords;
    obj.onmouseover = function () {
        this.focus();
        this.value = this.value == ay[0] ? "" : this.value;
    };
    obj.onmouseout = function () {
        this.blur();
        this.value = this.value == "" ? ay[0] : this.value;
    }
    $(document).keypress(function (event) {
        if (event.which == '13') {
            var v = $S.trim($$("query").value);
            if (v.length == 0 || v == ay[0]) {
                $$("query").focus();
                $$("query").value = "";
                return false;
            };
            location.href = "/search/" + $$("query").value + "/";
        }
    });
};

function WebMenu() {
    $("#menu").find("li.main").each(function (index) {
        if ($(this).find(".msub").length > 0) {
            $(this).find(".msub:eq(0)").append('<div class="menusub"><div class="cont">&nbsp;</div><div class="bot"></div></div>');
			$(this).find("li.def").addClass("lion");
        }
        $(this).mouseover(function () {
            $("#menu").find("li.main").removeClass("on");
            $(".msub").css("display", "none");
            if ($(this).find(".msub").length == 0) { return; }
            $(this).addClass("on").find(".msub").css("left", index * 88 + 7).css("display", "block").find(".cont").height($(this).find("li").length * 27 + 7);
        });
    });
    $(".msub").find("li").each(function () {
        var astr = $(this).find("a").html();
        if (astr.length > 5) {
            $(this).find("a").html(astr.substring(0, 5)).attr("title", astr);
        }
        $(this).mouseenter(function () {
            $(this).parentsUntil(".msub").find("li").removeClass("lion");
            $(this).addClass("lion");
        });
    });
    $(".msub").mouseleave(function () {
        $(this).css("display", "none").find("li").removeClass("lion");
        $("#menu").find("li.main").removeClass("on");
    });
};

function Ajax(action, callback) {
    $D.ajax("/site/ajax.aspx", "t=" + action, callback);
};

function SetClick(type) {
    if (config.cid == 0 || config.vtype > 2) return;
    if (type == "content") {
        Ajax("z101&up=yes&id=" + config.cid);
    } else if (type == "topic") {
        Ajax("z100&up=yes&id=" + config.cid);
    }
}

function LoginCheck() {
    var name = $("#username").val(), pwd = $("#password").val();
    if ($.trim(name) != "" && $.trim(pwd) != "") { $("#loginform").submit(); }
}

myFocus.extend({
    mF_classicHC: function (par, F) {
        var box = F.$(par.id);
        F.addList(box, ['txt', 'num-bg', 'num']);
        var pic = F.$li('pic', box), txt = F.$li('txt', box), num = F.$li('num', box), n = pic.length;
        var txtH = isNaN(par.txtHeight / 1) ? 26 : par.txtHeight;
        box.style.width = par.width + 2 + 'px'; box.style.height = par.height + txtH + 2 + 'px';
        F.$c('num-bg', box).style.bottom = F.$c('num', box).style.bottom = txtH + 1 + 'px';
        for (var i = 0; i < n; i++) {
            pic[i].style.display = 'none';
            txt[i].style.cssText = 'display:none;top:' + (par.height + 2) + 'px;width:' + (par.width + 2) + 'px';
        }
        eval(F.switchMF(function () {
            pic[index].style.display = 'none';
            txt[index].style.display = 'none';
            num[index].className = '';
        }, function () {
            F.fadeIn(pic[next]);
            txt[next].style.display = '';
            num[next].className = 'current';
        }))
        eval(F.bind('num', 'par.trigger', par.delay));
    }
});
myFocus.extend({
    mF_YSlider: function (par, F) {
        var box = F.$(par.id);
        F.addList(box, ['rePic', 'txt', 'num']); F.$c('rePic', box).innerHTML = F.$c('pic', box).innerHTML;
        var pic = F.$li('pic', box), rePic = F.$li('rePic', box), txt = F.$li('txt', box), num = F.$li('num', box), n = pic.length;
        var s = par.direct == 'one' ? 1 : 0, d1 = par.width, d2 = par.height;
        eval(F.switchMF(function () {
            var r = s ? 1 : Math.round(1 + (Math.random() * (2 - 1))), dis, d, p = {};
            dis = r == 1 ? d1 : d2, d = Math.round(Math.random() + s) ? dis : -dis, p[r == 1 ? 'left' : 'top'] = d;
            pic[index].style.display = txt[index].style.display = 'none';
            rePic[index].style.cssText = 'left:0;top:0;display:block;filter:alpha(opacity=100);opacity:1;';
            F.slide(rePic[index], p, 500, 'swing').fadeOut(rePic[index], 500);
            num[index].className = '';
        }, function () {
            pic[next].style.display = txt[next].style.display = 'block';
            num[next].className = 'current';
        }))
        eval(F.bind('num', 'par.trigger', par.delay));
    }
});
myFocus.set.params('mF_YSlider', { direct: 'one' });

$(function () {
    $(window).bind('load', function () {
        $('img').each(function () {
            if ((typeof this.naturalWidth != "undefined" && this.naturalWidth == 0) || this.readyState == 'uninitialized') {
                $(this).attr('src', config.temp_dir + ay[1]);
            }
        });
    })
});
