//firstitem:
//lastitem:		indices of items to be displayed
//displayitem:	item needing to be displayed
//numberitems:	items to display per page
//callback():	displays the items

function ywNavigation( firstitem, lastitem, displayitem, numberitems, callback, relative_url ) {
	var nav = arguments.callee; //can't use 'this' here
	nav.first = firstitem;
	nav.current = displayitem - ( displayitem - firstitem ) % numberitems;
	nav.last = lastitem;
	nav.size = numberitems;
	nav.redisplay = callback;
	nav.href = relative_url;
}
ywNavigation.firstItem = function() {
	return this.current;
};
ywNavigation.lastItem = function() {
	return Math.min( this.last, this.current + this.size - 1);
};
ywNavigation.makeNavBar = function() {
	var pageTotal = Math.ceil( (this.last + 1 - this.first) / this.size );
	if (pageTotal <= 1) {
		bardiv.innerHTML = '';
		return;
	}
	var page = Math.ceil( (this.current + 1 - this.first) / this.size );
	
	var html = '';
	if (page > 1) {
		var prev = this.current - this.size;
		var last = prev + this.size - 1;
		html = '<a href="$href?current=$prev" onclick="' + this.redisplay
		+ '($prev, $last); return false;">< Previous Page</a>';
		html = (html.replace( /\$prev/g, prev )).replace( /\$last/g, last );
	}
	if (page < pageTotal) {
		if (html) {
			html += ' |\n ';
		}
		var next = this.current + this.size;
		var last = Math.min( this.last, next + this.size - 1 );
		var temp = '<a href="$href?current=$next" onclick="' + this.redisplay
		+ '($next, $last); return false;">Next Page ></a>';
		html += (temp.replace( /\$next/g, next )).replace( /\$last/g, last );
	}
	return html.replace( /\$href/g, this.href );
};