﻿
(new Image()).src = "image/summarize-3.jpg";
(new Image()).src = "image/function-3.jpg";
(new Image()).src = "image/profit-3.jpg";
(new Image()).src = "image/summarize-2.jpg";
(new Image()).src = "image/function-2.jpg";
(new Image()).src = "image/profit-2.jpg";
var currentPage = 1;
var currentType = 0;
var ps = 10;
function Display(type) {
    $("#pannel_" + currentType).hide();
    $("#pannel_" + type).show();
    currentType = type;
    showPage(1);
}
var GetPageHtml = function(total, pageSize, pageIndex) {
    var t = Math.ceil(total / pageSize);
    if (total == 0) return "";
    var temp = "";
    var i;
    if (pageIndex != 1)
        temp += "<a href = '#' onclick = 'javascript:showPage(1)'><img src = 'image/first.jpg'/></a>";
    if (pageIndex > 1)
        temp += "<a href = '#' onclick = 'javascript:prePage()'><img src = 'image/pre.jpg'/></a>";
    if (pageIndex < t)
        temp += "<a href = '#'onclick = 'javascript:nextPage()'><img src = 'image/next.jpg'/></a>";
    if (pageIndex != t)
        temp += "<a href = '#' onclick = 'javascript:lastPage()'><img src= 'image/last.jpg'/></a>";
    return temp;
};
function showPage(a) {
    $("#pannel_" + currentType + " li").hide();
    for (var i = 0; i < ps; i++) {
        $("#li_" + currentType + "_" + (ps * (a - 1) + 1 + i)).show();
    }
    currentPage = a;
    debugger
    if (totals[currentType] != 0) {
        $(".news-Paging").html(GetPageHtml(totals[currentType], ps, currentPage));
        var end = (currentPage * ps > totals[currentType]) ? totals[currentType] : (currentPage * ps);
        $(".news-PageInfo").html("显示第 " + (ps * (a - 1) + 1) + "-" + end + " 条/共 " + totals[currentType] + " 条");
    }
    else {
        $(".news-Paging").html("");
        $(".news-PageInfo").html("");
        $("#pannel_" + currentType).html("<p>当前还没有数据！</p>");
    }
   
}
function prePage() {
    showPage(currentPage-1);
}
function nextPage() {
    showPage(currentPage + 1);
}
function lastPage() {
    showPage(Math.ceil(totals[currentType] / ps));
}
function GetUrlParam() {
    var URLParams = new Array();
    var aParams = document.location.search.substr(1).split('&');
    for (i = 0; i < aParams.length; i++) {
        var aParam = aParams[i].split('=');
        URLParams[aParam[0]] = aParam[1];
    }
    return URLParams;
}
$(function() {
    $("#imgs img").bind("click", function(e) {
        var t = $("#tag_img-" + currentType).attr("src");
        $("#tag_img-" + currentType).attr("src", t.replace(/\d.jpg/, "2.jpg"));
        var typeid = this.id.split("-")[1];
        this.src = this.src.replace(/\d.jpg/, "3.jpg");
        Display(typeid);
    });
    var params = GetUrlParam();
    if (params["page"] && params["page"] > 0)
        currentPage = params["page"];
    if (params["idx"])
        currentType  = params["idx"];
    $("#imgs img").eq(currentType).trigger("click");

});
