	var headings = {"de" : "Thomas Brandmeier Ranktechnik"};
	var verticalPadding = 30;
	var horizontalPadding = 60;
	var usePHP = false;
	zoomLevels.pop();
	
	var langIndex = 0;
	var zoomIndex = 1;

    
    function createZoomSlider() {
    	var zoomSliderDiv = document.getElementById('zoomSlider');
    	var leftPrinterElement = document.createElement("DIV");
    	leftPrinterElement.id = "printL";
    	leftPrinterElement.className = "print";
    	leftPrinterElement.onclick = print;
    	zoomSliderDiv.appendChild(leftPrinterElement);
    	var imageMinusElement = document.createElement("DIV");
		imageMinusElement.id = "minus";
    	imageMinusElement.className = "plusMinus";
    	zoomSliderDiv.appendChild(imageMinusElement);
  		for (var i = 0; i < zoomLevels.length; i++) {
  			var divElement = document.createElement("DIV");
  			zoomSliderDiv.appendChild(divElement);
  			divElement.id = "button" + i;
  			divElement.className = "klein_ohne";
  			divElement.onmouseover = glowKlein;
  			divElement.onmouseout = noGlowKlein;
  			divElement.onclick = resetZoom;
  			var parElement = document.createElement("P");
  			parElement.className = "zoomLabel";
  			parElement.id = "zoomLabel" + i;
  			parElement.appendChild(document.createTextNode(zoomLevels[i]));
  			divElement.appendChild(parElement);
  		}
    	var imagePlusElement = document.createElement("DIV");
    	imagePlusElement.className = "plusMinus";
    	imagePlusElement.id = "plus";
    	zoomSliderDiv.appendChild(imagePlusElement);
    	var rightPrinterElement = document.createElement("DIV");
    	rightPrinterElement.id = "printR";
    	rightPrinterElement.className = "print";
    	rightPrinterElement.onclick = print;
    	zoomSliderDiv.appendChild(rightPrinterElement);
    }
    
    function createLanguageSelector() {
    	var languageSelectorDiv = document.getElementById('languageSelector');
    	languageSelectorDiv.style.width = languages.length * 24 + "px";
    	languageSelectorDiv.style.visibility = "hidden";
    	languageSelectorDiv.style.height = "0px";
  		for (var i = 0; i < languages.length; i++) {
  			var divElement = document.createElement("DIV");
  			languageSelectorDiv.appendChild(divElement);
  			divElement.className = "imageDiv";
  			var imgElement = document.createElement("img");
  			imgElement.id = "lang" + i;
  			imgElement.className = "lang_unselected";
  			imgElement.onmouseover = glowLang;
  			imgElement.onmouseout = noGlowLang;
  			imgElement.onclick = resetLang;
  			imgElement.src = "img/flag_" + languages[i] +".gif";
  			divElement.appendChild(imgElement);
  		}
    }
    
	function getEventSource(evt, prefix) {
		var source;
		if (document.all) {
			source = event.srcElement;
		} else {
			source = evt.target;
		}
		if (source.id.substring(0, prefix.length) == prefix) {
			return source;
		} else {
			return source.parentNode;
		}
	}
    
	function glowKlein(evt) {
		var button = getEventSource(evt, "button");
		var className = button.className;
		if (className == 'klein_ohne') {
			button.className = "klein_schein";
		} else {
			button.className = "gross_schein";
		} 	
	}
	
  	function noGlowKlein(evt) {
		var button = getEventSource(evt, "button");
		var className = button.className;
  		if (className == 'klein_schein') {
  			button.className = "klein_ohne";
  		} else {
  			button.className = "gross_ohne";
  		} 	
  	}
  	
	function glowLang(evt) {
		var button = getEventSource(evt, "lang");
		var className = button.className;
		if (className == 'lang_unselected') {
			button.className = "lang_unselected_glow";
		} else {
			button.className = "lang_selected_glow";
		} 	
	}
	
  	function noGlowLang(evt) {
		var button = getEventSource(evt, "lang");
		var className = button.className;
  		if (className == 'lang_unselected_glow') {
  			button.className = "lang_unselected";
  		} else {
  			button.className = "lang_selected";
  		} 	
  	}
  	
  	function setButtons() {
  		for (var i = 0; i < zoomLevels.length; i++) {
  			var button = document.getElementById('button' + i);
  			var zoomLabel = document.getElementById('zoomLabel' + i);
  			if (i == zoomIndex) {
  				button.className = "gross_ohne";
  				zoomLabel.className = "zoomLabelSelected";
  			} else {
  				button.className = "klein_ohne";
  				zoomLabel.className = "zoomLabel";
  			}
  		}
  	}

   	function initBook() {
  		var optimalZoom = 0;
  		for (var i = 0; i < zoomLevels.length; i++) {
			var bookWidth = horizontalPadding + (2 * baseWidth * zoomLevels[i]/100) | 0;
			var windowWidth = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
			if (windowWidth > bookWidth) {
				optimalZoom = i;
			} else {
				break;
			}
		}
		zoomIndex = 0;
   		createZoomSlider();
   		//createLanguageSelector();
		resetBook();		
		//document.getElementById('heading').innerHTML = headings[languages[langIndex]];
   	}
   	
   	function resetZoom(evt) {
   		var button = getEventSource(evt, "button");
		zoomIndex = parseInt(button.id.substr(6, 1));
		resetBook();
   	}
   	
   	function print(evt) {
   		var button = getEventSource(evt, "print");
		var which = button.id.substr(5, 1);
		var index = window.location.href.lastIndexOf('#/');
		if (index == -1) {
			var pageToPrint = 1;
			var  pageURL = window.location.href;
		} else {
			var pageToPrint = parseInt(window.location.href.substring(index + 2));
			var  pageURL = window.location.href.substring(0, index);
			if (which == 'R') {
				pageToPrint += 1;
			}
		}
		if (pageToPrint == 0) {
			pageToPrint = 1;
		} else if (pageToPrint == numberOfPages + 1) {
			pageToPrint = numberOfPages;
		}
		var baseURL = pageURL.substring(0, pageURL.lastIndexOf('/'));
		var pdfURL = baseURL + '/resources/' + pdfFiles[languages[langIndex]][pageToPrint];
		window.open(pdfURL, "Printversion", "width=800,height=600,left=100,top=200,location=no,dependent=yes");
   	}
   	
   	
   	function resetLang(evt) {
   		var button = getEventSource(evt, "lang");
		langIndex = parseInt(button.id.substr(4, 1));
		document.getElementById('heading').innerHTML = headings[languages[langIndex]];
		resetBook();
   	}
    
   	function resetBook() {
   		setButtons();
		var imageWidth = (baseWidth * zoomLevels[zoomIndex]/100) | 0;  
		var imageHeight = (baseHeight * zoomLevels[zoomIndex]/100) | 0;  
		var divWidth = 2 * (horizontalPadding + imageWidth);
		var divHeight = 2 * verticalPadding + imageHeight;

		if (usePHP) {
			var objXml = new XMLHttpRequest();
	     	objXml.open("GET", "../megazine.php", false);
	     	objXml.send(null);
	     	usePHP = false;
		}
		
		var epaperFile =  "resources/" + epaperFiles[languages[langIndex]][zoomLevels[zoomIndex]];
       	swfobject.embedSWF("megazine.swf",        /* Path to the megazine.swf. You probably won't have to change this. */
                           "megazine",                     /* Change this if you use another id for the div to display MegaZine. */
/* (1) */                  divWidth,                          /* This is the WIDTH of the element used to display MegaZine. */
/* (2) */                  divHeight,                         /* This is the HEIGHT of the element used to display MegaZine. */
                           "9.0.115",                      /* Required Flash Player version. You probably won't have to change this. */
                           "swfobject/expressInstall.swf", /* Path to the expressInstall.swf to upgrade Flash Player. You probably won't have to change this. */
                           {
                               xmlFile : epaperFile,   /* Used to pass the name of the xml file to use. Path is relative to the swf! */
                               top: "10"                 /* Determines the height of the empty space above pages in pixels */
                           },
                           {
/* (3) */                      bgcolor : "#7290B6",        /* This is the background color used for the Flash element. */
/* (4) */                      wmode : "transparent",    /* Remove the // to enable transparency (show HTML background). Not recommended if using videos. */
                               allowFullscreen : "true"    /* Required for fullscreen mode. */
                           },
                           {id : "megazine"});             /* Required for SWFAddress. */
	}

