<?php
Class Scroll {
	var $start;
	var $end;
	var $cur;

	function Scroll($path) {
		$this->start=0;
		$this->end=0;
		$this->cur=0;
	}

	function create($cur=0, $count=0, $p_count=9) {
		if ($count<1) return false;
		else if($count==1) {
			$this->start=0;
			$this->end=1;
			$this->cur=0;
			return true;
		}
		$cur=($cur<0 ? 0 : ($cur>=$count ? $count-1 : $cur));
		$p_count=($count<$p_count ? $count : $p_count);
		$dx=floor($p_count/2);
		$start=$cur-$dx;
		$end=$cur+$dx;
		if ($start<0) { $end-=$start; $start=0;}
		if ($end>=$count) {
			$start-=$end-$count+1;
			$end=$count-1;
		}
		if ($start<0) $start=0;
		$this->start=$start;
		$this->end=$end;
		$this->cur=$cur;
	}
}
?>