if (!this.Stats) {
	// Stats namespace
	Stats = (function () {
		
		// is de eigenschap (of variabele) gedefinieerd (functie van Pi Wik)
		function isDefined(property) {
			return typeof property !== 'undefined';
		}
		
		/**
		  *  Visit klasse
		  */
		function Visit(id) {
			
			// Plugin, Parameter name, MIME type (map van Pi Wik)
			var pluginMap = {
				// document types
				pdf:         ['pdf',   'application/pdf',               '0'],
				// media players
				quicktime:   ['qt',    'video/quicktime',               '0'],
				realplayer:  ['realp', 'audio/x-pn-realaudio-plugin',   '0'],
				wma:         ['wma',   'application/x-mplayer2',        '0'],
				// interactive multimedia 
				director:    ['dir',   'application/x-director',        '0'],
				flash:       ['fla',   'application/x-shockwave-flash', '0'],
				// RIA
				java:        ['java',  'application/x-java-vm',         '0'],
				gears:       ['gears', 'application/x-googlegears',     '0'],
				silverlight: ['ag',    'application/x-silverlight',     '0']
			};
			
			var id = id;
			
			escapeWrapper = window.encodeURIComponent || escape;

			// Geef additionele bezoekerinformatie door aan de statistieken module voor opslag
			function updateVisitorInfo () {
				
				// haal de bezoekers info op mbv javascript
				detectBrowserPlugins();
				
				// haal de tijd en datum op van de lokale pc
				var now = new Date();
				
				// haal de pagina referrer op
				var pageReferrer = getReferrer()
				
				// bouw de request URL
				var requestURL = 'stats.php?statsact=u' +
								'&id=' + id +
								'&tp=0' +
								'&cD=' + screen.colorDepth +
								'&rW=' + screen.width +
								'&rH=' + screen.height +
								'&h=' + now.getHours() + '&mi=' + now.getMinutes() + '&s=' + now.getSeconds() +
								'&y=' + now.getFullYear() + '&mo=' + (now.getMonth() + 1) + '&d=' + now.getDate() +
								'&urlref=' + escapeWrapper(pageReferrer) +
								'&ck=' + hasCookies() +
								'&rand=' + Math.random();
				
				// plugin data toevoegen
				for (i in pluginMap) {
					requestURL += '&' + pluginMap[i][0] + '=' + pluginMap[i][2];
				}
				
				// stuur de bezoekers info door
				getImage(requestURL);
				
			}
			
			// Stuur een image request naar de meegegeven url
			function getImage(url) {
				var image = new Image(1, 1);
				image.onLoad = function () { };
				image.src = url;
			}
			
			// Heeft de browser ondersteuning voor cookies (functie van Pi Wik)
			function hasCookies() {
				var testCookieName = '__testcookie';
				if (!isDefined(navigator.cookieEnabled)) {
					setCookie(testCookieName, '1');
					return getCookie(testCookieName) == '1' ? '1' : '0';
				}
				return navigator.cookieEnabled ? '1' : '0';
			}
			
			// Zet cookie waarde (functie van Pi Wik)
			function setCookie(cookieName, value, daysToExpire, path, domain, secure) {
				var expiryDate;

				if (daysToExpire) {
					// time is in milliseconds
					expiryDate = new Date();
					// there are 1000 * 60 * 60 * 24 milliseconds in a day (i.e., 86400000 or 8.64e7)
					expiryDate.setTime(expiryDate.getTime() + daysToExpire * 8.64e7);
				}

				document.cookie = cookieName + '=' + escapeWrapper(value) +
								  (daysToExpire ? ';expires=' + expiryDate.toGMTString() : '') +
								  ';path=' + (path ? path : '/') +
								  (domain ? ';domain=' + domain : '') +
								  (secure ? ';secure' : '');
			}
			
			// Haal de cookie waarde op (functie van Pi Wik)
			function getCookie(cookieName, path, domain) {
				var cookiePattern = new RegExp('(^|;)[ ]*' + cookieName + '=([^;]*)' +
						(path ? '(;[ ]*expires=[^;]*)?;[ ]*path=' + path.replace('/', '\\/') + '' : '') +
						(domain ? ';[ ]*domain=' + domain + '(;|$)' : '')),

					cookieMatch = cookiePattern.exec(document.cookie);

				return cookieMatch ? unescapeWrapper(cookieMatch[2]) : 0;
			}

			// Haal de browser plugins op (functie van Pi Wik)
			function detectBrowserPlugins() {
				var i, mimeType;

				// Safari en Opera
				// IE6: typeof navigator.javaEnabled == 'unknown'
				if (typeof navigator.javaEnabled !== 'undefined' && navigator.javaEnabled()) {
					pluginMap.java[2] = '1';
				}

				// Firefox
				if (typeof window.GearsFactory === 'function') {
					pluginMap.gears[2] = '1';
				}

				if (navigator.mimeTypes && navigator.mimeTypes.length) {
					for (i in pluginMap) {
						mimeType = navigator.mimeTypes[pluginMap[i][1]];
						if (mimeType && mimeType.enabledPlugin) {
							pluginMap[i][2] = '1';
						}
					}
				}
			}
			
			// Haal de pagina referrer op
			function getReferrer() {
				var referrer = '';
				try {
					referrer = top.document.referrer;
				} catch (e) {
					if (parent) {
						try {
							referrer = parent.document.referrer;
						} catch (e2) {
							referrer = '';
						}
					}
				}
				if (referrer === '') {
					referrer = document.referrer;
				}

				return referrer;
			}
			
			// functie om te controleren of een variabele numeriek is
			function isNumber(n) {
			  return !isNaN(parseFloat(n)) && isFinite(n);
			}
			
			// Deze functie logt een pagina weergave voor het bezoek
			function logPageView (pageID) {
				
				// controleer of de pageID numeriek is voor deze te loggen
				if (!isNumber(pageID))		return;
				
				// bouw de request URL
				var requestURL = 'stats.php?statsact=p' +
								'&id=' + id +
								'&tp=0' +
								'&pi=' + pageID +
								'&rand=' + Math.random();
				
				// stuur de log door
				getImage(requestURL);
				
			}
			
			// Deze functie logt een actie (handeling) op de website
			function logAction (actionTypeIndex, param1, param2) {
				if (param1 === undefined)	param1 = null;
				if (param2 === undefined)	param2 = null;
				
				// controleer of de actionTypeIndex een geldig nummer is
				if (actionTypeIndex === undefined || !isNumber(actionTypeIndex) || actionTypeIndex < 0 || actionTypeIndex > 254)		return;
				
				// als parameter 1 ingesteld is, controleer dan of deze wel numeriek is
				if (param1 != null && !isNumber(param1))		return;
				
				// bouw de request URL
				var requestURL = 'stats.php?statsact=a' +
								'&id=' + id +
								'&tp=0' +
								'&ai=' + actionTypeIndex;
				if (param1 != null)		requestURL +=	'&p1=' + param1;
				if (param2 != null)		requestURL +=	'&p2=' + escapeWrapper(param2);
				requestURL +=	'&rand=' + Math.random();
				
				// stuur de log door
				getImage(requestURL);
				
			}
			return {
				
				// public maken van de updateVisitorInfo functie
				updateVisitorInfo: function () {
					updateVisitorInfo();
				},
				
				// public maken van de logPageView functie
				logPageView: function (pageID) {
					logPageView(pageID);
				},
				
				// public maken van de logAction functie
				logAction: function (actionTypeIndex, param1, param2) {
					logAction(actionTypeIndex, param1, param2);
				}
				
			};
		}
		
		return {
			// public maken van de getVisit functie
			getVisit: function (id) {
				return new Visit(id);
			}
		};
		
	}());
	
}
