function FlippingBook() {
	this.pages = [];
	this.zoomPages = [];
	this.printPages = [];
	this.contents = [];

	this.stageWidth = 278;
	this.stageHeight = 194;
	
	this.settings = {
			bookWidth: 278,
			bookHeight: 194,
			scaleBook: false,
			bookToStageScaling: "1",
			downScaleOnly: true,
			pagesSet: this.pages,
			zoomPagesSet: this.zoomPages,
			printPagesSet: this.printPages,
			scaleContent: true,
			preserveProportions: false,
			centerContent: true,
			hardcover: false,
			hardcoverThickness: 3,
			hardcoverEdgeColor: "0xFFFFFF",
			highlightHardcover: true,
			frameWidth: 0,
			frameColor: "0xacc0c7",
			frameAlpha: 100,
			firstPageNumber: 1,
			autoFlipSize: 25,
			navigationFlipOffset: 30,
			flipOnClick: true,
			handOverCorner: true,
			handOverPage: true,
			alwaysOpened: true,
			staticShadowsType: "Asymmetric", // Asymmetric, Symmetric, Default
			staticShadowsDepth: 1,
			staticShadowsLightColor: "0xFFFFFF", // works for "Symmetric" shadows only
			staticShadowsDarkColor: "0x000000",
			dynamicShadowsDepth: 1,
			dynamicShadowsLightColor: "0xFFFFFF", // works for "dark" pages only
			dynamicShadowsDarkColor: "0x000000",
			moveSpeed: 2,
			closeSpeed: 3,
			gotoSpeed: 3,
			rigidPageSpeed: 5,
			flipSound: "",
			hardcoverSound: "",
			preloaderType: "None", // "Progress Bar", "Round", "Thin", "Dots", "Gradient Wheel", "Gear Wheel", "Line", "Animated Book", "None"
			pageBackgroundColor: "0xFFFFFF",
			loadOnDemand: true,
			allowPagesUnload: false,
			showUnderlyingPages: false,
			playOnDemand: true,
			freezeOnFlip: false,
			darkPages: false,
			smoothPages: false, // ** this has a bug that causes the wrong size page to be imported **
			rigidPages: false,
			flipCornerStyle: "manually",// "first page only", "each page", "manually"
			flipCornerPosition: "bottom-right",// "bottom-right","top-right","bottom-left","top-left"
			flipCornerAmount: 15,
			flipCornerAngle: 20,
			flipCornerRelease: true,
			flipCornerVibrate: true,
			flipCornerPlaySound: false,
			zoomEnabled: false,
			zoomPath: "",
			zoomImageWidth: 900,
			zoomImageHeight: 1165,
			zoomOnClick: true,
			zoomUIColor: "0x8f9ea6",
			zoomHint: "Double click for zooming.",
			zoomHintEnabled: false,
			centerBook: false,		
			useCustomCursors: true,
			dropShadowEnabled: true,
			dropShadowHideWhenFlipping: true,
			backgroundColor: "0xbcbdc1",
			backgroundImage: "",
			backgroundImagePlacement: "fit", //  "top left", "center", "fit"
			printEnabled: true,
			printTitle: "Print Pages",
			downloadURL: "",
			downloadTitle: "Download PDF",
			downloadSize: "Size: 4.7 Mb",
			downloadComplete: "Complete",
			extXML: ""
		};
		
		this.containerId = "fbContainer";
		this.forwardButtonId = "fbForwardButton";
		this.backButtonId = "fbBackButton";
		this.zoomButtonId = "fbZoomButton";
		this.printButtonId = "fbPrintButton";
		this.downloadButtonId = "fbDownloadButton";
		this.currentPagesId = "fbCurrentPages";
		this.totalPagesId = "fbTotalPages";
		this.contentsMenuId = "fbContentsMenu";			
};


FlippingBook.prototype.create = function(){
	this.settings.pagesSet = this.pages;
	this.settings.zoomPagesSet = this.zoomPages;
	this.settings.printPagesSet = this.printPages;
	
	var flashvars = {};
	var params = {wmode: "transparent", allowScriptAccess: "always"};
	var attributes = {};
	
	//swfobject.embedSWF("swf/FlippingBook.swf", "fbContainer", "278", "194", "9.0.0", "js/expressInstall.swf", flashvars, params, attributes, success);
	swfobject.embedSWF("swf/FlippingBook.swf", this.containerId, this.stageWidth, this.stageHeight, "9.0.0", "js/expressInstall.swf", this.settings, params, attributes, success);

}

var swfContainerRef;



function success(e){
if (e.success){
swfContainerRef = e.ref;
//setTimeout(function(){swfContainerRef.flipGotoPage(1)}, 2000);
}
	
}



FlippingBook.prototype.getFlippingBookReference = function() {
	return this.getObjectReference( this.containerId );
}

FlippingBook.prototype.getObjectReference = function( id ) {
	return document.getElementById( id );
}



FlippingBook.prototype.updatePagination = function( leftPageNumber, rightPageNumber ){
	return;
	var leftPageExists = ( leftPageNumber != undefined );
	var rightPageExists = ( rightPageNumber != undefined );
	
	var pageNumberString = (parseInt(leftPageNumber-2)) + "-" + (parseInt(rightPageNumber-2)); // PM hack here if you want to start at some arbitary number
	if( !leftPageExists )
		pageNumberString = rightPageNumber-2;	
	if( !rightPageExists )
		pageNumberString = leftPageNumber-2;
	if (pageNumberString == -1) pageNumberString = ""; // we've hit front cover

}



/*FlippingBook.prototype.onContentsChange = function(){
	var contentsSelect = flippingBook.getObjectReference( flippingBook.contentsMenuId );
	var pageNumber = contentsSelect.options[contentsSelect.selectedIndex].value;
	contentsSelect.blur();
	if( pageNumber )
		flippingBook.getFlippingBookReference().flipGotoPage( pageNumber );
}
*/

// my effort
FlippingBook.prototype.gotoPage = function(pageNumber){
	if( pageNumber && swfContainerRef) swfContainerRef.flipGotoPage( pageNumber );

}




FlippingBook.prototype.addLoadEvent = function ( fn ) {
	if (typeof window.addEventListener != "undefined") {
		window.addEventListener("load", fn, false);
	}
	else if (typeof document.addEventListener != "undefined") {
		document.addEventListener("load", fn, false);
	}
	else if (typeof window.attachEvent != "undefined") {
		window.attachEvent("onload", fn);
	}
	else if (typeof window.onload == "function") {
		var fnOld = window.onload;
		window.onload = function() {
			fnOld();
			fn();
		};
	}
	else {
		window.onload = fn;
	}
}


setInterval(autoflip, 5000);

// auto-flip system added by PM May 2011
var flipArray = [1,3,5,7,9,11,13,15];
var counter = 1;
var startup = true;

function autoflip(){
if(startup){
	counter = 1;
	startup = false;
}
if(counter == flipArray.length) counter = 0;
if(flipArray[counter] && current_url == "#home.html") flippingBook.gotoPage(flipArray[counter]);
counter++;	
}

flippingBook = new FlippingBook();

function special(){
if(counter == flipArray.length) counter = 1;
flippingBook.gotoPage(flipArray[counter]);
counter++;	
}
