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

	this.stageWidth = "100%";
	this.stageHeight = "100%";
	
	this.settings = {
			bookWidth: 1131,
			bookHeight: 800,
			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: 0xFFFFFF,
			frameAlpha: 100,
			firstPageNumber: 1,
			autoFlipSize: 50,
			navigationFlipOffset: 30,
			flipOnClick: true,
			handOverCorner: true,
			handOverPage: true,
			alwaysOpened: false,
			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: "Thin", // "Progress Bar", "Round", "Thin", "Dots", "Gradient Wheel", "Gear Wheel", "Line", "Animated Book", "None"
			pageBackgroundColor: 0xcccccc,
			loadOnDemand: true,
			allowPagesUnload: true,
			showUnderlyingPages: false,
			playOnDemand: true,
			freezeOnFlip: false,
			darkPages: false,
			smoothPages: false,
			rigidPages: false,
			flipCornerStyle: "manually",// "first page only", "each page", "manually"
			flipCornerPosition: "bottom-right",// "bottom-right","top-right","bottom-left","top-left"
			flipCornerAmount: 50,
			flipCornerAngle: 20,
			flipCornerRelease: true,
			flipCornerVibrate: true,
			flipCornerPlaySound: false,
			zoomEnabled: true,
			zoomPath: "pages/large/",
			zoomImageWidth: 1280,
			zoomImageHeight: 1809,
			zoomOnClick: true,
			zoomUIColor: 0xcccccc,
			zoomHint: "Doppelklick für Vergrößerung",
			zoomHintEnabled: true,
			centerBook: true,		
			useCustomCursors: true,
			dropShadowEnabled: true,
			dropShadowHideWhenFlipping: true,
			backgroundColor: 0xFFFFFF,
			backgroundImage: "img/bookBackground.jpg",
			backgroundImagePlacement: "fit", //  "top left", "center", "fit"
			printEnabled: true,
			printTitle: "Print Pages",
			downloadURL: "",
			downloadTitle: "Download PDF",
			downloadSize: "Size: 11,1 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";	

        this.button_x = [
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		230,
		0,
		-140,
		0,
                -140,
                0,
		-120,
		0,
		-220,
		0,
		340,
		0,
		340,
		0,
		300,
		0,
		-250,
		0,
		340,
		0,
		340,
		0,
		340,
		0,
		340,
		0,
		0,
		0,
		0,
		0,
		340,
		0,
		350,
		0,
		0,
		-330,
		120,
		-330,
		-50,
		0,
		0,
		-100,
		340,
		-150,
		100,
		-200,
		0,
		-150,
		220,
		-300,
		200,
		0,
		201,
		0,
		210,
		0,
		300,
		0,
		0,
		0,
		0,
		-150,
		300,
		250,
		360,
		-150,
		300,
		-150,
		300,
		-200,
		350,
		-100,
		200,
		-300,
		0,
		-300,
		360,
		0,
		200,
		0,
		0,
		-200,
		230,
		0,
		0,
		0,
		0
        ];
		
		this.button_y = [
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		560,
		0,
		530,
		0,
                530,
                0,
		530,
		0,
		530,
		0,
		530,
		0,
		530,
		0,
		500,
		0,
		530,
		0,
		530,
		0,
		530,
		0,
		530,
		0,
		160,
		0,
		0,
		0,
		0,
		0,
		530,
		0,
		300,
		0,
		0,
		240,
		140,
		240,
		340,
		0,
		0,
		180,
		350,
		250,
		370,
		420,
		0,
		280,
		150,
		200,
		100,
		0,
		180,
		0,
		260,
		0,
		285,
		0,
		0,
		0,
		0,
		300,
		150,
		200,
		90,
		300,
		180,
		200,
		90,
		200,
		100,
		150,
		180,
		280,
		200,
		280,
		170,
		0,
		200,
		0,
		0,
		200,
		100,
		200,
		0,
		0,
		0
        ];
		
		this.button_URL = [
		"",
		"",
                "",
		"",
                "",
		"",
                "",
		"",
                "",
                "",
                "http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/a0cced19987bde1550cae45aac456d33/Kunststoffrahmen-Galeria/",
		"",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/3c4432caad6939091cd1f8090a8425e0/Kunststoffrahmen-Trendstyle/",
		"",
                "http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/f140ea53d820d09bad5fa8f2bed7ce46/New-Lifestyle-Kunststoffrahmen/",
		"",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/b4c1aaee9d50f372528a6726c472af5d/Holzrahmen-Elegance/",
                "",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/d2a8a4186b21eb7cfe36ee2ceab60dc2/Holzrahmen-Meran/",
		"",
                "http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/683a8d78a858e2a09a31b6a44196fe1e/Holzrahmen-Bologna/",
		"",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/2452bf03b063ea0f35c8f8e0ddb8d8e5/Holzrahmen-Torino/",
                "",
		"http://www.allesrahmen.de/oxid.php/sid/1f5f1d5366ae21f2679043bf3aded54e/cl/details/anid/02269c427a854132487e7f61b2cd4355/Holzrahmen-Natura/",
		"",
                "http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/09fd2e3d1548bef6f0544002e18fa18c/Holzrahmen-Bolero/",
		"",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/1e5138189445689d27d36a0c566c163a/Holzrahmen-Exclusive/",
                "",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/10730b9cbcd48384fdcaa10ad6771003/Holzrahmen-Grado/",
		"",
                "http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/099842e7149f2843a7abf7041d9cc202/Holzrahmen-Chianti/",
		"",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/f4fd272bf79f575660efec6b20a96007/Holzrahmen-Lugano/",
                "",
		"",
		"",
                "",
		"",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/6d99e7f0ad7894e641cec16b4c99d852/Alurahmen-Aluline/",
                "",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/3422b37d63d8e7745982a912807b9cbc/Rahmenlose-Bildhalter-Klarglas/",
		"",
                "",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/7252699a757317fa08b0f2bb145928ef/Kunststoffrahmen-Galeria-Galerierahmen/",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/575887ea23343e9d7d4bc2c54a8990df/Kunststoffrahmen-Trendstyle-Galerierahmen/",
                "http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/b2181ab5d3a0d7cc4122409a46405e28/Holzrahmen-Bologna-Galerierahmen/",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/f24b87ecc95cc90932cd8140c90f2019/Holzrahmen-Natura-Galerierahmen/",
		"",
                "",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/554b0d661724dc0f4d3d3cdaa0253128/Alugalerie---Aluminium-Galerierahmen/",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/780dd7e55620952cca45f2c83a7c5062/White-Gallery/",
                "http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/f0acc1edb5093b29381aab71a4848647/Photogalerie-Rahmenlose-Bildhalter/",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/b7d13527a6983f029dd1a109766a0f80/Photogalerie-Kunststoff/",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/d910c0ea70943946627a42404a615b3d/Float-Frame/",
                "",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/6149eb08e136aae620c08660d2413701/Impression/",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/b9a013906bcbe810c8fa91a6ca0a122b/Carmen/",
                "http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/27443db4c947eedc7356fac1726ead31/Kabinett/",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/ca329e9cbcb5ecdd9227ea487ed0997e/Basixx/",
		"",
                "http://www.allesrahmen.de/oxid.php/sid/1f5f1d5366ae21f2679043bf3aded54e/cl/details/anid/0125c086f817e34916f9dc7f30d9bae4/Metall-%26quot%3BGloria%26quot%3B/",
		"",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/ad20bfa4911a04a391f5bea226ac841f/Nora/",
                "",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/e88a0f59a5d074c204f1853f03208fe4/Emily/",
		"",
                "",
		"",
		"",
                "http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/6e51126f320825671781bd75ac8a54d5/Mia/",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/0eb6faecd92f0bd98e82a091828c3b9e/Isabelle/",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/1db4e23eb1a3949b58718d22d17dc107/Jewel/",
                "http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/15a9492206cdb6bcb6efe59ed99e9fbd/Amore/",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/3b612751eb5f997b80347ded1b80df72/Romance/",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/dda9a8188bb61da179d485d7d81ba93d/Joy/",
                "http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/3f4c5cf39c2add8e3ef65f76e7241ec0/Glas-%26quot%3BStella%26quot%3B/",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/f70e1fbbd96ede83fcd96bfa02bcf6c7/Float-Frame/",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/06854a07701e73f9ee3d449baec866a5/Swing/",
                "http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/b29ce387d57268ce02b9f6561a82342e/Fotokarussell/",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/124ffb5b91d513b08b3fbddee18cf313/Studio-Line/",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/ded467ed4908c41ee5c30b2d8dda8d36/Studio-Line/",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/4d8e68430966444a10a9e937077149b9/Acryl/",
                "http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/331dbd0e973fda935202052dfc8897ea/Acryl/",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/9aa56773c12bec089bd884f18c6fa855/Aluminium-Fotowuerfel/",
                "http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/e938f7947632d776b783ac7a098e34e9/Minirahmen-%26quot%3BVersailles%26quot%3B/",
		"",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/fcd5ba09a5c0838cce8f92aa337abb14/Fotoseil-mit-Magneten/",
                "",
		"",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/d09fac7d5e29c8c00a8bb97883ac8ee6/Acryl-Schluesselanhaenger/",
                "http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/fac3627aa32268f025899b3c7526ef4b/Glitzerkugel/",
		"http://www.allesrahmen.de/oxid.php/sid/x/cl/details/anid/eead2271a30fdfe8ce4d220786a6942e/Pitzelpatz-MDF-Rahmen/",
		"",
                "",
		""
        ];

};

FlippingBook.prototype.create = function(){
	this.settings.pagesSet = this.pages;
	this.settings.zoomPagesSet = this.zoomPages;
	this.settings.printPagesSet = this.printPages;
	
	if( location.hash.substr(1) != "" )
		this.settings.firstPageNumber = location.hash.substr(1);
	
	this.addLoadEvent( this.onWindowLoad );
	swfobject.embedSWF("FlippingBook.swf", this.containerId, this.stageWidth, this.stageHeight, "8.0.0", "js/expressInstall.swf", this.settings, {allowScriptAccess: "always", bgcolor:  "#" + this.settings.backgroundColor.toString( 16 ), wmode: "transparent" });
}

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

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

FlippingBook.prototype.flipForward = function() {
	flippingBook.getFlippingBookReference().flipForward();
}

FlippingBook.prototype.flipBack = function() {
	flippingBook.getFlippingBookReference().flipBack();
}

FlippingBook.prototype.zoomButtonClick = function() {
	if( flippingBook.getFlippingBookReference().isZoomedIn() )
		flippingBook.zoomOut();
	else
		flippingBook.zoomIn();
	
}

FlippingBook.prototype.zoomIn = function() {
	this.getFlippingBookReference().zoomIn();
	this.updateButton( 0, 0);
}

FlippingBook.prototype.zoomOut = function() {
	this.getFlippingBookReference().zoomOut();
	this.updateButton( 0, 0);
}

FlippingBook.prototype.print = function() {	
	flippingBook.getFlippingBookReference().print();
}

FlippingBook.prototype.downloadFile = function() {	
	if( flippingBook.settings.downloadURL )
		flippingBook.getFlippingBookReference().downloadFile();
}

FlippingBook.prototype.onWindowLoad = function(){	
	var forwardButton = flippingBook.getObjectReference( flippingBook.forwardButtonId );
	if( forwardButton ){
		forwardButton.style.cursor = "pointer";
		forwardButton.onclick = flippingBook.flipForward;
	}
	
	var backButton = flippingBook.getObjectReference( flippingBook.backButtonId );
	if( backButton ){
		backButton.style.cursor = "pointer";
		backButton.onclick = flippingBook.flipBack;
	}
	
	var zoomButton = flippingBook.getObjectReference( flippingBook.zoomButtonId );
	if( zoomButton ){
		zoomButton.style.cursor = "pointer";
		zoomButton.onclick = flippingBook.zoomButtonClick;
	}
	
	var printButton = flippingBook.getObjectReference( flippingBook.printButtonId );
	if( printButton ){
		printButton.style.cursor = "pointer";
		printButton.onclick = flippingBook.print;
	}

	var downloadButton = flippingBook.getObjectReference( flippingBook.downloadButtonId );
	if( downloadButton ){
		downloadButton.style.cursor = "pointer";
		downloadButton.onclick = flippingBook.downloadFile;
	}
	
	flippingBook.buildContentsMenu();
}

FlippingBook.prototype.onPutPage = function( leftPageNumber, rightPageNumber ){
	this.updatePagination( leftPageNumber, rightPageNumber );
	this.updateContentsMenu( leftPageNumber, rightPageNumber );
	this.updateButton( leftPageNumber, rightPageNumber );
}

FlippingBook.prototype.updateButton = function( leftPageNumber, rightPageNumber ){
  	var leftPageExists = ( leftPageNumber != undefined );
	var rightPageExists = ( rightPageNumber != undefined );
	var iszoomed = flippingBook.getFlippingBookReference().isZoomedIn()

	if( leftPageExists) {
	  if(leftPageNumber > 0){
	    leftPageNumber--;
		if( this.button_URL[leftPageNumber]!="" ) {
		  this.getObjectReference( "btn_div1" ).setAttribute("style", 'visibility:visible;', 0);
          this.getObjectReference( "btn_div1" ).innerHTML = 
		  '<a href="' + this.button_URL[leftPageNumber] + '" target="_blank">' +
		    '<img src="/rahmentest/img/onlineshop.jpg" style="position: relative;top:' + this.button_y[leftPageNumber] + 'px;Left:' + this.button_x[leftPageNumber] + 'px;"/>' +
		  '</a>'
        }else{
		  this.getObjectReference( "btn_div1" ).innerHTML = '';
		}
	  }else{
	    if (iszoomed == 0){
		  this.getObjectReference( "btn_div1" ).setAttribute("style", 'visibility:hidden;', 0);
		}else{
	      this.getObjectReference( "btn_div1" ).setAttribute("style", 'visibility:visible;', 0);
		}
	  }
	}else{
	  this.getObjectReference( "btn_div1" ).innerHTML = '';
	}
	if( rightPageExists) {
	  if(rightPageNumber > 0){
	    rightPageNumber--;
		if( this.button_URL[rightPageNumber]!="" ) {
		  this.getObjectReference( "btn_div2" ).setAttribute("style", 'visibility:visible;', 0);
		  this.getObjectReference( "btn_div2" ).innerHTML = 
		  '<a href="' + this.button_URL[rightPageNumber] + '" target="_blank">' +
		    '<img src="/rahmentest/img/onlineshop.jpg" style="position: relative;top:' + this.button_y[rightPageNumber] + 'px;Left:' + this.button_x[rightPageNumber] + 'px;"/>' +
		  '</a>'
	    }else{
		  this.getObjectReference( "btn_div2" ).innerHTML = '';
		}
	  }else{
	    if (iszoomed == 0){
		  this.getObjectReference( "btn_div2" ).setAttribute("style", 'visibility:hidden;', 0);
		}else{
          this.getObjectReference( "btn_div2" ).setAttribute("style", 'visibility:visible;', 0);
		}
	  }
	}else{
	  this.getObjectReference( "btn_div2" ).innerHTML = '';
	}
}

FlippingBook.prototype.updatePagination = function( leftPageNumber, rightPageNumber ){
	var leftPageExists = ( leftPageNumber != undefined );
	var rightPageExists = ( rightPageNumber != undefined );
			
	var pageNumberString = leftPageNumber + "-" + rightPageNumber;
	if( !leftPageExists )
		pageNumberString = rightPageNumber;	
	if( !rightPageExists )
		pageNumberString = leftPageNumber;

	this.getObjectReference( this.currentPagesId ).innerHTML = pageNumberString;
	this.getObjectReference( this.totalPagesId ).innerHTML = " / " + this.getFlippingBookReference().totalPages();	
}

FlippingBook.prototype.buildContentsMenu = function(){
	var contentsSelect = this.getObjectReference( this.contentsMenuId );
	
	if( contentsSelect ){
		for( var i = 0; i < this.contents.length; i++ )
			contentsSelect.options[i] = new Option(this.contents[i][0], this.contents[i][1]);
			
		contentsSelect.onchange = this.onContentsChange;
	}
}

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

FlippingBook.prototype.updateContentsMenu = function( leftPageNumber, rightPageNumber ){
	var contentsSelect = flippingBook.getObjectReference( flippingBook.contentsMenuId );

	if( contentsSelect ){
		for( var i = 0; i < this.contents.length - 1; i++ ){
			var minPage = contentsSelect.options[i].value;
			var maxPage = contentsSelect.options[i+1].value;
			var leftOK = false;
			var rightOK = false;
			
			if( leftPageNumber )
				leftOK = ( Number( leftPageNumber ) >=  minPage && Number( leftPageNumber ) <= maxPage );
			else
				leftOK = true;

			if( rightPageNumber )
				rightOK = ( Number( rightPageNumber ) >=  minPage && Number( rightPageNumber ) <= maxPage );
			else
				rightOK = true;
				
			if( leftOK && rightOK )	
				break;
		}	
		contentsSelect.selectedIndex = i;
	}
}

FlippingBook.prototype.getWindowHeight = function() {
	var windowHeight = 0;
	
	if (typeof(window.innerHeight) == 'number' ) {
		windowHeight=window.innerHeight;
	}
	else {
		if (document.documentElement &&	document.documentElement.clientHeight) {
				windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body&&document.body.clientHeight) {
				windowHeight=document.body.clientHeight;
			}
		}
	}
	
	return windowHeight;
}

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;
	}
}

FlippingBook.prototype.handleWheel = function ( delta ){
	this.getFlippingBookReference().onWheelScroll( delta );
}

flippingBook = new FlippingBook();

function wheel(event){
	var delta = 0;
	if (!event) event = window.event;
	if (event.wheelDelta) {
		delta = event.wheelDelta/120; 
		if (window.opera) delta = -delta;
	} else if (event.detail) {
		delta = -event.detail/3;
	}
	if (delta)
		flippingBook.handleWheel(delta);
        if (event.preventDefault)
                event.preventDefault();
        event.returnValue = false;
}

function doubleclick(event){
  flippingBook.updateButton( 0, 0);
}

if (window.addEventListener)
	window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;
if (window.addEventListener)
	window.addEventListener('dblclick', doubleclick, false);

