﻿
function BAKItemInit(ClientID,MaxItems,ResName){var bData;var curPage=0;var userTemplate='<div class="bm-topauthor-wrap"><div class="bm-largethumb bm-thumb-wrap"><div class="bm-thumb"><a href="{Url}"><img src="{Image}" alt="{UserName}" /></a></div></div><div class="info"><a href="{Url}">{UserName}</a></div></div>';var creaTemplate='<div class="bm-thumb-crea"><div class="bm-thumb-wrap"><div class="bm-thumb"><a href="{Url}"><img src="{Image}" alt="{Title}" /><a/></div></div><div class="info"><a href="{Url}">{Title}</a></div></div>'
$j("#"+ClientID+" .bm-topauthor-pageLeft").click(function(){curPage-=2;if(curPage>=0)_fill(curPage,curPage+2);});$j("#"+ClientID+" .bm-topauthor-pageRight").click(function(){curPage+=2;if(curPage>=0)_fill(curPage,curPage+2);});$j.getJSON(Cuke.RootUrl+'BM/CreaItem/Home/Remote/BestAuthorService.ashx',{resName:ResName},function(r){if(r&&r!=''){bData=r;_fill(0,2);}});function _fill(start,count){if(bData.User.length>=count){var $i=$j("#"+ClientID+" .bm-topauthor");_preLoad($i);var content='';for(var i=start;i<count;i++){var user=bData.User[i];var tmp=userTemplate.replace(/{Url}/g,user.RootedUrl).replace(/{Image}/g,user.Image).replace(/{UserName}/g,user.UserName);var tmp2='';for(var j in user.Sheets){if(j<MaxItems){var crea=user.Sheets[j];tmp2+=creaTemplate.replace(/{Url}/g,crea.RootedUrl).replace(/{Image}/g,crea.Image).replace(/{Title}/g,crea.Title);}}
content+='<div class="bm-topauthor-one">'+tmp+'<div class="bm-topauthor-thumbs">'+tmp2+'</div></div>';}
$i.empty().append(content);}
_ensurePagers(count);}
function _ensurePagers(count){if(bData.User.length<=count)$j("#"+ClientID+" .bm-topauthor-pageRight img").hide();else $j("#"+ClientID+" .bm-topauthor-pageRight img").show();if(curPage==0)$j("#"+ClientID+" .bm-topauthor-pageLeft img").hide();else $j("#"+ClientID+" .bm-topauthor-pageLeft img").show();}
function _preLoad(d){d.empty().append(Cuke.format("<img src='{0}img/bmloader.gif' alt='loading' />",Cuke.Skin));}}
