﻿$(document).ready(function() {
    bind();
    newsbind();

    $("#search").change(function() {
        window.location.href = $("#search").val();
    });
});

//图片左右移动
function move(direction) {
    var licount = $("#roll > ul > li").length; //li的个数
    var livisible = 3; //其中3个是可视的。
    var liwidth = 124; //li的宽度
    var duration = 1000; //移动速度
    var toleft = $("#roll").position().left;

    if (direction.data.t == "left") {
        if (toleft > -(licount - livisible) * liwidth + 10) {
            $("#topic_box_pre").unbind("click");
            $("#topic_box_next").unbind("click");
            $("#roll").animate({ left: toleft - liwidth }, duration, "", bind);
        }
    } else {
        if (toleft < 0) {
            $("#topic_box_pre").unbind("click");
            $("#topic_box_next").unbind("click");
            $("#roll").animate({ left: toleft + liwidth }, duration, "", bind);
        }
    }
}
function bind() {
    $("#topic_box_pre").bind("click", { t: "left" }, move);
    $("#topic_box_next").bind("click", { t: "right" }, move);
}

function newsmove(direction) {
    var licount = $("#newsroll > ul > li").length; //li的个数
    var livisible = 1; //其中1个是可视的。
    var liheight = 80; //li的高度
    var duration = 1000; //移动速度
    var totop = $("#newsroll").position().top;

    if (direction.data.t == "up") {
        if (totop > -(licount - livisible) * liheight) {
            $("#news_box_pre").unbind("click");
            $("#news_box_next").unbind("click");
            $("#newsroll").animate({ top: totop - liheight }, duration, "", newsbind);
        }
    } else {
        if (totop < 0) {
            $("#news_box_pre").unbind("click");
            $("#news_box_next").unbind("click");
            $("#newsroll").animate({ top: totop + liheight }, duration, "", newsbind);
        }
    }
}
function newsbind() {
    $("#news_box_pre").bind("click", { t: "up" }, newsmove);
    $("#news_box_next").bind("click", { t: "down" }, newsmove);
}
