var thisSort=null;
var sorttop=null;
var sortend=null;
function loadData(){
	sorttop=Position.page(document.body)[1]+Position.page($('part1'))[1];
	window.onscroll=scrollSort;

	getList('001','part2block1');
	getList('002______','part2block2');
	getList('003______','part2block3');
	getList('004______','part2block4');
	getList('005','part2block5');
	getList('006','part2block6');
	getList('007001','part2block7');
	getList1('10-19','part2block8');
	getList1('20-29','part2block9');
	getList1('30-39','part2block10');
	getList1('40-49','part2block11');
	getList1('50-59','part2block12');
	kf();
}
function getList(sort,update){
	var url = '/education/behind/loadsort.aspx?sort='+sort;
	new Ajax.Request(url,{method:'get',onComplete:Complete,onFailure:Failure});
	function Failure(ccc){}
	function Complete(ccc){
		var thisXml = ccc.responseXML;
		var sortname = elementAttrib(thisXml.selectNodes('/root')[0],'title');
		var rows = thisXml.selectNodes('/root/row');
		var tmp='<div class="part2"><p class="ptitle"><a name="'+update.replace('part2block','')+'"></a><span style="float:left;padding:0px 0px 0px 10px;">'+sortname+' ['+rows.length+' ÖÖ]'+'</span></p><div id="'+update+'"></div></div>';
		new Insertion.Bottom($('block2'),tmp);
		var count = rows.length;
		var displayidx=0;	
		var displayend=count<=80?count:80;
		display(true);

		function display(next){
			tmp='<table>';
			for(var i=displayidx;i<displayend;i++){
				tmp+=(i%4==0? '<tr>': '')+'<td><a href="/education/book_intro.aspx?listid='+elementAttrib(rows[i],'listid')+'" target="_blank">'+elementAttrib(rows[i],'bkmc')+'</a></td>'+((i+1)%4==0? '</tr>': '');
			}
			tmp+='</table>';
			new Insertion.Bottom($(update),tmp);
			if(next){
				displayidx+=80;	
				displayend+=80;
				if(displayend<count && next)
					setTimeout(display.bind(this,true),150);
				else{
					displayend=count;
					setTimeout(display.bind(this,false),150);
				}
			}
		}
	}
}
function getList1(sort,update){
	var url = '/education/behind/loadesort.aspx?sort='+sort;
	new Ajax.Request(url,{method:'get',onComplete:Complete,onFailure:Failure});
	function Failure(ccc){}
	function Complete(ccc){
		var thisXml = ccc.responseXML;
		var sortname = elementAttrib(thisXml.selectNodes('/root')[0],'title');
		var rows = thisXml.selectNodes('/root/row');
		var tmp='<div class="part2"><p class="ptitle"><a name="'+update.replace('part2block','')+'"></a><span style="float:left;padding:0px 0px 0px 10px;">'+sortname+' ['+rows.length+' ÖÖ]'+'</span></p><div id="'+update+'"></div></div>';
		new Insertion.Bottom($('block2'),tmp);
		var count = rows.length;
		var displayidx=0;	
		var displayend=count<=80?count:80;
		display(true);
		
		function display(next){
			tmp='<table>';
			for(var i=displayidx;i<displayend;i++){
				tmp+=(i%4==0? '<tr>': '')+'<td><a href="/education/ebook.aspx?id='+elementAttrib(rows[i],'bkdz')+'&name='+elementAttrib(rows[i],'bkmc')+'" target="_blank">'+elementAttrib(rows[i],'bkmc')+'</a></td>'+((i+1)%4==0? '</tr>': '');
			}
			tmp+='</table>';
			new Insertion.Bottom($(update),tmp);
			if(next){
				displayidx+=80;	
				displayend+=80;
				if(displayend<count && next)
					setTimeout(display.bind(this,true),150);
				else{
					displayend=count;
					setTimeout(display.bind(this,false),150);
				}
			}


		}
	}
	
}


function scrollSort(){
	sortend=Element.getDimensions($('block2')).height+sorttop;
	var xx=sorttop-Position.page(document.body)[1]+2;
	if(xx+$('part1').offsetHeight<=sortend)
		Element.setStyle($('part1'),{top:sorttop-Position.page(document.body)[1]+'px'});
}



