// Flipbook object is used to manage the flipbook
// flipbookname is the base name of the flipbook
// numentries is the number of entries (entries are numbered 1 - numentries)
function flipbook(flipbookname, numentries)
{
	this.currentindex = 1;
	this.numentries = numentries;
	this.flipbookname = flipbookname;
	
	this.flipto = flipto;
	this.flipnext = flipnext;
	this.flipprev = flipprev;
	this.doswap = doswap;
	this.isIE6or7 = false;
	if(navigator.appVersion.indexOf("MSIE 6.")!= -1 || navigator.appVersion.indexOf("MSIE 7.") != -1)
	    this.isIE6or7 = true;

}

function flipto(tonumber)
{
	this.doswap(tonumber);
}

function flipnext()
{
	if(this.currentindex == this.numentries) this.doswap(1); else this.doswap(this.currentindex+1);
}

function flipprev()
{
	if(this.currentindex == 1) this.doswap(this.numentries); else this.doswap(this.currentindex-1);

}

// Swaps to the specified item number - changing visibility as well
function doswap(tonumber)
{
	if(this.currentindex != tonumber) 
	{
		var oldatagelement = document.getElementById(this.flipbookname + "_A" + this.currentindex.toString());
		var olddivelement = document.getElementById(this.flipbookname + "_" + this.currentindex.toString());
		if(this.isIE6or7)
		{
			oldatagelement.removeAttribute("className");
		    olddivelement.removeAttribute("className");
		    olddivelement.setAttribute("className","fliphidden");
		}
		else
		{
			oldatagelement.removeAttribute("class");
		    olddivelement.removeAttribute("class");
		    olddivelement.setAttribute("class","fliphidden");
		}
	}
	var newatagelement = document.getElementById(this.flipbookname + "_A" + tonumber.toString());
	var newdivelement = document.getElementById(this.flipbookname + "_" + tonumber.toString());
	if(this.isIE6or7)
	{
	    newatagelement.setAttribute("className","onState");
	    newdivelement.setAttribute("className","flipvisible");
	}
	else
	{
    	newatagelement.setAttribute("class","onState");
	    newdivelement.setAttribute("class","flipvisible");
	}

	
	this.currentindex = tonumber;
}