window.addEvent('domready', function(){

	var pagingA = [];
	
	$$('#bottomcontent #bottomscrollcontent .contentelement .contenttext').each(function(item, index){
			
			if (item.hasClass('contenttext')) {
				
				children = item.getChildren();
				children.each(function(child, childindex){
					
					if (child.hasClass('textcont')) {
						
						pagingA[index] = new Object();
						
						//var scrolltext = new Fx.Scroll(child.getProperty('id'), {
						pagingA[index]["scroll"] = new Fx.Scroll(child, {
							wait: false,
							duration: 0,
							offset: {'x': 0, 'y': 0},
							transition: Fx.Transitions.linear
						});
						pagingA[index]["scrolltoy"] = 0;
						pagingA[index]["cont2height"] = child.getFirst().getCoordinates().height;
						pagingA[index]["step"] = parseInt(child.getStyle('height'));
						
						// adjust height for 'last' paging
						if (parseInt(pagingA[index]["cont2height"]) % parseInt(pagingA[index]["step"]) != 0) {
							var factor = parseInt(pagingA[index]["cont2height"]) / parseInt(pagingA[index]["step"]);
							factor = Math.ceil(factor);
							var newheight = parseInt(parseInt(pagingA[index]["step"]) * factor);
							child.getFirst().setStyle('height', newheight);
							pagingA[index]["cont2height"] = newheight;
						}
						
						
						
					} else if (child.hasClass('pagingnav')) {
						
						// prev
						//prev = child.getFirst();
						child.getFirst().addEvent('click', function(event) {
							if (pagingA[index]["scrolltoy"] > 0) {
								pagingA[index]["scrolltoy"] = pagingA[index]["scrolltoy"] - pagingA[index]["step"];
								pagingA[index]["scroll"].scrollTo(0, pagingA[index]["scrolltoy"]);
							}
						});
						// next
						//next = child.getLast();
						child.getLast().addEvent('click', function(event) {
							if (pagingA[index]["scrolltoy"]+pagingA[index]["step"] < pagingA[index]["cont2height"]) {
								pagingA[index]["scrolltoy"] = pagingA[index]["scrolltoy"] + pagingA[index]["step"];
								pagingA[index]["scroll"].scrollTo(0, pagingA[index]["scrolltoy"]);
							}
						});
						
						// paging invisible
						if ((pagingA[index]["cont2height"]-1) <= pagingA[index]["step"]) {	// -1 for IE6
							child.getFirst().setStyle('display', 'none');
							child.getLast().setStyle('display', 'none');
						}

					}
				});
			}
		});
		
}); 
