//Pagination. A set of named DIVs is controlled by two buttons.

function Book()
{
	this.basename = "";
	this.currentPage= 0;
	this.numPages = 0;
	this.nextGlyph = [null,"",""];
	this.prevGlyph = [null,"",""];
	this.changeFuncSet = false;
	this.changeFunc = null;
}

Book.prototype.setPageName = function(name)
{
	this.basename = name;
}

Book.prototype.setNumberOfPages = function(num)
{
	this.numPages= num;
}

Book.prototype.setChangeFunc = function(func)
{
	this.changeFuncSet = true;
	this.changeFunc = func;
}

Book.prototype.flickpage = function(way)
{
	//window.status= new Date();
	var p;
	var displayobj;
	if(this.changeFunc != null) this.changeFunc();
	this.currentPage = this.currentPage + way;
	for (p=1;p<=this.numPages;p++){	    
            displayobj = document.getElementById(this.basename+p);
	    //alert("p="+p+" "+displayobj);
	    if(p == this.currentPage){
		displayobj.style.display='block';
	    }else{
		displayobj.style.display='none';
	    }
	  }    
	this.switchGlyphs();
	if(this.changeFunc != null) this.changeFunc();

	//call the set on change
	
}

Book.prototype.next = function()
{
    if(this.currentPage < this.numPages) {
	this.flickpage(1);
    } 
    else {
	this.flickpage(0);
    }
    
    //return "";    

}

Book.prototype.prev = function()
{
    if(this.currentPage > 1) {
	this.flickpage(-1);
    } else {
	this.flickpage(0);
    }
	
}

Book.prototype.diagnostic = function()
{
	var str = "currentPage = " + this.currentPage + "\n";
	str = str + "Number of Pages = " + this.numPages;
	alert(str);
}

Book.prototype.setNextGlyph = function(domid,src,srcblank) {
	this.nextGlyph = [domid,src,srcblank];
};

Book.prototype.setPrevGlyph = function(domid,src,srcblank) {
	this.prevGlyph = [domid,src,srcblank];
};

Book.prototype.switchGlyphs = function () {
	if(this.currentPage == this.numPages) {
		this.nextGlyph[0].src = this.nextGlyph[2];
	}
	else {
		this.nextGlyph[0].src = this.nextGlyph[1];		
	}
	
	if(this.currentPage > 1) {
		this.prevGlyph[0].src = this.prevGlyph[1];
	}else{
	 	this.prevGlyph[0].src = this.prevGlyph[2];
	}
};

Book.prototype.open = function() 
{	
	this.flickpage(1);
}
