function initCheck() {
	theTable = document.getElementById('expressionList');
	if (theTable) {
		theAnchors = theTable.getElementsByTagName('a');
		allDivs = theTable.getElementsByTagName('div');
		for (i=0;i<theAnchors.length;i++) {
			if (theAnchors[i].className == 'checkLink') {
				theAnchors[i].parentNode.parentNode.attributes['onclick'].value = '';
				//theAnchors[i].parentNode.parentNode.getElementsByTagName('input')[0].attributes['onclick'].value = '';
				theTds = theAnchors[i].parentNode.parentNode.getElementsByTagName('td');
				for (j=0;j<theTds.length;j++) {
					if (theTds[j]!=theAnchors[i].parentNode) {							
						theTds[j].onclick = function() {
							this.parentNode.getElementsByTagName('input')[0].checked=this.parentNode.getElementsByTagName('input')[0].checked?false:true;
						}
					}
				}
				theAnchors[i].onclick = function() {
					for (k=0;k<allDivs.length;k++) {
						if (allDivs[k].className=='check' && allDivs[k] != this.parentNode.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('div')[0]) {
							allDivs[k].style.display = 'none';
							for (j=0;j<theAnchors.length;j++) {
								if (theAnchors[j].className == 'checkLink' && theAnchors[j]!=this) {
									theAnchors[j].style.backgroundImage = 'url(media/arrowsmlI.gif)';
								}
							}
						}
					}
					theDivs = this.parentNode.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('div');
					for (j=0;j<theDivs.length;j++) {
						if (theDivs[j].className=='check') {
							theDivs[j].style.display = theDivs[j].style.display!='block' ? 'block' : 'none';
						}
					}
					this.style.backgroundImage = this.style.backgroundImage!='url(media/arrowsmlA.gif)'?'url(media/arrowsmlA.gif)':'url(media/arrowsmlI.gif)';
					return false;
				}
			}
		}
	}
}

function initSend() {
	theForm = document.getElementById('sendExpression');
	theSend = document.getElementById('expressionSubmit');
	theTable = document.getElementById('expressionList');
	if (theTable && theSend) {
		allInputs = theTable.getElementsByTagName('input');				
		theImgs = theTable.getElementsByTagName('img');				
		theSend.onclick = function() {
			allCheck = false;
			sendIt = true;
			for(k=0;k<allInputs.length;k++) {
				if (allInputs[k].type=='checkbox') {
					if (allInputs[k].checked) allCheck = true;
				}
			}
			for (i=0;i<theImgs.length;i++) {
				if (theImgs[i].src.indexOf('icon_incomplete.gif')!=-1) {
					theInputs = theImgs[i].parentNode.parentNode.getElementsByTagName('input');
					for (j=0;j<theInputs.length;j++) {
						if (theInputs[j].type=='checkbox') {
							if (theInputs[j].checked) sendIt = false;
						}
					}
				}
			}
			if(!allCheck) {
				alert('U heeft geen uitingen gekozen...');
				return false;
			} else {
				if (sendIt) {
					if (confirm('Uitingen gechecked. Verzenden?')) {
						theForm.submit();
					} else {
						return false;
					}
				} else {
					if (confirm('Gekozen uitingen zijn niet compleet. Toch verzenden?')) {
						theForm.submit();
					} else {
						return false;
					}
				}
			}
			return false;
		}
		return false;
	}
	return false;
}

function initToggle(obj) {
	theForm = $(obj);
	if ($defined(theForm)) {
		allLinks = $$('#'+obj+' .toggle');
		//allDivs = textForm.getElementsByTagName('div');
		for (i=0;i<allLinks.length;i++) {			
			allLinks[i].mySlide = new Fx.Slide(allLinks[i].getAttribute('toggleId'));
			allLinks[i].mySlide.hide();
			if ($defined($(allLinks[i].getAttribute('scrollbox')))) $(allLinks[i].getAttribute('scrollbox')).style.overflowY='hidden';
			allLinks[i].onclick = function() {
				//document.getElementById(this.getAttribute('toggleId')).style.display = document.getElementById(this.getAttribute('toggleId')).style.display!='block' ? document.getElementById(this.getAttribute('toggleId')).style.display = 'block' : document.getElementById(this.getAttribute('toggleId')).style.display = 'none';
				if (obj == 'picteditor') {
					this.mySlide.toggle();
					this.style.backgroundImage = this.style.backgroundImage != 'url(media/arrow_up.gif)' ? 'url(media/arrow_up.gif)' : 'url(media/arrow_down.gif)';
					if (this.getAttribute('objId') != null && this.getAttribute('objId') != '' && this.style.backgroundImage.indexOf('arrow_up.gif') != -1) {
						listId = this.getAttribute('listId');
						new Ajax('/Ajax/'+this.getAttribute('lib')+'.php', {
							method: 'get',
							data: 'id='+this.getAttribute('objId')+"&className="+$('class_name').value+"&list="+this.getAttribute('list')+"&listId="+this.getAttribute('listId'),
							update: $(this.getAttribute('list')),
							onComplete: function() {
								switch (listId) {
									case "pictlist":
									initPict(maxPict);
									break
									case "bglist":
									initBack(maxBg);
									break
									case "facadelist":
									initFacade();
									break
									case "fontlist":
									initFont();
									break
								}
							},
							onFailure : failTekst
						}).request();
					}
				} else {
					scrollboxId = this.getAttribute('scrollbox');
					if($(scrollboxId).style.overflowY=='scroll'||$(scrollboxId).style.overflowY=='') {
						$(scrollboxId).style.overflowY='hidden';
						this.mySlide.toggle();
						this.style.backgroundImage = 'url(media/arrow_down.gif)';
					} else {
						//this.myslide.scrollbox.value = this.getAttribute('scrollbox');
						this.mySlide.toggle().chain(function() {
							$(scrollboxId).style.overflowY='scroll';
						});
						this.style.backgroundImage = 'url(media/arrow_up.gif)';
					}
				}
				return false;
			}
		}
	}
}

function initExampleToggle() {
	var status = {
		'true': 'open',
		'false': 'close'
	};
	
	if ($('example') && $('exampleToggle')) {
		var exampleSlide = new Fx.Slide('example');
		
		var state = Cookie.read(kenmerk);
		if (state=='close') {
			exampleSlide.hide();
			$('exampleToggle').style.backgroundImage = 'url(/media/arrow_down.gif)';
		}
		
		$('exampleToggle').addEvent('click', function(e){
			e.stop();
			exampleSlide.toggle();
			this.style.backgroundImage = this.style.backgroundImage!='url(/media/arrow_down.gif)'?'url(/media/arrow_down.gif)':'url(/media/arrow_up.gif)';
		});
		exampleSlide.addEvent('complete', function() {
			Cookie.write(kenmerk, status[exampleSlide.open]);
		});
	}
	
}


function loadBg(holder_id,code,search,remove,code_id) {
	var o = $(code);
	new Ajax('/Ajax/'+search+'.php', {
		method: 'get',
		data: 'id='+o.value+'&remove='+remove,
		update: $(holder_id).getElements('li')[0],
		onComplete: function() {
			$('bgholder').getElements('li')[0].style.backgroundImage = 'url("/media/bg_pictholder_hi.gif")';
		}
	}).request();
}

function initQuicksearchBg() {
	if ($('bgSnelzoeken')) {
		$('bgSnelzoeken').addEvent("click", function(evt) {
			new Event(evt).stop();
			searchImageCode('bgholder','background','searchBackground','removeBg','achtergrond_id',0);
		});
	}
}

function removeBg(del) { 
	if (maxBg > 1) {
		del.parentNode.innerHTML = ' ';
		setAllBg();
	} else {
		bgCount = 0;
		del.parentNode.style.backgroundImage = 'url("/media/bg_pictholder.gif")';
		$('achtergrond_id').value = '';
		del.parentNode.innerHTML = ' ';
	}
	return false;
}
/*
{ 
	del.parentNode.style.backgroundImage = 'url("/media/bg_pictholder.gif")';
	$('achtergrond_id').value = '';
	del.parentNode.innerHTML = ' ';
	return false;
}
*/


function loadFacade(holder_id,code,search,remove,code_id) {
	var bw = ($('class_name').value == 'UitingPersoneel') ? '1' : '0';
	var t = new Date();
	var o = $(code);
	
	new Ajax('/Ajax/'+search+'.php', {
		method: 'get',
		data: 'id='+o.value+'&remove='+remove+'&bw='+bw+'&t='+t.toString(),
		update: $(holder_id).getElements('li')[0],
		onComplete: function() {
			$('facadeholder').getElements('li')[0].style.backgroundImage = 'url("/media/bg_pictholder_hi.gif")';
		}
	}).request();
}

function initQuicksearchFacade() {
	if ($('facadeSnelzoeken')) {
		$('facadeSnelzoeken').addEvent("click", function(evt) {
			new Event(evt).stop();
			searchImageCode('facadeholder','facade','searchKader','removeFacade','kader_id',0);
		});
	}
}

function initFacade() {
	thePictForm = document.getElementById('picteditor');
	if (thePictForm) {
		theFacadeHolder = $('facadeholder');
		theFacadeList = $('facadelist');
		theFacadeLi = theFacadeHolder.getElements('li')[0];
		facadeItems = theFacadeList.getElements('a');
		facadeItems.each(function(facadeItem, i) {
			if (facadeItem.className!='delete') {
				facadeItem.addEvent("click", function(evt) {
					new Event(evt).stop();
					theFacadeLi.innerHTML = this.parentNode.innerHTML;
					theFacadeLi.innerHTML += '<br /><a href="#" class="delete"><img src="/media/icon_delimg.gif" alt="delete" /><\/a>';
					theFacadeLi.style.backgroundImage = 'url("/media/bg_pictholder_hi.gif")';
					$('kader_id').value = theFacadeLi.getElementsByTagName('a')[0].getAttribute('value');
					theFacadeLi.getElements('a')[0].onclick = function() { return false; }
					theFacadeLi.getElementsByTagName('a')[1].addEvent("click", function(e) {
						new Event(e).stop();
						this.parentNode.style.backgroundImage = 'url("/media/bg_pictholder.gif")';
						$('kader_id').value = '';
						this.parentNode.innerHTML = ' ';							
					});
				});
			}
		});
	}
}

function removeFacade(del) { 
	del.parentNode.style.backgroundImage = 'url("/media/bg_pictholder.gif")';
	$('kader_id').value = '';
	del.parentNode.innerHTML = ' ';
	return false;
}

function searchImageCode(holder_id,code,search,remove,inputId,count) {
	var o = $(code);
	if (o.value!='' && o.value!=' ') {
		new Ajax('/Ajax/'+search+'.php', {
			method: 'get',
			data: 'snelcode='+o.value+'&remove='+remove,
			update: $(holder_id).getElements('li')[count],
			onComplete: function(response) {
				if (response!='') {
					if (holder_id!='pictholder') {
						if ($(holder_id).getElements('a')[0]) {
							$(inputId).value = $(holder_id).getElements('a')[0].getAttribute('value');
							o.parentNode.parentNode.style.backgroundImage = '';
						}
					} else {
						setAll();
					}
				} else {
					o.parentNode.parentNode.style.backgroundColor = '';
					$(holder_id).getElements('li')[count].style.backgroundColor = '';
				}
			}
		}).request();
	}
}

function loadImage(count) {
	var theIds = $('afbeelding_id').value.split(",");
	dataValue = theIds[count];
	if (dataValue!='' && dataValue!=null) {
		countArray.push(count);
		pictCount = countArray.length;
		//alert($('pictholder').getElements('li')[i]);
		$('pictholder').getElements('li')[count].style.backgroundImage = 'url("/media/bg_pictholder_hi.gif")';
		new Ajax('/Ajax/searchImage.php', {
			method: 'get',
			data: 'id='+theIds[count]+'&remove=removeImg&edit=editImg',
			update: $('pictholder').getElements('li')[count]
/*
			onComplete: function() {
				initImageSlider($('afbeeldingSchaal').value);
			}
*/
		}).request();
	}
}

function initPict(max) {
	maxPict = max;
	pictCount = 0;
	if (maxPict > 1) initSort();
	thePictForm = document.getElementById('picteditor');
	if (thePictForm) {
		countArray = new Array();
		thePictTitles = $('picttitles');
		thePictHolder = $('pictholder');
		thePictList = $('pictlist');
		allLi = thePictHolder.getElements('li');
		if (allLi.length == 0) {
			for (var it=0;it<maxPict;it++) {
				var newLiTitle = new Element('li');
				newLiTitle.innerHTML = 'Afbeelding ' + (it+1);
				if (it==maxPict-1) newLiTitle.className = 'last';
				thePictTitles.adopt(newLiTitle);
				var newLi = new Element('li');
				newLi.innerHTML = ' ';
				if (it==maxPict-1) newLi.className = 'last';
				if (maxPict > 1) s.addItems(newLi);
				thePictHolder.adopt(newLi);
				if ($('afbeelding_id').value!='' && $('afbeelding_id').value!=null) {
					loadImage(it);
				}
			}
		} else {
			setAll();
		}
		if (thePictList) {
			
			pictItems = thePictList.getElements('a');
			pictItems.each(function(pictItem, i) {
				if (pictItem.className!='delete') {
					pictItem.addEvent("click", function(evt) {
						new Event(evt).stop();
						allLi = thePictHolder.getElements('li');
						if (pictCount <= maxPict-1 || maxPict == 1) {
							placeId = getFreePlacerHolder();
							allLi[placeId].innerHTML = this.parentNode.innerHTML;
							allLi[placeId].innerHTML += '<br /><a href="#" class="delete"><img src="/media/icon_delimg.gif" alt="delete" /><\/a>';
							allLi[placeId].innerHTML += '<a href="#" title="tester" class="edit"><img src="/media/icon_editimg.gif" alt="bewerk" /><\/a>';
							allLi[placeId].style.backgroundImage = 'url("/media/bg_pictholder_hi.gif")';

							theImgLink = allLi[placeId].getElementsByTagName('a')[0];
							theImgLink.onclick = function() { return false; }
							theDelete = allLi[placeId].getElementsByTagName('a')[1];
							theEdit = allLi[placeId].getElementsByTagName('a')[2];
							setAll();
							theDelete.onclick = function() {
								if (maxPict > 1) {
									this.parentNode.innerHTML = ' ';
									setAll();
								} else { 
									pictCount--
									this.parentNode.style.backgroundImage = 'url("/media/bg_pictholder.gif")';
									$('afbeelding_id').value = '';
									this.parentNode.innerHTML = ' ';
								};
								return false;
							}
							theEdit.onclick = function() {
								
								biszImage(this);
								return false;
							}
						} else {
							alert('U moet eerst een plaatje verwijderen voordat u een nieuwe toe kunt voegen');
						}
						return false;
					});
				}
			});
		}
	}
}

function initBack(max) {
	maxBg = max;
	bgCount = 0;
	if (maxBg > 1) initBgSort();
	theBgForm = document.getElementById('bgholder');
	if (theBgForm) {
		countArray = new Array();
		theBgHolder = $('bgholder');
		theBgTitles = $('bgtitles');
		theBgList = $('bglist');
		allBgLi = theBgHolder.getElements('li');
		if (allBgLi.length == 0) {
			for (var it=0;it<maxBg;it++) {
				var newLiTitle = new Element('li');
				newLiTitle.innerHTML = 'Achtergrond ' + (it+1);
				if (it==maxBg-1) newLiTitle.className = 'last';
				theBgTitles.adopt(newLiTitle);
				var newLi = new Element('li');
				newLi.innerHTML = ' ';
				if (it==maxBg-1) newLi.className = 'last';
				if (maxBg > 1) s.addItems(newLi);
				theBgHolder.adopt(newLi);
				if ($('achtergrond_id').value!='' && $('achtergrond_id').value!=null) {
					loadBack(it);
				}
			}
		} else {
			setAllBg();
		}
		if (theBgList) {
			var class_name = $('class_name').value;
			bgItems = theBgList.getElements('a');
			bgItems.each(function(bgItem, i) {
				if (bgItem.className!='delete') {
					bgItem.addEvent("click", function(evt) {
						new Event(evt).stop();
						allLi = theBgHolder.getElements('li');
						if (bgCount <= maxBg-1 || maxBg == 1) {
							placeBgId = getFreeBgPlacerHolder();
							allBgLi[placeBgId].innerHTML = this.parentNode.innerHTML;
							
							allBgLi[placeBgId].innerHTML += '<br /><a href="#" class="delete"><img src="/media/icon_delimg.gif" alt="delete" /><\/a>';
							if (class_name!='UitingPersoneel')
							{
								allBgLi[placeBgId].innerHTML += '<a href="#" title="tester" class="edit"><img src="/media/icon_editimg.gif" alt="bewerk" /><\/a>';
							}
							allBgLi[placeBgId].style.backgroundImage = 'url("/media/bg_pictholder_hi.gif")';

							theBgLink = allBgLi[placeBgId].getElementsByTagName('a')[0];
							theBgLink.onclick = function() { return false; }
							theDelete = allBgLi[placeBgId].getElementsByTagName('a')[1];
							if (class_name!='UitingPersoneel')
							{
								theEdit = allBgLi[placeBgId].getElementsByTagName('a')[2];
							}
							setAllBg();
							theDelete.onclick = function() {
								if (maxBg > 1) {
									this.parentNode.innerHTML = ' ';
									setAllBg();
								} else { 
									bgCount--
									this.parentNode.style.backgroundImage = 'url("/media/bg_pictholder.gif")';
									$('achtergrond_id').value = '';
									this.parentNode.innerHTML = ' ';
								};
								return false;
							}
							if (class_name!='UitingPersoneel')
							{
								theEdit.onclick = function() {
									
									biszImage(this);
									return false;
								}
							}
						} else {
							alert('U moet eerst een achtergrond verwijderen voordat u een nieuwe toe kunt voegen');
						}
						return false;
					});
				}
			});
		}
	}
}

function loadBack(count) 
{
	var theIds = $('achtergrond_id').value.split(",");
	dataValue = theIds[count];
	if (dataValue!='' && dataValue!=null) {
		countArray.push(count);
		bgCount = countArray.length;
		$('bgholder').getElements('li')[count].style.backgroundImage = 'url("/media/bg_pictholder_hi.gif")';
		new Ajax('/Ajax/searchBackground.php', {
			method: 'get',
			data: 'id='+theIds[count]+'&remove=removeBg&edit=editBg',
			update: $('bgholder').getElements('li')[count]
		}).request();
	}
}


function getFreePlacerHolder() {
	for (i=0;i<maxPict;i++) {
		if (thePictHolder.getElements('li')[i].innerHTML == ' ' || thePictHolder.getElements('li')[i].innerHTML == '') return i;
	}
	return 0;
}
function getFreeBgPlacerHolder() {
	for (i=0;i<maxBg;i++) {
		if (theBgHolder.getElements('li')[i].innerHTML == ' ' || theBgHolder.getElements('li')[i].innerHTML == '') return i;
	}
	return 0;
}

function removeBg(del)
{
	if (maxBg > 1) {
		del.parentNode.innerHTML = ' ';
		setAllBg();
	} else {
		bgCount = 0;
		del.parentNode.style.backgroundImage = 'url("/media/bg_pictholder.gif")';
		$('achtergrond_id').value = '';
		del.parentNode.innerHTML = ' ';
	}
	return false;
}
function editBg(edit)
{
	biszImage(edit);
	return false;
}

function removeImg(del) { 
	if (maxPict > 1) {
		del.parentNode.innerHTML = ' ';
		setAll();
	} else {
		pictCount = 0;
		del.parentNode.style.backgroundImage = 'url("/media/bg_pictholder.gif")';
		//$('pictcodes').getElements('li')[0].style.backgroundColor = '#e9eef5';
		$('afbeelding_id').value = '';
		del.parentNode.innerHTML = ' ';
	}
	return false;
}
function editImg(edit) { 
	biszImage(edit);
	return false;
}


function setAll() {
	pictCount = 0;
	$('afbeelding_id').value = '';
	for (i=0;i<maxPict;i++) {
		if (thePictHolder.getElements('li')[i].innerHTML != ' ' && thePictHolder.getElements('li')[i].innerHTML != '') {
			pictCount++;
			$('afbeelding_id').value += thePictHolder.getElements('li')[i].getElements('a')[0].getAttribute('title');
			if (maxPict>1 && i<maxPict-1) { 
				$("afbeelding_id").value += ',';
			}
			thePictHolder.getElements('li')[i].style.backgroundImage = 'url("/media/bg_pictholder_hi.gif")';
		} else {
			$('afbeelding_id').value += '';
			if (maxPict>1 && i<maxPict-1) { 
				$("afbeelding_id").value += ',';
			}
			thePictHolder.getElements('li')[i].style.backgroundImage = 'url("/media/bg_pictholder.gif")';
		}				
		thePictHolder.getElements('li')[i].className = i==maxPict-1 ? 'last' : '';
	}
}

function setAllBg() {
	bgCount = 0;
	$('achtergrond_id').value = '';
	for (i=0;i<maxBg;i++) {
		if (theBgHolder.getElements('li')[i].innerHTML != ' ' && theBgHolder.getElements('li')[i].innerHTML != '') {
			bgCount++;
			$('achtergrond_id').value += theBgHolder.getElements('li')[i].getElements('a')[0].getAttribute('title');
			if (maxBg>1 && i<maxBg-1) { 
				$("achtergrond_id").value += ',';
			}
			theBgHolder.getElements('li')[i].style.backgroundImage = 'url("/media/bg_pictholder_hi.gif")';
		} else {
			$('achtergrond_id').value += '';
			if (maxBg>1 && i<maxBg-1) { 
				$("achtergrond_id").value += ',';
			}
			theBgHolder.getElements('li')[i].style.backgroundImage = 'url("/media/bg_pictholder.gif")';
		}				
		theBgHolder.getElements('li')[i].className = i==maxBg-1 ? 'last' : '';
	}
}

function initSort() {
	s = new Sortables('pictholder', {				
		//revert: { duration: 500, transition: 'elastic:out' },
		opacity: 0.5,
		clone: false,
		constrain: false,
		onComplete: function(item) { setAll(); }
	});
}
function initBgSort() {
	s = new Sortables('bgholder', {				
		//revert: { duration: 500, transition: 'elastic:out' },
		opacity: 0.5,
		clone: false,
		constrain: false,
		onComplete: function(item) { setAllBg(); }
	});
}

function initImageSlider(val) {
/*
	imgScaler.set(100);
	imageSlider = $('imageslider');
	imageSlideButton = $('imageslidebutton');
	schaalInput = $('afbeeldingSchaal');
	scaleVal = $('scaleValue');
	scaleImg = $('pictholder').getElements('img')[0];
	scaleProportion = scaleImg.width/scaleImg.height * 100;
	schaalInput.value = val;
	var imgScaler = new Slider(imageSlider, imageSlideButton, {
		steps: 99,	// There are 100 steps
		range: [1,100],	// Minimum value is 1
		onChange: function(value){
				schaalInput.value = value;
				if (scaleProportion>=100) {
					scaleImg.width = 124*value/100;
					scaleImg.height = 124*value/scaleProportion;
				} else {
					scaleImg.width = (scaleProportion/100)*124*value/100;
					scaleImg.height = 124*value/100;
				}
				scaleVal.innerHTML = value + ' %';
		}
	}).set(val);
	
	if (schaalInput.value=='') {
		imgScaler.set(100);
	} else {
		imgScaler.set(schaalInput.value);
	}
*/
}

function loadFont(holder_id,code,search,remove,code_id) {
	var o = $(code);
	new Ajax('/Ajax/'+search+'.php', {
		method: 'get',
		data: 'id='+o.value+'&remove='+remove,
		update: $(holder_id).getElements('li')[0],
		onComplete: function() {
			$('fontholder').getElements('li')[0].style.backgroundImage = 'url("/media/bg_pictholder_hi.gif")';
		}
	}).request();
}

function initFont() {
	thePictForm = document.getElementById('picteditor');
	if (thePictForm) {
		theFontHolder = $('fontholder');
		theFontList = $('fontlist');
		theFontLi = theFontHolder.getElements('li')[0];
		FontItems = theFontList.getElements('a');
		FontItems.each(function(FontItem, i) {
			FontItem.addEvent("click", function(evt) {
				new Event(evt).stop();
				theFontLi.innerHTML = this.parentNode.innerHTML;
				theFontLi.style.backgroundImage = 'url("/media/bg_pictholder_hi.gif")';
				$('font_id').value = theFontLi.getElementsByTagName('a')[0].getAttribute('value');
			});
		});
	}
}

function removeFont(del) { 
	del.parentNode.style.backgroundImage = 'url("/media/bg_pictholder.gif")';
	$('font_id').value = '';
	del.parentNode.innerHTML = ' ';
	return false;
}


function initCopy() {
	theTable = document.getElementById('expressionList')
	theImgs = theTable.getElementsByTagName('img');
	allDivs = theTable.getElementsByTagName('div');
	for (i=0;i<theImgs.length;i++) {
		if (theImgs[i].src.indexOf('icon_copy.gif')!=-1) {
			theImgs[i].parentNode.onclick = function() {
				for (k=0;k<allDivs.length;k++) {
					if (allDivs[k].className=='copy' && allDivs[k] != this.parentNode.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('div')[0]) {
						allDivs[k].style.display = 'none';
					}
				}
				theDivs = this.parentNode.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('div');
				for (j=0;j<theDivs.length;j++) {
					if (theDivs[j].className=='copy') {
						theDivs[j].style.display = theDivs[j].style.display!='block' ? 'block' : 'none';
					}
				}
				return false;
			}
		}
	}
}

function initClicks(fieldID,listID) {
	if ($defined('fieldID') && $defined('listID')) {
		var textBox = FCKeditorAPI.GetInstance(fieldID);
		if (textBox && $(listID)!=null) {
			listLinks = $(listID).getElementsByTagName('a');
			//listLinks = $$('#'+listID+' A');
			for (i=0;i<listLinks.length;i++) {
				listLinks[i].onclick = function() {
					//alert(this.innerHTML);
					textBox.SetHTML(this.innerHTML);
					return false;
				}
			}
		}
	}
}

function insert(myField, myValue, theWidth, theHeight, theAlt) {
	var textBox = FCKeditorAPI.GetInstance(myField);
	theImg = ' <img src="' + myValue + '" width="' + theWidth + '" height="' + theHeight + '" alt="' + theAlt + '"  unselectable="on"/>';
	textBox.InsertHtml(theImg);
	return false;
}

function positionBox(box) {
	bWidth = box.offsetWidth;
	bHeight = box.offsetHeight;
	box.style.left = ((getWidth() / 2) - (bWidth / 2)) + 'px';
	box.style.top = ((getHeight() / 2) - (bHeight / 2)) + getScrollTop() + 'px';
}

function initLoad() {
	//document.getElementById('load').style.display = 'block';
	$('load').style.height = getScrollHeight() + 'px';
	positionBox($('center'));
}


function setDisplay(item) {
	h = item.getStyle('height').toInt();
	if (h==0) {
		item.setStyle('display','none');
	} else {
		//item.setStyle('display','block');
		item.setStyle('height','auto');
	}
}


function initPapers() {
	paperList = $('papers');
	if ($defined(paperList)) { 
		paperLinks 		= paperList.getElements('a');
		//paperToggleLinks = paperList.getElements('a.toggle');
		paperChosen		= $('chosenPaper');
		paperInput		= $('dagblad');
		columnSelect	= $('columns');
		for (i=0;i<paperLinks.length;i++) {
			if (paperLinks[i].className == 'toggle') {
				// tooggle item
				
				// alert('0.1'+paperLinks[i].getAttribute('toggleId'));
				paperLinks[i].mySlide = new Fx.Slide(paperLinks[i].getAttribute('toggleId'),{
					'onComplete': function() {
						if (this.open) {
							this.wrapper.setStyle('height','auto');
						} else {
							this.wrapper.setStyle('height','0');
						}
					}
				});
				// toggle current menu's according to the image
				if (paperLinks[i].getStyle('backgroundImage').indexOf('arrow_right.gif)')!= -1 || $(paperLinks[i].getAttribute('toggleId')).getAttribute('showthis')== 'no' || paperLinks[i].getStyle('backgroundImage').indexOf('arrowsmlI.gif)')!= -1) {
					paperLinks[i].mySlide.hide();
				}
				
				paperLinks[i].addEvent('click', function(e) {
					e = new Event(e);
					for (k=0;k<paperLinks.length;k++) {
						if (paperLinks[k].className == 'toggle') {
							if (paperLinks[k]!=this) {
								if (this.parentNode.parentNode != paperList) {
									subPaperLinks = this.parentNode.parentNode.getElements('a');
									for (j=0;j<subPaperLinks.length;j++) {
										if (subPaperLinks[j].className == 'toggle') {
											if (subPaperLinks[j]!=this) {
												subPaperLinks[j].mySlide.slideOut();
												subPaperLinks[j].setStyle('backgroundImage','url(media/arrowsmlI.gif)');
											}
										}
									}
								} else {
									if (paperLinks[k].getStyle('backgroundImage').indexOf('arrow_down.gif)') != -1) {
										paperLinks[k].mySlide.slideOut();
										paperLinks[k].setStyle('backgroundImage','url(media/arrow_right.gif)');
									} else if (paperLinks[k].getStyle('backgroundImage').indexOf('arrowsmlA.gif)') != -1) {
										paperLinks[k].mySlide.slideOut();
										paperLinks[k].setStyle('backgroundImage','url(media/arrowsmlI.gif)');
									}
								}
							}
						}
					}
					this.mySlide.toggle();
					if (this.getStyle('backgroundImage').indexOf('arrow_right.gif)') != -1) {
						this.setStyle('backgroundImage','url(media/arrow_down.gif)');
					} else if (this.getStyle('backgroundImage').indexOf('arrow_down.gif)') != -1) {
						this.setStyle('backgroundImage','url(media/arrow_right.gif)');
					} else if (this.getStyle('backgroundImage').indexOf('arrowsmlI.gif)') != -1) {
						this.setStyle('backgroundImage','url(media/arrowsmlA.gif)');
					} else if (this.getStyle('backgroundImage').indexOf('arrowsmlA.gif)') != -1) {
						this.setStyle('backgroundImage','url(media/arrowsmlI.gif)');
					}
					e.stop();
					//return false;
				});
			} else if (paperLinks[i].className == 'notoggle') {
				// alert('notoggle');
				paperLinks[i].onclick = function() { return false; }
			} else {
				paperLinks[i].onclick = function() {
					for (i=0;i<paperLinks.length;i++) {
						if (paperLinks[i].className != 'toggle') {
							paperLinks[i].className = '';
						}
					}
					this.className = 'hi';
					paperChosen.innerHTML = this.innerHTML;
					paperInput.value = this.id;
					// hier met Ajax gegevens voor datum en kolommen ophalen...
					fillSelectKolommen(this.id,$('id').value);
					fillSelectPlaatsingsdata(this.id,$('papereditor').id.value);
					return false;
				}
			}
		}
	}
	return false;
}


function showKranten(who) {
	var layout = ($('layout_id'))? $('layout_id').value : ''; 
	
	if (who=='hah') {
		$('krant').style.display		= 'none';
		$('huisaanhuis').style.display	= 'block';
		$('publishdate').style.display	= 'none';
		$('menu_landelijk').className	= 'normal';
		$('menu_hah').className			= 'hi';
		fillSelectKolommen('',layout,true);
	} else {
		$('krant').style.display		= 'block';
		$('huisaanhuis').style.display	= 'none';
		$('publishdate').style.display	= 'block';
		$('menu_landelijk').className	= 'hi';
		$('menu_hah').className			= 'normal';
		fillSelectKolommen($('dagblad').value,layout,false);
	}
}

var SlideItMoo = new Class({
					   
	initialize: function(options){
		this.options = $extend({
			itemsVisible:5,
			showControls:1,
			autoSlide: 0,
			transition: Fx.Transitions.linear,
			currentElement: 0,
			thumbsContainer: 'thumbs',
			elementScrolled: 'thumb_container',
			overallContainer: 'gallery_container'
		},options || {});	
		
		this.images = $(this.options.thumbsContainer).getElements('a');
		// assumes that all thumbnails have the same width
		this.image_size = this.images[0].getSize();
		
		// resizes the container div's according to the number of itemsVisible thumbnails
		this.setContainersSize();
		
		this.myFx = new Fx.Scroll(this.options.elementScrolled,{ transition: this.options.transition });		
		// adds the forward-backward buttons
		if( this.images.length > this.options.itemsVisible ){
			this.fwd = this.addControlers('addfwd');
			this.bkwd = this.addControlers('addbkwd');
			this.forward();
			this.backward();
			/* if autoSlide is not set, scoll on mouse wheel */
			if( !this.options.autoSlide ){
				$(this.options.thumbsContainer).addEvent('mousewheel', function(ev){
					new Event(ev).stop();
					ev.wheel < 0 ? this.fwd.fireEvent('click') : this.bkwd.fireEvent('click');			
				}.bind(this));
			}
			else{
				this.startIt = function(){ this.fwd.fireEvent('click') }.bind(this);
				this.autoSlide = this.startIt.periodical(this.options.autoSlide, this);
				this.images.addEvents({
					'mouseover':function(){
						$clear(this.autoSlide);						
					}.bind(this),
					'mouseout':function(){
						this.autoSlide = this.startIt.periodical(this.options.autoSlide, this);
					}.bind(this)
				})
			}
		};
		
		// if there's a specific default thumbnail to start with, slide to it
		if( this.options.currentElement!==0 ){
			this.options.currentElement-=1;
			this.slide(1);
		}
	},
	
	setContainersSize: function(){
		$(this.options.overallContainer).set({
			styles:{
				'width': this.options.itemsVisible * this.image_size.x + 50*this.options.showControls + (this.options.itemsVisible-1)*3
			}
		});
		$(this.options.elementScrolled).set({
			styles:{
				'width': this.options.itemsVisible * this.image_size.x + (this.options.itemsVisible-1)*3
			}
		});
	},
	
	forward: function(){				
		this.fwd.addEvent('click',function(){
			this.slide(1);
		}.bind(this));		
	},
	
	backward: function(){			
		this.bkwd.addEvent('click',function(){											
			this.slide(-1);			
		}.bind(this))	
	},
	
	addControlers: function(cssClass){
		element = new Element('div',{
			'class': cssClass,
			styles:{
				'display': this.options.showControls ? '' : 'none'
			}
		}).injectInside($(this.options.overallContainer));
		return element;
	},
	
	slide: function(step){
		/* if autoslice is on, when end is reached, go back to begining */
		if(this.options.autoSlide && this.options.currentElement >= this.images.length-this.options.itemsVisible ){
			this.options.currentElement = -1;
		}
		
		if ( ( this.options.currentElement < this.images.length-this.options.itemsVisible && step>0 ) || ( step < 0 && this.options.currentElement !== 0 ) ){
			this.myFx.cancel();
			this.options.currentElement += step;		
			this.myFx.toElement( this.images[this.options.currentElement] );
		}
	}
})

function initShow() {
	// get the slideshow
	theShowHolder = $('slideshow');			
	if (theShowHolder) {
		// get the picture container
		thePictHolder = $('pict_con');
		// assign effects to pictholder
		fx = thePictHolder.effects({duration: 1000, transition: Fx.Transitions.Quart.easeOut});
		// get the pictures
		thePicts = thePictHolder.getElementsByTagName('IMG');
		// get the loaderbox
		theLoader = $('loader');
		//get the thumbholder
		theThumbHolder = $('thumbs');
		if (theThumbHolder) {
			activePict = $('active');
			
			
			// get the thumblinks
			theThumbs = theThumbHolder.getElementsByTagName('A');
			if (theThumbs.length!=0) {
				//get the thumbnail images
				theThumbPicts = theThumbHolder.getElementsByTagName('IMG');
				if ($defined(activePict)) {
					if (activePict.src.indexOf('media/geen_image.gif')==-1) {
						$('message').style.display = 'none';
						// resize the picture container to fit the width of the active picture onload
						if (activePict.height != thePictHolder.height || activePict.width != thePictHolder.width) {
							thePictHolder.style.height = activePict.height + 'px';
							thePictHolder.style.width = activePict.width + 'px';
						}
					} else {
						$('message').style.display = 'inline';
						$('message').innerHTML = 'Kies een voorbeeld<br /><br />';
					}
				}
				// assign functions to thumbs
				for (i=0;i<theThumbs.length;i++) {
				
					if (theThumbPicts[i].getAttribute('pid') == $('voorbeeld_id').value) {
						activePict.src			= theThumbPicts[i].getAttribute('psrc');
						activePict.width		= theThumbPicts[i].getAttribute('pwidth');
						activePict.height		= theThumbPicts[i].getAttribute('pheight');
						thePictHolder.style.width = theThumbPicts[i].getAttribute('pwidth') + 'px';
						thePictHolder.style.height = theThumbPicts[i].getAttribute('pheight') + 'px';
						theThumbs[i].id='activeThumb';
						$('message').style.display = 'none';
					}
												
					// assign pictures to thumbs
					theThumbs[i].pictObj = theThumbPicts[i];
					
					theThumbs[i].onclick = function(e) {
						if (activePict.src.indexOf('media/geen_image.gif')!=-1) {
							$('message').style.display = 'none';
						}
						activePict.src			= this.pictObj.getAttribute('psrc');
						if (activePict.height != parseInt(this.pictObj.getAttribute('pheight')) || activePict.width != parseInt(this.pictObj.getAttribute('pwidth'))) {
							clearActive(this);
							
							$('voorbeeld_id').value = this.pictObj.getAttribute('pid');
							
							activePict.style.display = 'none';
							//activePict.src			= this.pictObj.getAttribute('psrc');
							activePict.width		= this.pictObj.getAttribute('pwidth');
							activePict.height		= this.pictObj.getAttribute('pheight');
							//$('active').alt=this.pictObj.getAttribute('palt');
							theLoader.style.display = 'block';
							fx.pict = this.pictObj;
							fx.start({
								'height': this.pictObj.getAttribute('pheight'),
								'width': this.pictObj.getAttribute('pwidth')
							}).chain(function() {
								setActive();									
							});
						} else {
							clearActive(this);
							setActive();
						}
						e = new Event(e).stop();
						return false;
					};
				}
				
			}
		}
	}
}

function setActive() {
	theLoader.style.display = 'none';
	$('active').style.display = 'block';
}

function clearActive(thmb) {
	for (i=0;i<theThumbs.length;i++) {
		theThumbs[i].id='';
	}
	thmb.id='activeThumb';
}

function controlForm() {
	theStyleForm = $$('#designeditor fieldset')[0];
	theStyleLinks = theStyleForm.getElements('A');
	theStyleInputs = theStyleForm.getElements('INPUT');
	for (i=0;i<theStyleLinks.length;i++) {
		theStyleLinks[i].correspondingInput = theStyleInputs[i];
		theStyleLinks[i].onclick = function() {
			if (!this.correspondingInput.checked) {
				this.correspondingInput.checked = true;
				for (j=0;j<theStyleLinks.length;j++) {
					theStyleLinks[j].className = '';
				}
				this.className = 'active';						
				$('thumbs').className = 'busy';
				$('thumbs').innerHTML = '<img src="media/loadbar.gif" width="130" height="6" />';
				var url = '/Ajax/requestThumbs.php?id='+this.getAttribute('value')+'&className=UitingAdvertentie&objId='+$('id').value+"&"+new Date();
				//alert(url);
				new Ajax(url, {
					method: 'get',
					update: $('thumbs'),
					onComplete : function() {
						$('thumbs').className = '';
						initShow();
					}
				}).request();
			}
			return false;
		}
	}
	
	for (i=0;i<theStyleInputs.length;i++) {
		theStyleInputs[i].correspondingLink = theStyleLinks[i];
		if (theStyleInputs[i].checked) {
			for (j=0;j<theStyleLinks.length;j++) {
				theStyleLinks[j].className = '';
			}
			theStyleLinks[i].className = 'active';
			var url = '/Ajax/requestThumbs.php?id='+theStyleInputs[i].value+'&className=UitingAdvertentie&objId='+$('id').value+"&"+new Date();
			$('thumbs').className = 'busy';
			$('thumbs').innerHTML = '<img src="media/loadbar.gif" width="130" height="6" />';
			new Ajax(url, {
				method: 'get',
				update: $('thumbs'),
				onComplete : function() {
					$('thumbs').className = '';
					initShow();
				}
			}).request();
		}
		theStyleInputs[i].onclick = function() {					
			for (j=0;j<theStyleLinks.length;j++) {
				theStyleLinks[j].className = '';
			}
			this.correspondingLink.className = 'active';
			$('thumbs').className = 'busy';
			$('thumbs').innerHTML = '<img src="media/loadbar.gif" width="130" height="6" />';
			var url = '/Ajax/requestThumbs.php?id='+this.value+'&className=UitingAdvertentie&objId='+$('id').value+"&"+new Date();
			alert(url);
			new Ajax(url, {
				method: 'get',
				update: $('thumbs'),
				onComplete : function() {
					$('thumbs').className = '';
					initShow();
				}
			}).request();
		}		
	}
}

function placeValue() {
	theNext = $('exampleLink');
	theForm = $('hiddenForm');
	theInput = $('example');
	
	theNext.addEvent('click', function(ex) {
		ex = new Event(ex).stop();
		theForm.submit();
		return false;
	});
}

function fillSelectKolommen(dagblad,uiting)
{
	new Ajax('/Ajax/fillSelectKolommen.php', {
		method: 'get',
		data: 'id='+dagblad+'&uiting='+uiting+'&t'+new Date(),
		update: $('kolomHolder'),
		onFailure: failFillSelectKolommen
	}).request();
}

function testSuc(resp)
{
	alert(resp.responseText);
}

function failFillSelectKolommen()
{
	alert("De kolomaantallen kunnen niet worden opgehaald.");
}

function searchPapers() {
	if (document.getElementById('searchPaper').value=='Zoek blad') 
	{
		document.getElementById('searchPaper').value = '';
	}
 	if (true) {
 		new Ajax('/Ajax/searchPapers.php', {
 			method: 'get',
 			data: 'search='+document.getElementById('searchPaper').value,
 			onSuccess: successPapers,
 			onFailure: failPapers
 		}).request();
		if (document.getElementById('searchPaper').value=='') 
		{
			document.getElementById('searchPaper').value = 'Zoek blad';
		}
 	} else {
 		return false;
 	}
 	return false;
}

function fillSelectPlaatsingsdata(dagblad,advertentie_id)
{
	new Ajax('/Ajax/fillSelectPlaatsingsdata.php', {
		method: 'get',
		data: 'id='+dagblad+'&adId='+advertentie_id+'&t='+new Date(),
		update: $('plaatsingsdata'),
		onFailure: failFillSelectPlaatsingsdata
	}).request();
}

function failFillSelectPlaatsingsdata()
{
	alert("De plaatsingsdata kunnen niet worden opgehaald.");
}

function initScroll() {
	if($('keeper')) {
		keeperTop = $('keeper').getPosition().y;
		//keeperBottom = $('keeper').getPosition().y + $('keeper').getSize().y;
		fxk = $('keeper').effects({duration: 500, transition: Fx.Transitions.Quart.easeOut});
		doScroll();
	}
}

function doScroll() {			
	if (keeperTop - 40 < this.document.getScroll().y) {
		fxk.start({
			top: this.document.getScroll().y - keeperTop + 40
		});
	} else {
		if ($('keeper').style.top != '0px') {
			fxk.start({
				top: 0
			});
		} else {
			$('keeper').style.top = '0px';
		}
	}
	setTimeout('doScroll()', 100 );
}

/*
function positionBox(box) {
	bWidth = box.getStyle('width').toInt();
	bHeight = box.getStyle('height').toInt();
	box.style.left = ((getWidth() / 2) - (bWidth / 2)) + 'px';
	box.style.top = ((getHeight() / 2) - (bHeight / 2)) + getScrollTop() + 'px';
}
*/

function keepbox() {
	fx.start({
		'top': ((getHeight() / 2) - (bHeight / 2)) + getScrollTop(),
		'left': ((getWidth() / 2) - (bWidth / 2))
	})
	theKeeper=setTimeout('keepbox()', 100 );
}

function openMask(boxID) {
	var corrIE = 0;			
	var theMask = $('mask');
	var theBox = $(boxID);
	theMask.style.display = 'block';
	theMask.style.height = getScrollHeight() + 'px';
	theBox.style.visibility = 'hidden';
	theBox.style.display = 'block';			

	fx = new Fx.Styles(theBox, {
		duration: 500,
		wait: false,
		transition: Fx.Transitions.Quad.easeOut
	});

	var bHeight = theBox.getStyle('height').toInt();
	positionBox(theBox);
	theBox.style.overflow = 'hidden';
	theBox.style.width = '0px';
	theBox.style.height = '0px';
	theBox.style.visibility = 'visible';
	if (boxID=='reactbox') checkReactForm();
	//alert(fx.bHeight);
	fx.start({
		'height': bHeight,
		'width': bWidth
	}).chain(function() {
		keepbox();
	});
	return false;
}

function closeMask(id) {
	clearTimeout(theKeeper);
	fx.start({
		'height': 0,
		'width': 0
	}).chain(function() {
		$(id).style.display = 'none'
		$('mask').style.display = 'none'
		this.start({
			'height': bHeight,
			'width': bWidth
		});
	});
}

function openCloseMask(id1,id2) {
	clearTimeout(theKeeper);
	fx.start({
		'height': 0,
		'width': 0
	}).chain(function() {
		$(id1).style.display = 'none'
		$('mask').style.display = 'none'
		this.start({
			'height': bHeight,
			'width': bWidth
		});
	}).chain(function() {
		openMask(id2);
	});
}

function setPlaatsingsDatum(val) {
	var time = val*1000; // seconds > milliseconds
	var mydate = new Date();
	mydate.setTime(time);
	document.forms['papereditor'].day_plaatsingsdatum.value=mydate.getDate();
	document.forms['papereditor'].month_plaatsingsdatum.value=mydate.getMonth()+1;
	var year = mydate.getYear();
	if (year < 2000) year += 1900;
	document.forms['papereditor'].year_plaatsingsdatum.value=year;
}

function openPlaatsingsDatum() {
	return false;
}


function getTeksten(type_id, categorie_id, type_naam, trefwoord) {
	new Ajax('/Ajax/getTeksten.php', {
		method: 'get',
		data: 'id='+categorie_id+'&trefwoord='+trefwoord+'&type_id='+type_id+'&t'+new Date(),
		update: $(type_naam),
		onSuccess: function() {
			if (type_naam=='gedichten') {
				initClicks('gedicht','poetryList');
			} else if (type_naam=='aanheffen') {
				initClicks('aanhef','inaugurationList');
			} else if (type_naam=='slotzinnen') {
				initClicks('infoSlotzin','slotList');
			}
		},
		onFailure: failGetTeksten
	}).request();
}

function failGetTeksten() {
	alert("De teksten kunnen niet worden opgehaald.");
}	
