//
function app0(opPara) {
  var op = opPara;
  //包括: InfoCatId , DocInfo  
  
  var InfoLiTmpl =  new Ext.Template("<li><a href='javascript:void(0)' infoId={infoId} infoTitle={infoTitle} >{infoTitle}</a>{pubTime}</li>" );
 //<li><a href="javascript:void(0)" onclick="test1();">中山大学附属第三医院活体肝移植手术再获成功 </a></li>
  function buildInfoList(jUl,DocInfo,hasTime,count){ //从后台获取当前信息分类下的所有信息列表
    if (DocInfo){
      jUl.empty();
      var row = $(XP_Row,DocInfo)
      for(var i=0 ; i < row.length ; i++){
        if(i==count)return;
        var jEl = row.eq(i);
        var jInfo = $( InfoLiTmpl.apply({infoId:jEl.attr('ID') , infoTitle:jEl.attr('TITLE') ,
          pubTime: hasTime?getTime(jEl.attr('PUBTIME')):''  }) 
        );
        jUl.append( jInfo );
        jInfo.find('a').click( showInfoById )  ;
      }
    }
    
    function getTime(time){
      return "<span>("+time.substr(0,10)+")</span>";
    }
  }

  var jContFrame = $('#contFrame');
  var jInfoTitle = $('#infoTitle');
  var jAttachBox = $('.box10');
  var jTime =$("#time");
  var attachItemTmpl = new Ext.Template("<li><a href='{url}'>{indexfile}</a></li>" );
  function showInfoById(e){
    var jA =$(e.target || e.srcElement);
    var infoId = jA.attr('infoId');
    jContFrame.attr('src',BasePath+'doAction?Action=getInfoZWHTMLByInfoId&InfoId='+infoId);
    jTime.text(getTimesByID(infoId));
    jInfoTitle.html(jA.attr('infoTitle'));
    toggleInfo(true);

    //http://localhost/zssy/doAction?Action=getInfoZWHTMLByInfoId&InfoId=1046'
    
    $.ajax({
      url:getActionUrl('getInfoByInfoId'),dataType:'json',data:{InfoId:infoId},
      success:function(j){
        var havaAttach=false;
        var jAttachList = $('#attachList').empty();
        $(j.InfoD).each(function(i,n){
          if ("0"==n.iszw){
            var url = getActionUrl('getInfoAttachByInfoId')+'&InfoId='+infoId+'&DocId='+n.id ;
            jAttachList.append(attachItemTmpl.apply({url : url,indexfile:n.indexfile }));
            havaAttach=true;
          }
        });
        havaAttach? jAttachBox.show(): jAttachBox.hide();
      }
    })
  }
  
  var mTime={}
  function getTimesByID(ID){
    mTime[ID] = mTime[ID] || $(XP_Row+"[ID='"+ID+"']",op.DocInfo).attr('PUBTIME');
    return mTime[ID]; 
  } 
  
  var jlnews =$('.lnews'); 
  var jArticle=$('.Article');
  var jInfohBox=$('.box8');
  function toggleInfo(bool){
    !bool?jlnews.show():jlnews.hide();
    bool?jArticle.show():jArticle.hide();
    bool?jInfohBox.show():jInfohBox.hide();
  }
  
  function initInfoAllList(){
    buildInfoList($('#ulInfoAllList'),op.DocInfo,true);
  }
  
  function bulidRightInfoList(){
    buildInfoList($('#ulInfoList'),op.DocInfo,false,5);
  }
  
  function main(){
     initInfoAllList();
     bulidRightInfoList();
  }
  
  return {
    main : main
  }
}