function class_webwinkel () {
	
	
	this.handle 					= function (get) {
		
		if (cache.categorien === undefined) 
		{
			var ajaxload = new ajaxcall(base_url + 'json/webwinkel/getCategorien', '');
			
			ajaxload.onload = function (data) {
				
				data = ajaxload.toJSON (data);
				cache.fill_categorien(data);
				
				webwinkel_content.buildMenu(cache.categorien);
				
				webwinkel.checkurl(cache.categorien[0]['id']);
				webwinkel.putOpen(document.getElementById(cache.categorien[0]['id']));
				
			};
		}
		else
		{
			webwinkel_content.buildMenu(cache.categorien);
			this.checkurl(get);
		}
		
		
	};
	
	this.buildMenu = function() {
		
		if (cache.categorien === undefined) 
		{
			var ajaxload = new ajaxcall(base_url + 'json/webwinkel/getCategorien', '');
			
			ajaxload.onload = function (data) {
				
				data = ajaxload.toJSON (data);
				cache.fill_categorien(data);
				
				webwinkel_content.buildMenu(cache.categorien);
			};
		}
		else
		{
			webwinkel_content.buildMenu(cache.categorien);
		}
		
		
	};
	
	this.putOpen = function (object) {
		
		for(var i = 0; i < 21; i++)
		{
			if (document.getElementById(i + 'sub') !== null)
				document.getElementById(i + 'sub').style.display = 'none';
		}
		
		
		document.getElementById(object.rev + 'sub').style.display = '';
		
	};
	
	
	this.checkurl					= function (get) {
		
		webwinkel_content.changeActive(get);
		
		if (get[1] == 'webshop')
		{
			this.content();
		}
		else
		{
			this.categorie(get);
			webwinkel_content.changeActive(get);
		}
		
	};
	
	this.content 					= function (get) {
		
		if (cache.pagina === undefined)
		{
			var ajaxload = new ajaxcall(base_url + 'json/webwinkel/getPagina', 'id=' + get);
			
			ajaxload.onload = function (data) {
				
				data = ajaxload.toJSON (data);
				cache.fill_pagina(data);
				
				webwinkel_content.showPagina(cache.pagina);
				
			};
		}
		else
		{
			webwinkel_content.showPagina(cache.pagina);
		}
		
	};
	
	this.categorie					= function (active) {
		
		var check = false;
		for(var i = 0; i < cache.categorien.length; i++)
		{
			if (cache.categorien[i]['id'] == active)
			{
				var data = cache.categorien[i];
			}
			else if (cache.categorien[i]['parentID'] == active)
			{
				check = true;
			}
		}
		var subs = new Array();
		for(var i = 0; i < cache.categorien.length; i++)
		{
			if (cache.categorien[i]['parentID'] == data['id'])
			{
				subs[subs.length] = cache.categorien[i];
			}	
		}
		if (subs.length > 0)
		{
			this.getRestProducten(data, subs);
		}
		
		if (check === false)
		{
			if (cache.producten === undefined)
			{
				var producten = new ajaxcall(base_url + 'json/webwinkel/getProducten', 'id=' + active);
				producten.onload = function (json) {
					
					json = producten.toJSON(json);
					cache.fill_producten(active, json);
					
					if (cache.producten[active] === null)
						return;
					
					webwinkel_content.showProducten(cache.producten[active], data);
					
				};
				return;
			}
			else 
			{
				if (cache.producten[active] === undefined)
				{
					var producten = new ajaxcall(base_url + 'json/webwinkel/getProducten', 'id=' + active);
					producten.onload = function (json) {
						
						json = producten.toJSON(json);
						cache.fill_producten(active, json);
						
						if (cache.producten[active] === null)
							return;
						
						webwinkel_content.showProducten(cache.producten[active], data);
						
					};
					return;
				}
			}
			
			webwinkel_content.showProducten(cache.producten[active], data);
		}
		
	};
	
	this.getRestProducten		= function (data, subs) {
		
		var length = subs.length;
		var post = '';
		for(var i = 0; i < length; i++) {
			
			if (i == (length - 1))
				post += i + '=' + subs[i]['id'];
			else
				post += i + '=' + subs[i]['id'] + '&';
			
		}
		
		var prods = new ajaxcall(base_url + 'json/webwinkel/getRestProducten', post);
		prods.onload = function (producten) {
			
			producten = prods.toJSON(producten);
			
			webwinkel_content.showCategorie(data, producten);
			
		};
		
	};
	
	this.getPath 				= function (data)
	{
		for(var i = 0; i < cache.categorien.length; i++)
		{
			if (cache.categorien[i]['id'] == data['parentID'])
			{
				return cache.categorien[i]['titel'];
			}
		}
		return false;
		
	};
	
	this.sortProducten				= function (sort, categorie) {
		
		if (sort != 'prijs')
			cache.producten[categorie['id']] = sortArray(cache.producten[categorie['id']], sort, false);
		else
			cache.producten[categorie['id']] = sortArray(cache.producten[categorie['id']], sort, true);
		
		webwinkel_content.showProducten(cache.producten[categorie['id']], categorie);
		
	};
	
	this.berekenen = function (price, aantal) {
		
		if (aantal !== undefined)
			webwinkel_content.aantal = aantal;
		
		
		
		
		
	};
	
};
var webwinkel = new class_webwinkel();
