var pageIndex=1
var pageCount=1

jQuery(document).ready(function(){

function Request(strName){  
var strHref = location.href;
//http://localhost:29190/template/ChanList.html?action=GetPageData&PageNo=1&type=media&oder=UploadDate&id=e3539ddb-f3fa-417c-a231-002b0bc63064
var intPos = strHref.indexOf("?");  
var strRight = strHref.substr(intPos + 1);  
var arrTmp = strRight.split("&");  
for(var i = 0; i < arrTmp.length; i++) {  
var arrTemp = arrTmp[i].split("=");  
if(arrTemp[0].toUpperCase() == strName.toUpperCase()) return arrTemp[1];  
}  
}  

//-----------------------------------------------------------

function getPageData(pageNo){ //取得某页数据的方法
         $.get("/AJaxPage/ChanListPage.ashx",{"action":Request ("action"),"PageNo":Request ("PageNo") ,type:Request ("type"),"oder":Request ("oder"),id:Request ("id")},function(data,status){
        var chanId=Request ("id")
         pageIndex =Request ("PageNo")
    
             if(status=="success"){
             $("#Comment").empty();

           var json =  jQuery.parseJSON(data);

           $("#pages").empty(); 
           var p=$("<p>"+pageNo  +"/"+ pageCount +"</p>" );
        
           $("#pages").append(p);
      
           //上一页链接
           var shangPage=parseInt(pageNo)-1
           var shang 
    
           if (pageIndex=1){
             shang=$("<span>上一页</span>")
        
           }else {
              if (Request ("oder")=="Point"){
                              
              shang=$("<a href='ChanList.htm?action=GetPageData&PageNo="+shangPage+"&type=media&oder=Point&id="+chanId +"'> 上一页</a>")
             }else {
                shang=$("<a href='ChanList.htm?action=GetPageData&PageNo="+shangPage+"&type=media&oder=TotalView&id="+chanId +"'> 上一页</a>")
             }
           }
           
            if (pageIndex=1){
             shangye=$("<span>上一页</span>")
        
           }else {
              if (Request ("oder")=="Point"){
                              
              shangye=$("<a href='ChanList.htm?action=GetPageData&PageNo="+shangPage+"&type=media&oder=Point&id="+chanId +"'> 上一页</a>")
             }else {
                shangye=$("<a href='ChanList.htm?action=GetPageData&PageNo="+shangPage+"&type=media&oder=TotalView&id="+chanId +"'> 上一页</a>")
             }
           }
           $("#shang").empty();
           $("#shang").append(shang);
            $("#shang").empty();
           $("#shang").append(shangye);
           
           //下一页链接

           var nextPage=parseInt(pageNo)+1
            var next
           if (pageIndex ==pageCount ){
             next=$("<span>下一页</span>")
           }else{
            if (Request ("oder")=="Point"){
                next=$("<a href='ChanList.htm?action=GetPageData&PageNo="+nextPage+"&type=media&oder=Point&id="+chanId +"'> 下一页</a>")
             }else {
                next=$("<a href='ChanList.htm?action=GetPageData&PageNo="+nextPage+"&type=media&oder=TotalView&id="+chanId +"'> 下一页</a>")
             }
           }
           var nextye
           if (pageIndex ==pageCount ){
             nextye=$("<span>下一页</span>")
           }else{
            if (Request ("oder")=="Point"){
                nextye=$("<a href='ChanList.htm?action=GetPageData&PageNo="+nextPage+"&type=media&oder=Point&id="+chanId +"'> 下一页</a>")
             }else {
                nextye=$("<a href='ChanList.htm?action=GetPageData&PageNo="+nextPage+"&type=media&oder=TotalView&id="+chanId +"'> 下一页</a>")
             }
           }
       
           $("#next").empty();
           $("#next").append(next);
           
           $("#nextye").empty();
           $("#nextye").append(nextye);
             $("#video_title1").click(function(e){ //页码创建后，就为每一个页码监听一个click事件。
                 var listHref="/html/ChanList.htm?action=GetPageData&PageNo=1&type=media&oder=TotalView&id="+Request ("id");
                   window.location.href=listHref 
                   document.getElementById('box_box').className="video_title1";
                  
             }); 
             $("#video_title2").click(function(e){ //页码创建后，就为每一个页码监听一个click事件。
                 var listHref="/html/list/List_"+Request ("id")+"_0_1.htm"
                 window.location.href=listHref 
                 document.getElementById('box_box').className="video_title3";
             });
             
             $("#video_title3").click(function(e){   
                 var listHref="/html/ChanList.htm?action=GetPageData&PageNo=1&type=media&oder=Point&id="+Request ("id");
                 window.location.href=listHref 
                 document.getElementById('box_box').className="video_title3";
              });
            for(var i=0,l=json.length;i<l;i++){
      
//             var li= $("<li>"+json[i]["Name"]+"</li>");   
                if (i%4==3){
                  var li= $("<li class='right_none'><p class='img_hover'><a href='"+json[i]["player"]+"'  onclick ='window.open("+json[i]["player"]+")'><img src='"+json[i]["ImageUrl"]+"' width='175' height='131' /><span></span></a></p><span class='text'><a href='"+json[i]["player"]+"' onclick ='window.open('"+json[i]["player"]+"')'> "+json[i]["Name"]+"</a><br />发表于"+json[i]["UploadDate"]+"<br /><b>播放："+json[i]["TotalView"]+"</b>评论："+json[i]["PointCount"]+"</span></li>");
              
                }else {
                 var li= $("<li><p class='img_hover'><a href='"+json[i]["player"]+"'  onclick ='window.open("+json[i]["player"]+")'><img src='"+json[i]["ImageUrl"]+"' width='175' height='131' /><span></span></a></p><span class='text'><a href='"+json[i]["player"]+"' onclick ='window.open('"+json[i]["player"]+"')'> "+json[i]["Name"]+"</a><br />发表于"+json[i]["UploadDate"]+"<br /><b>播放："+json[i]["TotalView"]+"</b>评论："+json[i]["PointCount"]+"</span></li>");

                }
                $("#Comment").append(li);    //每取出一条数据就创建一个li并append到Comment/ul内。
            }
      
            }
          });
}
//-------------------------------------------------------------------
getPageData(Request ("pageNo")); //首次进入页面，看到的是第一页的数据
//----------------------------------------------------------------/
//取得所有的页数并且初始化分页按钮
 $.get("/AJaxPage/ChanListPage.ashx",{"action":"GetPageCount",type:Request ("type"),id:Request ("id")},function(data,status){
             if(status=="success"){  
               var tr1=$("<tr></tr>");
               for(var i=1;i<=pageNo;i++){
                     var td=$("<td><a href=''>"+i+"</a></td>");
                     tr1.append(td);    
               } 
               var pageNo=parseInt(data);
               pageCount =pageNo 
              $("#pageNo").append(tr1); 
              $("#pageNo a").click(function(e){ //页码创建后，就为每一个页码监听一个click事件。
                   e.preventDefault();          //取消a的默认跳转行为
                   getPageData($(this).html()); //点击后就去执行取页数据的操作。
                 });
             }     
          });
//----------------------------------------------------------------------------
});