	var bb4 = new BackBone4(vendorId);

	var ImageUploader_SentImages = [];
	var ImageUploader_Id = window.LfdnrStart || 0;
	var ImageUploader_Counter = 0;
	var ImageUploader_StartInterval = false;
	var ImageUploader_FinishInterval = false;

	var ImageUploader_Height = ImageUploader_Height || generateNewImageUploaderHeight();

	var ImageUploader_Width = ImageUploader_Width || generateNewImageUploaderWidth();//|| 720;
	var ImageUploader_TopHeight = 150; // ImageUploader_TopHeight || Math.floor(ImageUploader_Height / 2) - 15;
	var ImageUploader_BeforeUploadCalled = false;

	var treepane_width = 0;
	
	var clientTypes = {
		HTML: 4,
		Java: 5,
		ActiveX: 7
	}
	
	function generateNewImageUploaderHeight() {
		windowHeight = 0;
		try {
			windowHeight = document.body.clientHeight;
		} catch(e) {
			if(window.innerWidth) {
				windowHeight = window.innerHeight;
			} else {
				windowHeight  = 600;
			}
		}
		var height = windowHeight - (window.ImageUploader_HeightReducement || 260);
		if(height < 70) height = 0;
		return height;
	}
	
	function generateNewImageUploaderWidth() {
		windowWidth = 0;
		try {
			windowWidth = document.body.clientWidth;
		} catch(e) {
			if(window.innerWidth) {
				windowWidth = window.innerWidth;
			} else {
				windowWidth  = 600;
			}
		}
		var width = windowWidth - (window.ImageUploader_WidthReducement || 20);
		if(width < 200) width = 0;
		return width;
	}	
	
	function IsPopupUploader() {
		if(
			document.uploadData && 
			document.uploadData.popupUploader &&
			document.uploadData.popupUploader.value == 1
		) {
			return true;
		} else {
			return false;	
		}
	}
	
	function swapControlButtons(mode) {
		if(document.uploadData.tan.value != "" && mode == false) {
			// If this uploader is just adding, we need the cancel Button at any time
			return;
		}
		
		// Mode true = uplading, false = not uploading (default)
		var cancel = document.getElementById("controlButtonCancel");
		var send   = document.getElementById("controlButtonSend");

		if(!cancel || !send) {
			return false;
		}
		
		if(mode) {
			send.disabled = true;
			disableButton(send);
			
			cancel.disabled = false;
			deactivateButton(cancel);
		} else {
			send.disabled = false;
			deactivateButton(send);
			
			cancel.disabled = true;
			disableButton(cancel);
		}
	}
	
	function ImageUploader_Cancel() {
		clearInterval(ImageUploader_StartInterval);
		clearInterval(ImageUploader_FinishInterval);

		getImageUploader("ImageUploader").setTreePaneWidth(treepane_width);
		
		if(bb4.progress.UploadStarted == true) {
			getImageUploader("ImageUploader").Stop();
		} else if(bb4.progress.OrderOpened == true || bb4.progress.OpeningOrder == true) {
			bb4.progress.UploadCanceled = true;
		} else {
			bb4.resetProgress();
			bb4.progress.OrderCanceled = true;
			bb4.addStatusMessage(430);
			bb4.stopAllIntervals();
			swapControlButtons(false);
		}

		if(IsPopupUploader()) {
			opener.goTo("images");
			self.close();
		} else if(document.backToCartForm && document.backToCartForm.tan.value != "") {
			document.backToCartForm.submit();
		}
	}
	
	function ImageUploader_SendNow() {
		getImageUploader('ImageUploader').Send();
		treepane_width = getImageUploader("ImageUploader").getTreePaneWidth();
		getImageUploader("ImageUploader").setTreePaneWidth(-1);
	}
	
	function ImageUploader_Send() {
		doBeforeUploadStart();

		var dataForm = document.uploadData;

		if(dataForm.existingOrder.value == "0") {
			dataForm.tan.value = "";
			dataForm.orderid.value = "";
			bb4.tan = bb4.orderid = false;
		}
		
		bb4.resetProgress();
		bb4.stopAllIntervals();

		var fileCount = Number(getImageUploader("ImageUploader").getUploadFileCount());
		var fileSize = new FileSize(Number(getImageUploader("ImageUploader").getTotalFileSize()));
		
		if(fileCount == 0) {
			alert(getString(142044));
			return true;
		}

		bb4.progress.OrderCanceled = false;

		bb4.resetStatusMessage();
		bb4.setStatusItemCount(5 + fileCount);

		swapControlButtons(true);
		
		var tan = dataForm.tan.value;
		var orderid = dataForm.orderid.value;

		// Retrieve Upload Server
		bb4.getLis(fileCount, fileSize, [tan, orderid]);

		// Retrieve OrderID and Transaction Number
		bb4.getTan();

		// Open Order for Upload
		bb4.openOrder(DummyEmailAddress, clientLanguage, (clientTypes[iu.controlType] || 4), clientVersion, clientVersion);
		
		// Wait for the Order beeing opened
		// Than begin with the File Transfer
		clearInterval(ImageUploader_StartInterval);
		ImageUploader_StartInterval = setInterval(function() {
			if(bb4.progress.OrderOpened == true) {
				clearInterval(ImageUploader_StartInterval);

				bb4.addStatusMessage(41102);
				bb4.setStatus(3);

				// Set TAN and Orderid for the File Uploads
				dataForm.tan.value = bb4.tan;
				dataForm.orderid.value = bb4.orderid;
				
				getImageUploader("ImageUploader").AddField("tan", bb4.tan)
				getImageUploader("ImageUploader").AddField("orderid", bb4.orderid)

				// Set the URL to send to
				//getImageUploader("ImageUploader").setAction("http://www.silverwire.com");
				getImageUploader("ImageUploader").setAction(bb4.LIS.getUploadUrl());
			
				// Listen for errors and user interactions
				bb4.listenForUploadFailure();
				bb4.listenForUploadCancel();
				
				if(dataForm.existingOrder.value == "0") {
					bb4.listenForPageReload();
				}
			
				// Start File Upload
				ImageUploader_SendNow();
				bb4.progress.UploadStarted = true;
			}
		}, 500);
		
		// After a successfull file upload, confirm the Order on the Server
		bb4.confirmOrder();
		
		clearInterval(ImageUploader_FinishInterval);
		ImageUploader_FinishInterval = setInterval(function() {
			if(bb4.progress.OrderConfirmed == true) {
				clearInterval(ImageUploader_FinishInterval);
				
				bb4.setStatus(bb4.statusItemCount);

				if(IsPopupUploader()) {
					opener.goTo("images");
					self.close();
				} else {
					// Set the Success URL
					var dataForm = document.uploadData;
					var redirectForm = '\
					<form method="post" action="/basket/index.php" name="forwardAfterUploadForm">\
						<input type="hidden" name="tan" value="' + bb4.tan + '" />\
						<input type="hidden" name="orderid" value="' + bb4.orderid + '" />\
						<input type="hidden" name="uniqueid" value="' + dataForm.uniqueid.value + '" />\
					</form>';
					
					var div = document.createElement("div");
					div.innerHTML = redirectForm;
					document.body.appendChild(div);
					
					var form = document.forms["forwardAfterUploadForm"];
					form.submit();
				}
					
				// var redirectUrl = "/basket/index.php?tan=" + bb4.tan + "&orderid=" + bb4.orderid + "&uniqueid=" + dataForm.uniqueid.value
				// window.location.href = redirectUrl;
			}
		}, 500);
	}

	function ImageUploader_IncrementId() {
		ImageUploader_Id++;
		ImageUploader_Counter++;
		getImageUploader("ImageUploader").AddField("LFDNR", ImageUploader_Id);
	}
	
	function ImageUploader_ResetId() {
		ImageUploader_Id = 0;
		ImageUploader_Counter = 0;
		getImageUploader("ImageUploader").AddField("LFDNR", ImageUploader_Id);
	}

	function ImageUploader_Progress(Status, Progress, ValueMax, Value, StatusText) {
		if(Status == "UPLOAD" && !ImageUploader_SentImages[StatusText] && StatusText.trim() != "") {
			bb4.addStatusMessage(getString(10005).replace("%s", Number(ImageUploader_Counter)));
			bb4.setStatus(3 + (Number(ImageUploader_Counter)));

			ImageUploader_SentImages[StatusText] = 1;
			ImageUploader_IncrementId();
		}
	
		if(Status == "COMPLETE" || Status == "CANCEL" || Status == "ERROR") {
			if(Status == "CANCEL") {
				bb4.progress.UploadCanceled = true;
				swapControlButtons(false);
			} else if(Status == "ERROR") {
				bb4.progress.UploadFailed = true;
				swapControlButtons(false);
			} else if(Status == "COMPLETE") {
				bb4.progress.UploadFinished = true;
			}

			SentImages = [];
			ImageUploader_ResetId();
			ImageUploader_SentImages = [];
			
			ImageUploader_BeforeUploadCalled = false;
		}
	}

	function ImageUploader_BeforeUpload() {
		if(ImageUploader_BeforeUploadCalled == false) {
			ImageUploader_IncrementId();
		}

		ImageUploader_BeforeUploadCalled = true;
	}
	
	var initCompleteDone = false;
	function ImageUploader_InitComplete() {
		if(initCompleteDone == true) {
			return;
		}

		initCompleteDone = true;
		try {
			document.getElementById("LoadingMessage").style.display = "none";
		} catch(e) { }
			
		setTimeout(function() {
			var u = getImageUploader('ImageUploader');
			if(u) {
				u.setFolderPaneHeight(Math.round(u.offsetHeight / 2));
			}
		}, 1);

		if(window.doAfterUploaderInit) {
			doAfterUploaderInit();	
		}
	}
	
	// Initiate the Uploader Object
	var iu = new ImageUploaderWriter("ImageUploader", ImageUploader_Width, ImageUploader_Height);
	
	// Enable Active-X and Java
	iu.activeXControlEnabled = true;
	iu.javaAppletEnabled = true;
	
	// For ActiveX control we specify full path for CAB file
	iu.activeXControlCodeBase = location.protocol + "//" + location.hostname + "/upload/JavaActiveX/ImageUploader4.cab";
	//iu.activeXControlVersion  = "4,1,32,0";
	//iu.activeXClassId="B85537E9-2D9C-400A-BC92-B04F4D9FF17D";
	iu.activeXControlVersion  = "4,5,118,0";
	iu.activeXClassId="37A8A17B-2DDC-4600-BBC6-538C10AED8C0";
	iu.activeXProgId="Silverwire.ImageUploader.4";
	
	// For Java applet we specify only directory with JAR files
	iu.javaAppletCodeBase = "JavaActiveX/";
	iu.javaAppletJarFileName="ImageUploader2.jar";
	iu.javaAppletCached   = true;
	iu.javaAppletVersion  = "2.1.35.1";

	// License Key
	iu.addParam("LicenseKey",
		"9573-6679-8469-8533;7256-7486-7152-9907;" + // 213.155.85.81
		"7638-7639-9446-9575;5383-6152-6900-5618;" + // 213.155.85.82
		"5591-7594-6600-8624;7988-7428-5383-5696;" + // 213.155.85.83
		"7751-5633-7751-8667;7688-9362-5164-6651;" + // 213.155.85.84
		"7636-6607-6735-6742;9523-8539-5242-5276;" + // 213.155.85.85
		"8629-8647-8623-8655;5448-7844-6564-7975;" + // 213.155.85.86
		"5615-7767-9623-5623;6510-7968-5435-5039;" + // 213.155.85.87
		"7766-7764-7763-5719;6858-9671-6164-5536;" + // 213.155.85.88
		"7190-7574-6930-7191;5880-7935-6182-5974;" + // 213.155.85.89
		"7695-6055-7015-8391;8690-5386-5991-8664;" + // 213.155.85.90

		"7382-9710-6879-8671;9576-8704-6597-9274;" + // 213.155.72.212
		"6125-7477-7255-5871;7305-9110-5087-6335;" + // 213.155.72.213
		"8351-5515-7307-5122;7075-7657-9893-5919;" + // 213.155.72.210
		"7758-7631-5331-7631;6674-5417-6669-6154;" + // 213.155.72.206 - lis5.silverlabxp.de
		"5555-8183-5715-9695;6310-9414-5072-8568;" + // 202.177.223.154
		"7119-7639-9042-7238;6476-5950-5662-8930;" + // 213.155.73.6
		"6968-6394-8793-7152;7478-9044-8038-9916;" + // 213.155.73.7
		"6319-7221-7287-7765;8912-6710-7210-8228;" + // 213.155.73.8
		"7635-5703-5699-5719;8498-9036-8954-9636;" + // 213.155.73.9 
		"7711-6647-9063-7007;6744-8864-5832-5848;" + // 213.155.73.10
		"9015-9470-5300-5780;7568-6584-8584-9624"    // 213.155.73.11
	);
	
	// Speed Issues
	iu.addParam("SignatureFilter", "All");
	iu.addParam("MinImageWidth", "0");
	iu.addParam("MinImageHeight", "0");
	iu.addParam("MaxImageWidth", "0");
	iu.addParam("MaxImageHeight", "0");

	// Catch some events
	iu.addEventListener("Progress", "ImageUploader_Progress");
	iu.addEventListener("BeforeUpload", "ImageUploader_BeforeUpload");

	if(window.ImageUploader_InitComplete && iu.getControlType() == "ActiveX") {
		if(window.Events) {
			Events.add(window, "load", ImageUploader_InitComplete);
		} else {
			window.attachEvent("onload", ImageUploader_InitComplete);
		}
	} else {	
		iu.addEventListener("InitComplete", "ImageUploader_InitComplete");
	}
	
	if(typeof(window.LoadJavaActiveXDefaultSetup) == "undefined" || window.LoadJavaActiveXDefaultSetup == true) {
		// Define a Two Panel Desgin
		iu.addParam("Layout", "ThreePanes");
		
		// Disable sending of Thumbnails
		iu.addParam("UploadThumbnail1FitMode", "off");
		
		// Disable Debugging for Live Environment
		iu.addParam("ShowDebugWindow", "False");
		
		// How much retries should the Uploader do, before canceling
		iu.addParam("AutoRecoverMaxTriesCount", "0");
		iu.addParam("AutoRecoverTimeOut", "3000");
		
		// We will only send one file per request
		iu.addParam("FilesPerOnePackageCount","1");
	
		// Set the right Colors
		iu.addParam("PaneBackgroundColor", "#FFFFFF");
		iu.addParam("BackgroundColor", "#FFFFFF");
		
		// Only JPGs may be used
		iu.addParam("FileMask", "*.jpg;*.jpeg;*.jpe");
		
		// Hide all Buttons
		iu.addParam("ShowButtons", "False");
		
		// Add a Form with some information, which has to be send with every upload
		// The required information are now added with the AddField Method, ass the 
		// AdditionalFormName Parameter does not always work ...
		// iu.addParam("AdditionalFormName", "uploadData");
		
		// Some misc options
		iu.addParam("CheckFilesBySelectAllButton", "True");
		iu.addParam("UncheckUploadedFiles", "False");
		iu.addParam("DescriptionsReadOnly", "True");
		iu.addParam("ShowDescriptions", "False");
		iu.addParam("EnableRotate", "False");
		iu.addParam("AllowRotate", "False");
		iu.addParam("ShowUploadListButtons", "True");
		iu.addParam("ShowUploadCompleteMessage", "False");
		// iu.addParam("FolderPaneHeight", ImageUploader_TopHeight);

		iu.addParam("ProgressDialogWidth", "450");
		iu.addParam("Padding", "0");
		
		// Hide the one and other button
		iu.addParam("MenuInvertSelectionText", "");
	}

	if(clientLanguage != "EN" && clientLanguage != "US") {
		function addLangParam(name, stringid) {
			iu.addParam(name, getString(stringid));
		}

		addLangParam("ButtonAddAllToUploadListText", 41104);
		addLangParam("ButtonAddToUploadListText", 103);
		addLangParam("ButtonRemoveAllFromUploadListText", 41105);
		addLangParam("ButtonRemoveFromUploadListText", 2273);
		addLangParam("DropFilesHereText", 142044);
		addLangParam("HoursText", 41106);
		addLangParam("MinutesText", 41107);
		addLangParam("SecondsText", 41108);
		addLangParam("ListColumnFileNameText", 224);
		addLangParam("ListColumnFileSizeText", 604);
		addLangParam("ListColumnFileTypeText", 41109);
		addLangParam("ListColumnLastModifiedText", 41110);
		addLangParam("MenuAddAllToUploadListText", 41104);
		addLangParam("MenuAddToUploadListText", 103);
		addLangParam("MenuDeselectAllText", 41111);
		addLangParam("MenuDetailsText", 41112);
		addLangParam("MenuIconsText", 41113);
		addLangParam("MenuListText", 41114);
		addLangParam("MenuRefreshText", 41115);
		addLangParam("MenuRemoveAllFromUploadListText", 41105);
		addLangParam("MenuRemoveFromUploadListText", 2273);
		addLangParam("MenuSelectAllText", 85);
		addLangParam("MenuThumbnailsText", 41116);
		addLangParam("MessageBoxTitleText", 41117);
		addLangParam("MessageCannotConnectToInternetText", 4030);
		addLangParam("MessageNoInternetSessionText", 4030);
		addLangParam("MessageNoResponseFromServerText", 10006);
		addLangParam("MessageServerNotFoundText", 10002);
		addLangParam("MessageUploadCancelledText", 430);
		addLangParam("MessageUploadFailedText", 437);
		addLangParam("ProgressDialogBytesSentText", 41118);
		addLangParam("ProgressDialogCancelButtonText", 104);
		addLangParam("ProgressDialogCloseButtonText", 30);
		addLangParam("ProgressDialogCloseWhenUploadCompletesText", 41119);
		addLangParam("ProgressDialogEstimatedTimeText", 41120);
		addLangParam("ProgressDialogPreparingDataText", 41121);
		addLangParam("ProgressDialogTitleText", 41003);
		addLangParam("ProgressDialogWaitingForResponseFromServerText", 41122);
		addLangParam("UnixFileSystemRootText", 41123);
		addLangParam("UnixHomeDirectoryText", 41124);
	}
	