/*************************************
	pagination script
*************************************/

/*

	expects a DOM id
		the dom id should contain children that will represent a 'page'
		// think of dom id as the id of a 'book'
	
	init_pagination will take the immediate children of the dom element (the 'pages')
	then it will re-format their ids (BE CAREFUL) to reflect the page sequencing
	
	it will grab and preserve the 'pages' style.display and use that as the on state
	
	it will create next and previous elements that'll use the provided target id

	it will pick the same element as the 'pages' are for the targetID-controls
	it will pick the same element as the 'page items' are for the targetID-{prev,count,next}

	it will put the textNodes in spans

<element style="clear: both;" id="targetID-controls">
	<element id="targetID-prev" class="prev"><span>< Prev</span></div>
	<element id="targetID-count" class="count">  <span id="targetID-paginate1" class="current">1</span>   <span onclick="page_flip(1, targetID);" id="targetID-paginate2">2</span>   </div>
	<element id="targetID-next" class="next"><span>Next ></span></div>
</element>
*/
function init_pagination(targetID) {
   var count = 1;
   while (document.getElementById(targetID + "-page-" + pagecount)) {
      if (pagecount == 1) {
         document.getElementById(targetID + "-page-" + pagecount).style.display = "block";
      } else {
         document.getElementById(targetID + "-page-" + pagecount).style.display = "none";
      }
      pagecount++;
   }
   showPagecount(targetID);

      document.getElementById(targetID + "-prev").onclick = function(){page_flip(-1, targetID)};
      document.getElementById(targetID + "-next").onclick = function(){page_flip(1, targetID)};

}