
Dingtai.List = {};

Dingtai.List.Init = function(pageIndex,pageCount) {
    Dingtai.List.InitTitlePage(pageIndex,pageCount);   
    Dingtai.List.InitPage(pageIndex,pageCount);  
};

Dingtai.List.PageSize = 5;
Dingtai.List.RecordCount = 0;
Dingtai.List.ShowMutilPageCount = 5;

Dingtai.List.InitPage = function(pageIndex,pageCount) {
    var str = "";
    var ul_page = jQuery(".video_page ul");
    ul_page.html(str);
    
//    alert(titlePage);
    if (pageIndex <= 1) { str = "<li class='previous'><span>上一页</span></li>";  }
    else {  str = "<li class='previous'><a href='" + Dingtai.List.GetFileName(pageIndex-1) + "'>上一页</a></li>";    }    
    ul_page.append(str);
        
    var preMore = false;
    var count = Dingtai.List.ShowMutilPageCount;
    if ((pageCount > count && pageIndex > count)) { preMore = true;}
    var nextMore = false;
    if (pageCount > count && pageIndex <= pageCount - count) { nextMore = true;}
    
//    if (preMore) { ul_page.append("<li class='pages'><a href='"+ Dingtai.List.GetFileName(pageIndex - count) +"'>...</a></li>"); }
    
    var start = 0;
    if(pageIndex > count) { start = pageIndex - count + 3; }
    else { start = 1; }
    var end = 0;
    if(pageIndex > pageCount - count) { end = pageCount;  if (pageCount > count) { start = pageCount - count + 1;} }
    else if(pageIndex < 5) { end =count; }
    else { end =pageIndex + count - 3; }
    
    for(var i = start; i<=end;i++){
        if (i==pageIndex) { ul_page.append("<li class='pages'><span>" + i +"</span></li>"); }
        else { ul_page.append("<li class='pages'><a href='"+  Dingtai.List.GetFileName(i) +"'>" + i +"</a></li>"); }
     }

//     if (nextMore) { ul_page.append("<li class='pages'><a href='"+  Dingtai.List.GetFileName(pageIndex + count) +"'>...</a></li>"); }
    
    if (pageIndex >= pageCount) { str = "<li class='next'><span>下一页</span></li>";  } 
    else {  str = "<li class='next'><a href='" + Dingtai.List.GetFileName(pageIndex+1) + "'>下一页</a></li>"; }
    ul_page.append(str);
};

Dingtai.List.InitTitlePage = function(pageIndex,pageCount) {

    var str = "";
    var ul_page = jQuery(".video_title_page");
    ul_page.html(str);
    str = "<div class='pages'>" + pageIndex + "/" + pageCount + "</div>"; 
     ul_page.append(str);

    if (pageIndex <= 1) { str = "<div class='previous'><span>上一页</span></div>";  }
    else {  str = "<div class='previous'><a href='" + Dingtai.List.GetFileName(pageIndex-1) + "'>上一页</a></div>";    }    
    ul_page.append(str);
            
    if (pageIndex >= pageCount) { str = "<div class='next'><span>下一页</span></div>";  } 
    else {  str = "<div class='next'><a href='" + Dingtai.List.GetFileName(pageIndex+1) + "'>下一页</a></div>"; }
    ul_page.append(str);
};

Dingtai.List.GetFileName = function (pageIndex) {
    var path = location.pathname;
    var ps = path.split("/");
    if (ps.length < 1) { return ""; }
    var fileName = ps[ps.length-1];
    if (fileName.indexOf(".") > 0) {
        fileName = fileName.substr(0,fileName.indexOf("."));   
        var fs = fileName.split("_");
        fileName = fileName.substr(0,fileName.length - fs[fs.length-1].length);  
    }
    fileName = fileName + pageIndex + ".htm";
    return fileName;
}