﻿$(function () {
    $("form").submit(function(){ return false; });
    playNum.click(function () {
        var i = $(this).text() - 1;
        indexChange(i);
    });
    $("#navlist").mouseover(function (e) {
        var target = $(e.target);
        target.attr("class", "over_" + target.attr("id"));
    }).mouseout(function (e) {
        var target = $(e.target);
        target.attr("class", "out_" + target.attr("id"));
    });
    $("#tb").keydown(function (event) {
        if (event.keyCode == 13) {
            Search();
        }
    });
    $("#searchbtn").click(function () {
        Search();
    });
});

function indexChange(i) {
    clearInterval(theTimer);
    playNum.filter('.active').removeClass('active');
    playNum.eq(i).addClass("active");
    playShow.html("<img src=" + playNum.eq(i).attr("url") + " />").hide().fadeIn("slow");
    playText.html(playNum.eq(i).next().html());
    theTimer = setTimeout(function() { i = i >= (playNum.size() - 1) ? 0 : ++i; indexChange(i); }, 5000);
};

function Search() {
    var key = $.trim($("#tb").val());
    if (key.length == 0) {
        alert('请输入搜索关键字！');
        return;
    }
    switch ($("input[name='searchtype']:checked").val()) {
        case "sm": window.open("http://reader.hnlib.com/Book/?k=" + encodeURIComponent(key),'_self'); break;
        case "zz": window.open("http://reader.hnlib.com/Book/?a=" + encodeURIComponent(key),'_self'); break;
        case "xw": location.href="../../search.aspx?k=" + encodeURIComponent(key); break;
        case "tw": window.open("http://reader.hnlib.com/Questions/Default.aspx?k=" + encodeURIComponent(key),'_self'); break;
    }
};
