var disableSwfInput = new Array();
var allimageDivs = new Array();
var swfhoofdhref = new Array();
var swfSuccesCounter = 0;
var changing = false;
window.swfElement = "";
window.swfSrcId = "";

function uploadError(file, errorCode, message){
	try{
		var progress = new FileProgress(file, this.customSettings.progressTarget);
		switch (errorCode){
		case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
			progress.setStatus("swfExclamation");
			setTimeout(function (){
				fadeOut(file.id, 100);
			},   10000);
			break;
		case SWFUpload.UPLOAD_ERROR.IO_ERROR:
			swfUploadErrorDiv("Er is een fout opgetreden in de verbinding. Probeer het nog eens.");
			progress.setStatus("swfExclamation");
			var self = this;
			self.cancelQueue();
			setTimeout(function () {
				fadeOut(file.id, 100);
			},   10000);
			break;
		case UPLOAD_LIMIT_EXCEEDED:
			swfUploadErrorDiv("Je hebt te veel bestanden tegelijk geselecteerd.");
			progress.setStatus("swfExclamation");
			setTimeout(function () {
				fadeOut(file.id, 100);
			},   10000);
			break;
		default:
			swfUploadErrorDiv("Er is een onbekende fout opgetreden.");
			progress.setStatus("swfExclamation");
			setTimeout(function () {
				fadeOut(file.id, 100);
			},   10000);
			break;
		
		}
	} catch (ex) {
        this.debug(ex);
    }
}

function fileQueueError(file, errorCode, message) {
	try {
		switch (errorCode) {
		case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
			swfUploadErrorDiv(file.name + ": dit bestand is leeg.");
			break;
		case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
			swfUploadErrorDiv(file.name + ": Deze afbeelding is te groot. Verklein de afbeelding en probeer het opnieuw.");
			break;
		case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
			swfUploadErrorDiv(file.name + ": Er is een onbekende fout opgetreden.");
			break;
		default:
			swfUploadErrorDiv(file.name + ": Er is een onbekende fout opgetreden.");
			break;
		}
	} catch (ex) {
		this.debug(ex);
	}
}

function swfUploadLoadFailed() {
	clearTimeout(this.customSettings.loadingTimeout);
	//document.getElementById("divLoadingContent").style.display = "none";
	//document.getElementById("divLongLoading").style.display = "none";
	document.getElementById("swfUploadConfirmed").style.display		= "none";
	document.getElementById("swfFallback").style.display			= "block";
	document.getElementById("divAlternateContent").style.display	= "block";
}

function swfUploadPreLoad() {
	var self = this;
	var loading = function () {
		//document.getElementById("divLoadingContent").style.display = "block";
		var longLoad = function () {
			//document.getElementById("divLoadingContent").style.display = "none";
			//document.getElementById("divLongLoading").style.display = "block";
		};
		this.customSettings.loadingTimeout = setTimeout(function () {
				longLoad.call(self)
			},
			15 * 1000
		);
	};
	this.customSettings.loadingTimeout = setTimeout(function () {
			loading.call(self);
		},
		1*1000
	);
}

function swfUploadLoaded() {
	var self = this;
	clearTimeout(this.customSettings.loadingTimeout);
	//document.getElementById("divLoadingContent").style.display = "none";
	//document.getElementById("divLongLoading").style.display = "none";
	document.getElementById("divAlternateContent").style.display = "none";
}

function fileQueued(file) {
	try {
		var progress = new FileProgress(file, this.customSettings.upload_target);
		progress.setStatus("progressCancel");
	} catch (ex) {
		this.debug(ex);
	}
}

function swfUploadErrorDiv(errorText){
	var swfErrorDivWrapper = document.getElementById("swfUploadErrorDivwrapper");
	var swfErrorDiv = document.createElement("div");
	swfErrorDiv.className = "swfUploadErrorDiv";
	var swfErrorDivId = rnd();
	swfErrorDiv.id = swfErrorDivId;
	swfErrorDiv.appendChild(document.createTextNode(errorText));
	swfErrorDivWrapper.appendChild(swfErrorDiv);
	fadeIn(swfErrorDiv, 0);
	setTimeout(function () {
	  fadeOut(swfErrorDivId, 100);
	}, 15000);
}

function rnd(){ 
  return String((new Date()).getTime()).replace(/\D/gi,'') 
}

function fileDialogComplete(numFilesSelected, numFilesQueued) {
	try {
		if (numFilesQueued > 0) {
			this.startUpload();
		}
	} catch (ex) {
		this.debug(ex);
	}
}

function uploadProgress(file, bytesLoaded) {
	try {
		var percent = Math.ceil((bytesLoaded / file.size) * 100);
		var progress = new FileProgress(file,  this.customSettings.upload_target);
		progress.setProgress(percent);
		if (percent === 100) {
		//Thumbnail aanmaken...
		  if(!(this.gedaan == 1)){
		    var oThumbnails = document.getElementById("thumbnails");
		    var SwfUploadNewDiv = document.createElement('div');
		    SwfUploadNewDiv.id = "swfUpload_SwfUploadNewDiv_image";
		    SwfUploadNewDiv.className = "imagedivLoading";
		    var firstDiv = oThumbnails.firstChild;
		    oThumbnails.insertBefore(SwfUploadNewDiv,firstDiv);
		    this.gedaan = 1
	  	  }
		  progress.setProgress(100);
		  progress.setStatus("progressCancel");
		} 
		else{
			//Opslaan... 
			progress.setStatus("progressCancel");
		}
	} catch (ex) {
		this.debug(ex);
	}
}

function uploadSuccess(file, serverData) {
	try {
		var progress = new FileProgress(file,  this.customSettings.upload_target);
		if (serverData.substring(0, 7) === "FILEID:") {
			//Thumbnail aangemaakt.
			var hiddenInputDiv = document.getElementById("hiddenInputDiv");
			addImage(swfMiniFolder + serverData.substring(7));
			progress.setStatus("swfCheckmark");
			progress.setProgress(100);
			swfSuccesCounter++;
			this.gedaan = 0;
		} 
		else {
			if(serverData.substring(0, 9) === "max_fotos"){
				swfUploadErrorDiv("Je hebt het maximaal aantal foto's bij je fotoalbum geplaatst. Verwijder eerst een aantal bestaande foto's uit je fotoalbum voordat je nieuwe toevoegt.");
				var self = this;
				self.cancelQueue();
				swfCancelThis(file.id);
			}
			else if(serverData.substring(0, 8) === "te_klein"){
				swfUploadErrorDiv(file.name + ": Deze afbeelding is te klein.");
				swfCancelThis(file.id);
			}
			else if(serverData.substring(0, 8) === "te_groot"){
				swfUploadErrorDiv(file.name + ": Deze afbeelding is te groot. Verklein de afbeelding en probeer het opnieuw.");
				swfCancelThis(file.id);
			}
			else if(serverData.substring(0, 13) === "niet_ingelogd"){
				swfUploadErrorDiv("Je bent niet ingelogd. Log in en probeer het opnieuw.");
				var self = this;
				self.cancelQueue();
				swfCancelThis(file.id);
			}
			else if(serverData.substring(0, 13) === "extentie_fout"){
				swfUploadErrorDiv(file.name + ": Deze afbeelding is ongeldig.");
				var self = this;
				self.cancelQueue();
				swfCancelThis(file.id);
			}
			else{
				swfUploadErrorDiv(file.name + ": Er is een onbekende fout opgetreden:");//serverData
				swfCancelThis(file.id);
			}
			setTimeout(function () {
			  fadeOut(file.id, 100);
			}, 10000);
			var oThumbnails = document.getElementById("thumbnails");
			oThumbnails.removeChild(oThumbnails.childNodes[0]);
			progress.setStatus("swfExclamation");
			progress.setProgress(100);
			this.gedaan = 0;
		}
	} catch (ex) {
		this.debug(ex);
	}
}

function swfCancelThis(fileid){
	var SwfProgressWrapper = document.getElementById(fileid);
	SwfProgressWrapper.className = "progressWrapper";
	var SwfProgressContainer = SwfProgressWrapper.firstChild;
	var SwfProgressSpan = SwfProgressContainer.childNodes[1];
	var swfProgressBar = SwfProgressSpan.childNodes[0];
	swfProgressBar.className = "completed";
}

function uploadComplete(file) {
	try {
		if (this.getStats().files_queued > 0) {
			this.startUpload();
		} else {
			var progress = new FileProgress(file,  this.customSettings.upload_target);
			//Afbeeldingen opgeslagen.
			if(swfSuccesCounter > 0){
				var swfUploadSuccesDivwrapper = document.getElementById("swfUploadSuccesDivwrapper");
				var swfUploadSuccesDiv = document.createElement("div");
				swfUploadSuccesDiv.className = "swfUploadSuccesDiv";
				swfUploadSuccesDiv.style.display = "block";
				var swfUploadSuccesDivId = rnd();
				swfUploadSuccesDiv.id = swfUploadSuccesDivId;
				if(swfSuccesCounter > 1){
					swfUploadSuccesDiv.appendChild(document.createTextNode(swfSuccesCounter + " foto's zijn verstuurd en wachten op activatie door de redactie."));
				}
				else{
					swfUploadSuccesDiv.appendChild(document.createTextNode(swfSuccesCounter + " foto is verstuurd en wacht op activatie door de redactie."));
				}
				swfUploadSuccesDivwrapper.appendChild(swfUploadSuccesDiv);
				fadeIn(swfUploadSuccesDiv, 0);
				setTimeout(function () {
					fadeOut(swfUploadSuccesDiv.id, 100);
				}, 15000);
				swfSuccesCounter = 0;
			}
			progress.setProgress(100);
		}
	} catch (ex) {
		this.debug(ex);
	}
}

function fieldEnter(element,keycode,srcId) {
	if (keycode == "13") {
		elem = document.getElementById(srcId);
		inputChange(escape(elem.id), escape(element.value));
		var inputTextSubmitbtn = document.getElementById(srcId + ".inputTextSubmitbtn");
		inputTextSubmitbtn.style.display = "none";
	} 
	else {
		return true;
	}
	swfElement = "";
	swfSrcId = "";
}

function toonToets(e){
	var code;
	if (!e){
		var e = window.event;
	}
	if (e.keyCode){
		code = e.keyCode;
	}
	else if (e.which){
		code = e.which;
	}
	if(code == 13){
		fieldEnter(swfElement, code, swfSrcId)
	}
}

function editBox(actual){
	var swfThisParent = actual.parentNode.parentNode.id;
	if(disableSwfInput[swfThisParent] != true){
		if(!changing){
			var newInputChild = document.createElement("input");
			newInputChild.id = actual.id;
			newInputChild.className = "swfInputText";
			newInputChild.style.maxlength = "50";
			newInputChild.type = "text";
			addEvent(newInputChild, 'focus', function() { highLight(newInputChild) } ); 
			addEvent(newInputChild, 'blur', function() { fieldBlur(newInputChild, actual.id) } );
			swfElement = newInputChild;
			swfSrcId = actual.id;
			addEvent(newInputChild, 'keypress', toonToets);
			if(actual.firstChild.data != "Voer titel in"){
				newInputChild.value = actual.firstChild.data;
			}
			actual.replaceChild(newInputChild, actual.firstChild);
			var inputTextSubmitbtn = document.getElementById(actual.id + ".inputTextSubmitbtn");
			inputTextSubmitbtn.style.display = "";
			changing = true;
			actual.firstChild.focus();
		}
	}
}

function highLight(a){
	a.style.border = "1px solid #CCC";
	a.style.background = "#FFF";
}

function fieldBlur(inputBox,srcId) {
	var inputTextSubmitbtn = document.getElementById(srcId + ".inputTextSubmitbtn");
	inputTextSubmitbtn.style.display = "none";
	elem = document.getElementById( srcId );
	inputChange(escape(elem.id), escape(inputBox.value));
}

function inputChange(elemId, inputBoxValue){
	var url = "image_uploader/ajax.php";
	var params = "action=swfChangeTitle&fieldname=" + elemId + "&content=" + inputBoxValue + "&random="+Math.round(999999*Math.random());
	var method = "post";
	var forcecall = true;
	ajaxCall(url, params, method, forcecall);
}

function changeEditBoxNow(content){
	if (content.length > 50){
	  content = content.substring(0, 50) + "";
	}
	var swfInputNewText = document.createTextNode(content);
	elem.removeChild(elem.firstChild);
	elem.appendChild(swfInputNewText);
	changing = false;
	return false;
}

function addImage(src) {
	var newImg = document.createElement("img");
	var SwfUploadNewDiv = document.getElementById("swfUpload_SwfUploadNewDiv_image");
	SwfUploadNewDiv.style.opacity = "0";
	var swfEditDiv = document.createElement("div");
	var swfEditHref = document.createElement("a");
	swfEditHref.className = "swfEditText";
	swfEditHref.id = src + "editDiv";
	swfEditHref.appendChild(document.createTextNode("Voer titel in"));
	swfEditHref.title = "Klik hier om de titel te wijzigen";
	var inputOpslaanButton = document.createElement("input");
	inputOpslaanButton.id = src + "editDiv.inputTextSubmitbtn";
	inputOpslaanButton.type = "image";
	inputOpslaanButton.value = "opslaan";
	inputOpslaanButton.className = "inputOpslaanButton";
	inputOpslaanButton.src = "images/interface/btn_kl_gr_opslaan.gif";
	inputOpslaanButton.style.display = "none";
	var swfDelHref = document.createElement("a");
	swfDelHref.className = "swfLink";
	var swfDeleteDiv = document.createElement("div");
	var swfNewDelImg = document.createTextNode("verwijder foto");
	var swfNewBR = document.createElement("br");
	var swfNextBR = document.createElement("br");
	var swfHoofdHref = document.createElement("a");
	swfHoofdHref.className = "swfLink";
	swfHoofdHref.id = src + ".hoofdfotohref";
	var swfHoofdFoto = document.createTextNode("selecteer als profielfoto");
	swfHoofdHref.appendChild(swfHoofdFoto);
	var swfNotActive = document.createElement("div");
	swfNotActive.className = "swfNotActive";
	var swfNotActiveText = document.createTextNode("(wacht op activatie door redactie)");
	swfNotActive.appendChild(swfNotActiveText);
	var swfImageSelfDiv = document.createElement("div");
	swfImageSelfDiv.className = "imageself";
	swfDelHref.appendChild(swfNewDelImg);
	addEvent(swfEditHref, 'click', function() { editBox(swfEditHref); } ); 
	addEvent(swfDelHref, 'click', function() { deletePhoto(src) } ); 
	addEvent(swfHoofdHref, 'click', function() { hoofdPhoto(src) } ); 
	swfEditDiv.appendChild(swfEditHref);
	newImg.onload = function () {
		swfImageSelfDiv.style.backgroundImage = 'url("image_uploader/' + src + '")';
		fadeIn(SwfUploadNewDiv, 0);
	};
	newImg.src = "image_uploader/" + src;
	newImg.style.display = "none";
	SwfUploadNewDiv.className = "imagediv";
	SwfUploadNewDiv.id = src;
	SwfUploadNewDiv.appendChild(swfImageSelfDiv);
	swfImageSelfDiv.appendChild(newImg);
	SwfUploadNewDiv.appendChild(swfEditDiv);
	SwfUploadNewDiv.appendChild(inputOpslaanButton);
	swfDeleteDiv.className = "swfbuttonlinks";
	swfDeleteDiv.appendChild(swfDelHref);
	swfDeleteDiv.appendChild(swfNewBR);
	swfDeleteDiv.appendChild(swfHoofdHref);
	swfDeleteDiv.appendChild(swfNextBR);
	swfDeleteDiv.appendChild(swfNotActive);
	SwfUploadNewDiv.appendChild(swfDeleteDiv);
}

function addEvent(obj, evType, fn) {
	if (obj.addEventListener){
	    obj.addEventListener(evType, fn, false);
	    return true;
	}
	else if (obj.attachEvent){
	    var r = obj.attachEvent("on"+evType, fn);
	    return r; 
	}
	else{
	    return false; 
	}
}

document.getElementsByClassName = function (needle){
    var s = [], r = [], undefined;
    var e = document.documentElement || document.body;
    var re = new RegExp('(^|\\s)' + needle + '(\\s|$)');
    while (e !== undefined){
        while (e){
            if (e.nodeType == 1){
                if (e.className && re.test(e.className)) r.push(e);
                s.push(e.firstChild);
            }
            e = e.nextSibling;
        }
        e = s.pop();
    }
    return r;
}

function makeWhite(element){
	var allimageDivs = document.getElementsByClassName("imagediv");
	var numImageDivs = allimageDivs.length;
	for(var i=0;i<numImageDivs;i++){
		allimageDivs[i].style.background = "white";
	}
	var swfhoofdhref = document.getElementsByClassName("swfHoofdfotoSelected");
	var numhoofdhrefs = swfhoofdhref.length;
	for(var i=0;i<numhoofdhrefs;i++){
		swfhoofdhref[i].innerHTML = "selecteer als profielfoto";
		swfhoofdhref[i].className = "swfLink";
	}
	var swfImagediv = document.getElementById(element);
	var swfhoofdhref = document.getElementById(element + ".hoofdfotohref");
	swfhoofdhref.className = "swfHoofdfotoSelected";
	
	if ( swfhoofdhref.hasChildNodes() ){
		while ( swfhoofdhref.childNodes.length >= 1 ){
			swfhoofdhref.removeChild( swfhoofdhref.firstChild );       
		}
	}
	var swfhoofdNewhref = document.createTextNode("profielfoto");
	swfhoofdhref.appendChild(swfhoofdNewhref);
	swfImagediv.style.background = "#FEF6ED";
}

FileProgress.prototype.disappear = function () {
	var reduceOpacityBy = 5; 
	var rate = 30;
	if (this.opacity > 0){
		this.opacity -= reduceOpacityBy;
		if (this.opacity < 0){
			this.opacity = 0;
		}
		if (this.fileProgressWrapper.filters){
			try {
				this.fileProgressWrapper.filters.item("DXImageTransform.Microsoft.Alpha").opacity = this.opacity;
			} catch (e) {
				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
				this.fileProgressWrapper.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + this.opacity + ")";
			}
		} else {
			this.fileProgressWrapper.style.opacity = this.opacity / 100;
		}
	}
	if (this.opacity > 0) {
		var oSelf = this;
		setTimeout(function () {
			oSelf.disappear();
		}, rate);
	} else {
		this.fileProgressWrapper.style.display = "none";
	}
};

function fadeOut(element, opacity) {
	disableSwfInput[element] = true;
	this.element = document.getElementById(element);
	var reduceOpacityBy = 5;
	var rate = 30;
	if (opacity > 0) {
		opacity -= reduceOpacityBy;
		if (opacity < 0) {
			opacity = 0;
		}
		if (this.element.filters) {
			try {
				this.element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
			} catch (e) {
				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
				this.element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')';
			}
		} else {
			this.element.style.opacity = opacity / 100;
		}
	}
	if (opacity > 0) {
		setTimeout(function () {
			fadeOut(element, opacity);
		}, rate);
	}
	else{
	  if(this.element.className == "imagediv"){
		if (this.element.filters) {
			try {
				this.element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = 100;
			} catch (e) {
				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
				this.element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + 100 + ')';
			}
		} else {
			this.element.style.opacity = 1;
		}
		if (this.element.hasChildNodes() )
		{
			while (this.element.childNodes.length >= 1 )
			{
				this.element.removeChild(this.element.firstChild );       
			} 
		}
		this.element.className = "imagedivLoading";
	  }
	  else{
	    this.element.style.display = "none";
	  }
		delete disableSwfInput[element];
	}
}

function fadeIn(element, opacity) {
	element.style.backgroundColor = element.style.backgroundColor; /*IE6 HACK*/
	var reduceOpacityBy = 2.5;
	var rate = 30;
	if (opacity < 100) {
		opacity += reduceOpacityBy;
		if (opacity > 100) {
			opacity = 100;
		}
		if (element.filters) {
			try {
				element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
			} catch (e) {
				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
				element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')';
			}
		} else {
			element.style.opacity = opacity / 100;
		}
	}
	if (opacity < 100) {
		setTimeout(function () {
			fadeIn(element, opacity);
		}, rate);
	}
}

function deletePhoto(src){
	if(disableSwfInput[src] != true){
		if(confirm('Weet je zeker dat je deze foto wilt verwijderen?')){
			fadeOut(src, 100)
			var url = "image_uploader/ajax.php";
			var params = "action=deletePhoto&src=" + src + "&random="+Math.round(999999*Math.random());
			var method = "post";
			var forcecall = true;
			ajaxCall(url, params, method, forcecall);
		}
	}
}

function hoofdPhoto(src){
	if(disableSwfInput[src] != true){
		var url = "image_uploader/ajax.php";
		var params = "action=hoofdPhoto&src=" + src + "&random="+Math.round(999999*Math.random());
		var method = "post";
		var forcecall = true;
		ajaxCall(url, params, method, forcecall);
	}
}

function FileProgress(file, targetID) {
	this.fileProgressID = file.id;
	this.opacity = 100;
	this.fileProgressWrapper = document.getElementById(this.fileProgressID);
	if (!this.fileProgressWrapper) {
		this.fileProgressWrapper = document.createElement("div");
		this.fileProgressWrapper.className = "progressWrapper";
		this.fileProgressWrapper.id = this.fileProgressID;
		this.fileProgressElement = document.createElement("div");
		this.fileProgressElement.className = "progressContainer";
		var progressCancel = document.createElement("div");
		progressCancel.className = "progressCancel";
		progressCancel.appendChild(document.createTextNode(" "));
		var progressText = document.createElement("div");
		progressText.className = "progressName";
		this.progressName = document.createElement("div");
		this.progressName.className = "progressSpan";
		if (file.name.length > 50){
			file.name = file.name.substring(0, 50) + "...";
		}
		this.progressName.appendChild(progressText);
		this.fileProgressElement.appendChild(progressCancel);
		this.fileProgressElement.appendChild(this.progressName);
		this.fileProgressWrapper.appendChild(this.fileProgressElement);
		document.getElementById(targetID).appendChild(this.fileProgressWrapper);
		fadeIn(this.fileProgressWrapper, 0);
		var SwfUploadNewDivProgress = document.createElement("div");
		SwfUploadNewDivProgress.style.position = "absolute";
		SwfUploadNewDivProgress.style.marginLeft = "15px";
		SwfUploadNewDivProgress.appendChild(document.createTextNode(file.name));
		this.progressName.appendChild(SwfUploadNewDivProgress);
	} 
	else {
		this.fileProgressElement = this.fileProgressWrapper.firstChild;
		this.span = this.fileProgressElement.childNodes[1];
		this.progressName = this.span.childNodes[1];
	}
	this.height = this.fileProgressWrapper.offsetHeight;
}

FileProgress.prototype.setProgress = function (percentage) {
	if (!(percentage == 100)){
		this.span.childNodes[0].className = "progressBarInProgress";
		this.fileProgressWrapper.className = "progressWrapperActive";
	}
	percentage = percentage * 3.85;
	this.span.childNodes[0].style.width = percentage + "px";
	if (this.status == "swfCheckmark"){
		this.fileProgressWrapper.className = "progressWrapper";
		var oSelf = this;
		setTimeout(function () {
			oSelf.disappear();
		},   10000);
		this.span.childNodes[0].className = "completed";
		this.span.childNodes[1].className = "textcompleted";
	}
	if (this.status == "swfExclamation"){
		this.fileProgressWrapper.className = "progressWrapper";
		var oSelf = this;
		setTimeout(function () {
			oSelf.disappear();
		},   10000);
		this.span.childNodes[0].className = "completed";
		this.span.childNodes[1].className = "textcompleted";
	}
};

FileProgress.prototype.setStatus = function (status) {
	this.status = status;
	this.fileProgressElement.childNodes[0].className = status;
	this.fileProgressElement.childNodes[0].innerHTML = "&nbsp;";
};

SWFUpload.prototype.cancelQueue = function () {
	this.customSettings.queue_cancelled_flag = true;
	var stats = this.getStats();
	this.fileProgressContainer = document.getElementById("divFileProgressContainer");
	while (stats.files_queued > 0) {
		this.cancelUpload();
		stats = this.getStats();
	}
};

function checkVarsToEnable(){
	if(alleHash[hashSelected-1] == undefined){
		enableDisable('vorigeDisabled');
	}
	else{
		enableDisable('vorigeEnabled');
	}
	if(alleHash[hashSelected+1] == undefined){
		enableDisable('volgendeDisabled');
	}
	else{
		enableDisable('volgendeEnabled');
	}
}

function changeGalleryImage(direction) {
	if(direction == 'next'){
		hashSelected++;
		titelSelected++;
		changeImageTo(alleHash[hashSelected], alleTitels[titelSelected]);
		bouwNummersOp();
	}
	else if(direction == 'back'){
		hashSelected--;
		titelSelected--;
		changeImageTo(alleHash[hashSelected], alleTitels[titelSelected]);
		bouwNummersOp();
	}
	else{
		changeImageTo(alleHash[direction], alleTitels[direction]);
		hashSelected = direction;
		titelSelected = direction;
		bouwNummersOp();
	}
	checkVarsToEnable();
}

function changeImageTo(hash, titel){
	var changeTitle = document.getElementById("changeTitle");
	changeTitle.removeChild(changeTitle.firstChild);
	var newChangeTitle = document.createTextNode(titel);
	changeTitle.appendChild(newChangeTitle);
	var changeImageWrapper = document.getElementById("changeImageWrapper");
	var changeAbleImage = document.getElementById("changeImageId");
	changeImageWrapper.removeChild(changeAbleImage);
	changeImageWrapper.className = "changeImageWrapperLoading";
	var newChangeImage = document.createElement("img");
	newChangeImage.id = "changeImageId";
	newChangeImage.className = "newChangeImage";
	newChangeImage.style.display = "none";
	newChangeImage.onload = function () {
		changeImageWrapper.className = "changeImageWrapper";
		newChangeImage.style.display = "";
		var newChangeImageHeight = newChangeImage.height + 20 + "px";
		changeImageWrapper.style.height = newChangeImageHeight;
	};
	newChangeImage.src = "image_uploader/" + swfNormalFolder + hash + ".jpg";
	changeImageWrapper.appendChild(newChangeImage);
	addEvent(newChangeImage, 'click', function() { fotoPopup(hashSelected); } ); 
}

function fotoPopup(fotono) {
	var fotoprofile_member = open("foto_popup.php?foto=" + alleHash[fotono], alleHash[fotono], "width=" + url_width[fotono] + ",height=" + url_height[fotono] + ",location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
	fotoprofile_member.focus();
}

function enableDisable(button){
	if(button == 'vorigeDisabled'){
		var vorigeButton = document.getElementById("vorigeButton");
		vorigeButton.className = "greyButtonDisabled";
	}
	if(button == 'volgendeDisabled'){
		var volgendeButton = document.getElementById("volgendeButton");
		volgendeButton.className = "greyButtonDisabled";
	}
	if(button == 'vorigeEnabled'){
		var vorigeButton = document.getElementById("vorigeButton");
		vorigeButton.className = "blueButtonEnabled";
	}
	if(button == 'volgendeEnabled'){
		var volgendeButton = document.getElementById("volgendeButton");
		volgendeButton.className = "blueButtonEnabled";
	}
}

function bouwNummersOp(){
	//allemaal verwijderen
	var numericLinks = document.getElementById("numericLinks");
	if ( numericLinks.hasChildNodes() ){
		while ( numericLinks.childNodes.length >= 1 ){
			numericLinks.removeChild( numericLinks.firstChild );       
		} 
	}
	//allemaal opbouwen
	if(alleHash.length > 1){
		for(var i=hashSelected-4;i<hashSelected+5;++i){
			if((i >= 0) && (i < aantalNummerLinks)){
				if(i == hashSelected){
					var nieuwNummerSelected = document.createElement("a");
					var ditNummer = document.createTextNode("foto" + (i+1));
					nieuwNummerSelected.className = "ditNummerSelected";
					nieuwNummerSelected.id = "ditNummer" + i;
					nieuwNummerSelected.appendChild(ditNummer);
					nieuwNummerSelected.href = "javascript:changeGalleryImage(" + i + ");";
					nieuwNummerSelected.style.cursor = "text";
					numericLinks.appendChild(nieuwNummerSelected);
					if((i+1) != (hashSelected+5)){
						if((i+1) < aantalNummerLinks){
							var nieuweSpatie = document.createTextNode(" | ");
							numericLinks.appendChild(nieuweSpatie);
						}
					}
				}
				else{
					nieuwNummer[i] = document.createElement("a");
					var ditNummer = document.createTextNode(i+1);
					nieuwNummer[i].className = "ditNummer";
					nieuwNummer[i].appendChild(ditNummer);
					nieuwNummer[i].id = "ditNummer" + i;
					nieuwNummer[i].href = "javascript:changeGalleryImage(" + i + ");";
					numericLinks.appendChild(nieuwNummer[i]);
					if((i+1) != (hashSelected+5)){
						if((i+1) < aantalNummerLinks){
							var nieuweSpatie = document.createTextNode(" | ");
							numericLinks.appendChild(nieuweSpatie);
						}
					}
				}
			}
		}
	}
}