/* 

	made by 4rn0 -- content managed websites (c) 2005 - www.4rn0.nl 
	jslashj.nl -- main JavaScript file -- last revision: 08102005
	
	custom scrollbar was created with coding by 13th Parallel;
	described here: http://13thparallel.org/archive/dhtml-scrollbars
   
*/


window.onload = function() {

	if (typeof(document.getElementById) == 'undefined') {
		document.getElementById = function(id) {
			return document.all[id];
		};
	}

	var bugRiddenCrashPronePieceOfJunk = (
		navigator.userAgent.indexOf('MSIE 5.2') != -1
		&&
		navigator.userAgent.indexOf('Mac') != -1
	);
	
	if (!bugRiddenCrashPronePieceOfJunk) {
		
		resizeWindow();
		
		if (document.getElementById('home').className != 'breadcrumb') {
			scroller.init();
			var scrollbarAreaH = document.getElementById('scrollArea').offsetHeight;
			window.setTimeout('scrollAreaHeight(' + scrollbarAreaH + ')', 360);
		}
		
	}
	
	var anchors = document.getElementsByTagName('A');
	for (var i = 0; i < anchors.length; i++) {
		if (anchors[i].getAttribute('rel') == 'external') {
			anchors[i].setAttribute('target', '_blank');
		}
	}
	
	var src = $('#content img').attr('src');
	var tmp;
	
	$('.clientList a').hover(
		function() {
			if ($(this).next('img').size()) {
				window.clearTimeout(tmp);
				$('#content img').attr('src', $(this).next('img').attr('src'));
			}
		},
		function() {
			tmp = window.setTimeout(function() {
				$('#content img').attr('src', src);	
			}, 100);
		}
	);
	
	var colophon = document.getElementById('copyright');
	var credits = document.getElementById('credits');

	if (colophon) {
		credits.style.display = 'none';
		colophon.onclick = function() {
			var credits = document.getElementById('credits');
			credits.style.display = (credits.style.display == 'none') ? '' : 'none';
			this.blur();
			return false;
		};
	}
	
	// # if (document.getElementById('navigation')) {
	// # 
	// # 	var groterLi = document.createElement('LI');
	// # 	var groterImg = document.createElement('IMG');
	// # 	groterImg.setAttribute('src', 'layout/groter.gif');
	// # 	groterImg.setAttribute('id', 'groter');
	// # 	groterImg.onclick = function() {
	// # 		if (parseInt(document.getElementById('canvas').style.fontSize)) {
	// # 			document.getElementById('canvas').style.fontSize = parseInt(document.getElementById('canvas').style.fontSize) + 1 + 'px';
	// # 		}
	// # 		else {
	// # 			document.getElementById('canvas').style.fontSize = '12px';
	// # 		}
	// # 	};
	// # 	groterLi.appendChild(groterImg);
	// # 
	// # 	var kleinerLi = document.createElement('LI');
	// # 	var kleinerImg = document.createElement('IMG');
	// # 	kleinerImg.setAttribute('src', 'layout/kleiner.gif');
	// # 	kleinerImg.setAttribute('id', 'kleiner');
	// # 	kleinerImg.onclick = function() {
	// # 		if (parseInt(document.getElementById('canvas').style.fontSize)) {
	// # 			document.getElementById('canvas').style.fontSize = parseInt(document.getElementById('canvas').style.fontSize) - 1 + 'px';
	// # 		}
	// # 		else {
	// # 			document.getElementById('canvas').style.fontSize = '10px';
	// # 		}
	// # 	};
	// # 	kleinerLi.appendChild(kleinerImg);
	// # 
	// # 	var navigation = document.getElementsByTagName('UL')[0];
	// # 	navigation.appendChild(groterLi);
	// # 	navigation.appendChild(kleinerLi);
	// # 	
	// # }
	
	if (document.getElementById('clientManager')) {
		if (document.getElementById('delete')) {
			document.getElementById('delete').onclick = function() {
				if (confirm('Weet U zeker dat U deze klant wilt verwijderen?')) {
					document.getElementById('clientManager').action = 'beheer/?action=removeClient&id=' + document.getElementById('id').value;
					document.getElementById('clientManager').submit();
				}
			};
		}
	}
	
	if (document.getElementById('fileManager')) {

		document.getElementById('fileManager').onsubmit = function() {
			if (document.getElementById('alt').value == '') {
				alert('U heeft geen beschrijving ingevoerd!');
				return false;
			}
			
			if (!new RegExp(/^[a-zA-Z0-9 ]+$/).test(document.getElementById('alt').value)) {
				alert('De beschrijvende tekst is ongeldig: alleen letters (a-z), cijfers (0-9) en spaties zijn toegestaan!');
				return false;
			}

			if (document.getElementById('source').value == '') {
				alert('U heeft geen bestand geselecteerd!');
				return false;
			}
		
			else {
				var image_array = document.getElementById('source').value.split('.');
				if (image_array[image_array.length-1].toLowerCase() != 'gif' && image_array[image_array.length-1].toLowerCase() != 'jpg') {
					alert('Afbeeldingen zijn alleen toegestaan in het \'gif\' of \'jpg\' formaat!' + "\n" + 'De afbeelding die U probeert te uploaden is van het \'' + image_array[image_array.length-1] + '\' type!');
					return false;
				}
			}
		};
		
		document.getElementById('delete').onclick = function() {
			var count = 0;
			
			for (i = 0; i < document.getElementById('fileManager').length; i++) {
				if (document.getElementById('fileManager').elements[i].type.toLowerCase() == "checkbox" && document.getElementById('fileManager').elements[i].checked == true) {
					count++;
				}
			}
		
			if (count == 0) {
				alert('U heeft geen bestanden geselecteerd!');
			}
			
			else {
				var files = (count > 1) ? 'deze ' + count + ' bestanden' : 'dit bestand';
				if (confirm('Weet U zeker dat U ' + files + ' wilt verwijderen?')) {
					document.getElementById('fileManager').action = 'beheer/?action=removeImages';
					document.getElementById('fileManager').submit();
				}
			}
		};
		
	}
	
};

window.onresize = function() {

	var bugRiddenCrashPronePieceOfJunk = (
		navigator.userAgent.indexOf('MSIE 5.2') != -1
		&&
		navigator.userAgent.indexOf('Mac') != -1
	);
	
	if (!bugRiddenCrashPronePieceOfJunk) {

		resizeWindow();

		if (document.getElementById('home').className != 'breadcrumb') {
			scroller.init();
		}
		
	}

};

function scrollAreaHeight(scrollbarAreaH) {
	if (scrollbarAreaH != document.getElementById('scrollArea').offsetHeight) {
		scrollbarAreaH = document.getElementById('scrollArea').offsetHeight;
		scroller.init();
	}
	window.setTimeout('scrollAreaHeight(' + scrollbarAreaH + ')', 360);
}

function resizeWindow() {

	if (document.getElementsByTagName('BODY')[0].className != 'beheer') {
		document.getElementById('canvas').style.margin = '-20.0em 0 0 -34.0em';
		document.getElementById('canvas').style.top = '50%';
		document.getElementById('canvas').style.left = '50%';
		document.getElementById('canvas').style.position = 'absolute';
	}
	
	else {
		if (document.getElementById('content').clientHeight != document.getElementById('canvas').clientHeight) {
			document.getElementById('sidebar').style.height = document.getElementById('content').clientHeight + 'px';
		}
	}
	
}

var Drag={obj:null,init:function(o,oRoot,minX,maxX,minY,maxY,bSwapHorzRef,bSwapVertRef,fXMapper,fYMapper){o.onmousedown=Drag.start;o.hmode=bSwapHorzRef?false:true;o.vmode=bSwapVertRef?false:true;o.root=oRoot&&oRoot!=null?oRoot:o;if(o.hmode&&isNaN(parseInt(o.root.style.left))){o.root.style.left="0px";}if(o.vmode&&isNaN(parseInt(o.root.style.top))){o.root.style.top="0px";}if(!o.hmode&&isNaN(parseInt(o.root.style.right))){o.root.style.right="0px";}if(!o.vmode&&isNaN(parseInt(o.root.style.bottom))){o.root.style.bottom="0px";}o.minX=typeof minX!='undefined'?minX:null;o.minY=typeof minY!='undefined'?minY:null;o.maxX=typeof maxX!='undefined'?maxX:null;o.maxY=typeof maxY!='undefined'?maxY:null;o.xMapper=fXMapper?fXMapper:null;o.yMapper=fYMapper?fYMapper:null;o.root.onDragStart=new Function();o.root.onDragEnd=new Function();o.root.onDrag=new Function();},start:function(e){var o=Drag.obj=this;e=Drag.fixE(e);var y=parseInt(o.vmode?o.root.style.top:o.root.style.bottom);var x=parseInt(o.hmode?o.root.style.left:o.root.style.right);o.root.onDragStart(x,y);o.lastMouseX=e.clientX;o.lastMouseY=e.clientY;if(o.hmode){if(o.minX!=null){o.minMouseX=e.clientX-x+o.minX;}if(o.maxX!=null){o.maxMouseX=o.minMouseX+o.maxX-o.minX;}}else{if(o.minX!=null){o.maxMouseX=-o.minX+e.clientX+x;}if(o.maxX!=null){o.minMouseX=-o.maxX+e.clientX+x;}}if(o.vmode){if(o.minY!=null){o.minMouseY=e.clientY-y+o.minY;}if(o.maxY!=null){o.maxMouseY=o.minMouseY+o.maxY-o.minY;}}else{if(o.minY!=null){o.maxMouseY=-o.minY+e.clientY+y;}if(o.maxY!=null){o.minMouseY=-o.maxY+e.clientY+y;}}document.onmousemove=Drag.drag;document.onmouseup=Drag.end;return false;},drag:function(e){e=Drag.fixE(e);var o=Drag.obj;var ey=e.clientY;var ex=e.clientX;var y=parseInt(o.vmode?o.root.style.top:o.root.style.bottom);var x=parseInt(o.hmode?o.root.style.left:o.root.style.right);var nx,ny;if(o.minX!=null){ex=o.hmode?Math.max(ex,o.minMouseX):Math.min(ex,o.maxMouseX);}if(o.maxX!=null){ex=o.hmode?Math.min(ex,o.maxMouseX):Math.max(ex,o.minMouseX);}if(o.minY!=null){ey=o.vmode?Math.max(ey,o.minMouseY):Math.min(ey,o.maxMouseY);}if(o.maxY!=null){ey=o.vmode?Math.min(ey,o.maxMouseY):Math.max(ey,o.minMouseY);}nx=x+((ex-o.lastMouseX)*(o.hmode?1:-1));ny=y+((ey-o.lastMouseY)*(o.vmode?1:-1));if(o.xMapper){nx=o.xMapper(y);}else if(o.yMapper){ny=o.yMapper(x);}Drag.obj.root.style[o.hmode?"left":"right"]=nx+"px";Drag.obj.root.style[o.vmode?"top":"bottom"]=ny+"px";Drag.obj.lastMouseX=ex;Drag.obj.lastMouseY=ey;Drag.obj.root.onDrag(nx,ny);return false;},end:function(){document.onmousemove=null;document.onmouseup=null;Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style[Drag.obj.hmode?"left":"right"]),parseInt(Drag.obj.root.style[Drag.obj.vmode?"top":"bottom"]));Drag.obj=null;},fixE:function(e){if(typeof e=='undefined'){e=window.event;}if(typeof e.layerX=='undefined'){e.layerX=e.offsetX;}if(typeof e.layerY=='undefined'){e.layerY=e.offsetY;}return e;}};var scroller={init:function(){scroller.docH=document.getElementById('contentArea').offsetHeight+(document.all?0:20);scroller.contH=document.getElementById('viewPort').offsetHeight;scroller.scrollAreaH=document.getElementById('scrollArea').offsetHeight;scroller.scrollH=(scroller.contH*scroller.scrollAreaH)/scroller.docH;if(scroller.scrollH<15){scroller.scrollH=15;}if(scroller.scrollH>scroller.contH){scroller.scrollH=0;document.getElementById('scroller').style.display='none';document.getElementById('contentArea').style.width='100%';}else{document.getElementById('scroller').style.height=Math.round(scroller.scrollH)+"px";document.getElementById('scroller').style.display='block';document.getElementById('contentArea').style.width='90%';}scroller.scrollDist=Math.round(scroller.scrollAreaH-scroller.scrollH);Drag.init(document.getElementById("scroller"),null,0,0,-1,scroller.scrollDist);document.getElementById("scroller").onDrag=function(x,y){var scrollY=parseInt(document.getElementById("scroller").style.top);var docY=0-(scrollY*(scroller.docH-scroller.contH)/scroller.scrollDist);document.getElementById("contentArea").style.top=docY+"px";};}}
