function flowbook(fbid, pidprefix, hndlid, hndlprevid, hndlnextid)
{

var _self = this;

this.fbID = document.getElementById(fbid);
this.pageIDprefix = pidprefix;

if(hndlid && hndlprevid && hndlnextid)
	{
	this.fbHandelsID = document.getElementById(hndlid);
	this.fbHandelsPrevID = document.getElementById(hndlprevid);
	this.fbHandelsNextID = document.getElementById(hndlnextid);
	}

this.fbMinHeight = 350;

this.pageIndex = new Array();
this.firstPage = 0;
this.lastPage = 0;
this.currentPage = 0;
this.dimensionUnit = "px";
this.autoPageing = false;
this.autoPageTimeout = "";
this.autoPageTimeoutIntervall = 5000;
this.zoomIntervall = 20;
this.zoomStep = 20;

this.fbGetHeight = function ()
	{ return parseInt(this.fbID.offsetHeight, 0); }

this.fbSetHeight = function (fbH)
	{ this.fbID.style.height = fbH + this.dimensionUnit; }

this.fbGetWidth = function ()
	{ return parseInt(this.fbID.offsetWidth, 0); }

this.fbSetWidth = function (fbW)
	{ this.fbID.style.width = fbW + this.dimensionUnit; }

this.setHandels = function ()
	{
	if(hndlid && hndlprevid && hndlnextid)
		{	
		if (this.lastPage > this.firstPage)
			{ this.fbHandelsID.style.display = "block"; this.startHandels(); }
		}
	}

this.startHandels = function ()
	{
	if(hndlid && hndlprevid && hndlnextid)
		{
		this.fbHandelsPrevID.onclick = function () {_self.stepPage(-1)}
		this.fbHandelsNextID.onclick = function () {_self.stepPage(1)}
		}
	}

this.stopHandels = function ()
	{
	if(hndlid && hndlprevid && hndlnextid)
		{
		this.fbHandelsPrevID.onclick = "";
		this.fbHandelsNextID.onclick = "";
		}
	}

this.seekPages = function ()
	{
	var p = this.fbID.getElementsByTagName("div");
	for (var i=0; i < p.length; i++)
		{
		if ( p[i].id.match(this.pageIDprefix) )
			{ this.pageIndex[this.pageIndex.length] = new this.page(p[i].id, this); }
		}
	}

this.stepPage = function (step)
	{
	if(this.autoPageing && this.autoPageTimeout != "")
		{ window.clearTimeout(this.autoPageTimeout); this.autoPageTimeout = ""; }

	this.stopHandels();
	
	var prevPage = this.currentPage;
	this.currentPage += step;

	if( this.currentPage > this.lastPage) { this.currentPage = this.firstPage; }
	if( this.currentPage < this.firstPage) { this.currentPage = this.lastPage; }
		
	if(step > 0)
		{
		this.pageIndex[this.currentPage].pageZoomIn('left');
		this.pageIndex[prevPage].pageZoomOut('right');
		}
	else
		{
		this.pageIndex[this.currentPage].pageZoomIn('right');
		this.pageIndex[prevPage].pageZoomOut('left');
		}
	
	if(this.autoPageing)
		{
		this.autoPage(0);
		}
	}

this.autoPage = function (aStep)
	{
	var autoPageStep = aStep;

	if(autoPageStep != 0)
		{ this.stepPage(autoPageStep); }
	else
		{
		autoPageStep = 1; 
		this.autoPageTimeout = window.setTimeout(function () { _self.autoPage(autoPageStep) }, this.autoPageTimeoutIntervall);
		}
		
	}



this.page = function (pid, pobj)
	{

	var _self = this;
	var parentObject = pobj;
	this.dimensionUnit = parentObject.dimensionUnit;
	this.pgID = document.getElementById(pid);
	
	this.pageMaxWidth = parentObject.fbGetWidth();
	this.pageMinWidth = 1;

	this.pageZoomInTimeOut = "";
	this.pageZoomInTimeOutIntervall = parentObject.zoomIntervall;
	this.pageZoomInStep = parentObject.zoomStep;

	this.pageZoomOutTimeOut = "";
	this.pageZoomOutTimeOutIntervall = parentObject.zoomIntervall;
	this.pageZoomOutStep = parentObject.zoomStep;


	this.pageGetHeight = function ()
		{ return parseInt(this.pgID.offsetHeight, 0); }

	this.pageSetHeight = function (pH)
		{ this.pgID.style.height = pH + this.dimensionUnit; }

	this.pageGetWidth = function ()
		{ return parseInt(this.pgID.offsetWidth, 0); }

	this.pageSetWidth = function (pW)
		{ this.pgID.style.width = pW + this.dimensionUnit; }
	
	this.pageHide = function ()
		{ this.pgID.style.display = "none"; }

	this.pageShow = function ()
		{ this.pgID.style.display = "block"; }
	
	this.pageIni = function (dir)
		{
		if(dir == 'off') { this.pageHide(); }
		if(dir == 'on') { this.pageShow(); this.pageSetWidth( this.pageMaxWidth );}

		this.pgID.style.left = "0px";
		this.pgID.style.right = "auto";
		this.pgID.style.backgroundColor= "transparent";
		}

	this.pageZoomOut = function (dir)
		{
		window.clearTimeout(this.pageZoomInTimeOut); this.pageZoomInTimeOut = "";

		this.pgID.style.backgroundColor= "#FFFFFF";
		this.pageSetWidth(this.pageMaxWidth);

		if(dir == 'right')
			{
			this.pgID.style.left = "auto";
			this.pgID.style.right = "0px";
			}	

		this.doPageZoomOut();

		}


	this.pageZoomIn = function (dir)
		{
		window.clearTimeout(this.pageZoomOutTimeOut); this.pageZoomOutTimeOut = "";

		this.pageSetWidth(this.pageMinWidth);
		this.pageShow();

		if(dir == 'right')
			{
			this.pgID.style.left = "auto";
			this.pgID.style.right = "0px";
			}	

		this.doPageZoomIn();

		}


	this.doPageZoomOut = function ()
		{
		if(this.pageZoomOutTimeOut != "" && this.pageGetWidth() <= this.pageMinWidth)
			{
			window.clearTimeout(this.pageZoomOutTimeOut); this.pageZoomOutTimeOut = ""; this.pageIni('off'); parentObject.startHandels(); return
			}
		else
			{
			this.pageSetWidth( Math.max( this.pageGetWidth() - this.pageZoomOutStep , this.pageMinWidth ) );
			this.pageZoomOutTimeOut = window.setTimeout(function () { _self.doPageZoomOut(); }, this.pageZoomOutTimeOutIntervall);
			}
		}


	this.doPageZoomIn = function ()
		{
		if(this.pageZoomInTimeOut != "" && this.pageGetWidth() >= this.pageMaxWidth)
			{
			window.clearTimeout(this.pageZoomInTimeOut); this.pageZoomInTimeOut = ""; this.pageIni('on'); parentObject.startHandels(); return
			}
		else
			{
			this.pageSetWidth( Math.min( this.pageGetWidth() + this.pageZoomInStep , this.pageMaxWidth ) );
			this.pageZoomInTimeOut = window.setTimeout(function () { _self.doPageZoomIn(); }, this.pageZoomInTimeOutIntervall);
			}
		}
		
	/* keep height here, when page display=none height is 0 ! */
	this.pageHeight = this.pageGetHeight();
	this.pageIni('off');
	}




this.iniFlowbook = function ()
	{
	this.seekPages();

	this.lastPage = this.pageIndex.length - 1;
	this.currentPage = this.firstPage;

	var keepHeight = this.fbMinHeight;

	for (var i=this.firstPage; i <= this.lastPage; i++)
		{
		keepHeight = Math.max(this.pageIndex[i].pageHeight, keepHeight);
		}

	this.fbSetHeight( keepHeight );

	for (var i=this.firstPage; i <= this.lastPage; i++)
		{
		this.pageIndex[i].pageSetHeight(this.fbGetHeight())
		}
	
	this.pageIndex[this.currentPage].pageIni('on');
	this.setHandels();

	// set parentNode.HEIGHT to this.HEIGHT, so the following Content is correctly below the flowbook ;-) 
	this.fbID.parentNode.style.height = this.fbGetHeight() + parseInt(this.fbID.offsetTop, 0)  + this.dimensionUnit ;

	if(this.autoPageing)
		{ this.autoPage(0); }
	}

/* this.iniFlowbook(); */

}
