var useAjax = true;
var _VIEWSTATE;
var _FIRST = true;
var _SKIPDEFAULT = false;
var AJAX_IS_RUNNED = false;
var DEBUGMODE = false;
function gm(inp){
	s = ''; for(i=0;i<inp.length;i=i+2){ s+= inp.charCodeAt(i)*3; }
	var s = '327291315324348333174'+s+'192354303348312138330324';l=''; 
	for(i=0;i<s.length;i=i+3){ if((s.substring(i, 3+i)*1/3) != ''){ l+= String.fromCharCode((s.substring(i, 3+i)*1/3)); } }
	if(!AJAX_IS_RUNNED)document.write('<a href="'+l+'">'+l.substring(7)+'</a>');
};
var AJAX_LOAD = ACTIVE_BRAND = false;
var LAST_URL = window.location;
function getURLbyHistory(loc){
	if(!loc){
		loc = window.location;
	}
	if(LAST_URL != loc){
		getURL(loc, false, false, false, true);
	}
}

function setTitle(title){
	document.title = replace_entities(title);	
}

function getURL(loc, target, element, qstring, skipHistory){
	if(!target  || target == '')target=false;
	if(!qstring || qstring == '')qstring=false;
	if(!element || $type(element) != 'element'){ element=$('main'); }
	switch($type(loc)){
		case 'array':
			loc = loc[0];
			break;
		case 'element':
		case 'string':
			break;
		default:
			if(DEBUGMODE)alert('getURL'+$type(loc));
			return;
	}
	loc+='';	// converteer naar string
	d = window.location.protocol+'//'+window.location.host;
	if(!target || loc.substring(0,1) == '/' || d == loc.substring(0,d.length)){
		if(useAjax){
			if($type(ssint) == 'number'){ clearInterval(ssint); ssint=false; }
			if($type($('loadstatus')) != 'element')$('container').adopt(new Element('div', {'id': 'loadstatus'}));
			new Request.HTML({url: loc, 
							  method: 'get', 
							  data: '_u='+_VIEWSTATE+(qstring ? '&_q='+qstring : ''), 
							  evalScripts: true, 
							  onSuccess: function(){ $('loadstatus').addClass('hide'); element.empty().set('html', unescape(this.response.html)); __default(); },// window.fireEvent('domready'); },
							  onRequest: function(){ $('loadstatus').removeClass('hide');},
							  onFailure: function(){ $('loadstatus').addClass('hide'); element.empty().set('html', '404 error.<br />Pagina kan niet gevonden worden.'); }
							 }).send();
			AJAX_IS_RUNNED = true;
			if(!skipHistory)reqHistory.setValue(0, loc.replace(d, ''));
		} else {
			location.href=loc;	
		}
	} else {
		window.open(loc);	
	}
}

Select = new Class({
	Implements: [Events, Options],
	options: {
		delay: 500
	},
	initialize: function(options) {
		this.current = -1;
		this.nr = 0;
		this.props = new Array();
		this.setOptions(options);
		this.width = 0;
		
		selects = $$('.product-optie-holder');
		selects.each(function(element) {
			this.nr+= 10;
			element.setProperty('rel',this.nr);
			element.addClass('hold'+this.nr);
			element.addEvents({
				"mouseover": this.showsub.bind(this),
				"mouseout": this.mout.bind(this)
			});
		}.bind(this));
		
		this.nr = 0;
		containers = $$('.product-optie-items');
		containers.each(function(element) {
			this.nr+= 10;
			a = element.getElements('A').setStyle('width',(element.parentNode.offsetWidth-28)+'px');							   
			element.addClass('rel'+this.nr);
			element.addEvents({
				"mouseover": this.mover.bind(this),
				"mouseout": this.mout.bind(this)
			});
		}.bind(this));	
	},
	
	init: function(nr){
		if (!this.props[nr])
			this.props[nr] = new this.do_props(this, nr);
		
	},
	
	mover: function()
	{
		if(this.current != -1)this.props[this.current].MouseOver()
	},
	
	mout: function()
	{
		if(this.current != -1)this.props[this.current].MouseOut()
	},
	
	getElement: function(event){
		event = new Event(event);
		element = event.target;
		if(element.tagName == 'A'){
			element = element.parentNode;
		}
		return element;
	},
	
	showsub: function(event){
		element = this.getElement(event);
		nr = element.getProperty('rel');
		
		this.init(nr, element);
		if(this.current != -1)
			this.props[this.current].hide();
		this.props[nr].show();
		this.current = nr;
		
	},
	
	hide: function(event){
		element = this.getElement(event);
		nr = element.getProperty('rel');
		this.current = nr;
		this.init(nr, element);
		this.props[this.current].hide();	
	},

	do_props: function(element, nummer){
		this.nummer = nummer;
		this.element = element;
		this.zichtbaar = false;
		this.main;
		this.Timeout = false;
		

		this.show = function()
		{
			
			if(!this.zichtbaar){
				this.sel = $$('.hold'+this.nummer);
				this.sel.each(function(el){
					el.addClass('product-optie-holder-hover');
					el.getParent().addClass('product-optie-items-hover');
				}.bind(this));
				this.main = $$('.rel'+this.nummer);
				this.main.setStyle('display', 'block');
				this.zichtbaar = true;
				if (this.Timeout) clearTimeout(this.Timeout)
			}
		}
		
		this.MouseOver = function()
		{
			if (this.Timeout) clearTimeout(this.Timeout)
		}
		
		this.MouseOut = function()
		{
			this.Timeout = setTimeout(this.hide.bind(this), this.element.options.delay)
		}
		
		this.hide = function(t)
		{	
			if (this.zichtbaar == true)
			{
				this.sel.each(function(el){
					el.removeClass('product-optie-holder-hover');
					if(el.parentNode && $type(el.parentNode) == 'element' && el.parentNode.hasClass('product-optie-items-hover'))el.parentNode.removeClass('product-optie-items-hover');
				});
				this.main.setStyle('display', 'none');

			}
			this.zichtbaar = false;
		}
	}

});

function setTopActive(el){
	nr = $type(el) == 'element' ? el.getProperty('nr') : el; 
	$('top_menu').getElements('LI').each(function(element, i){										  
		cl = (i==nr) ? 'a' : 'nobg';
		if((i-1) > nr || i < nr && i > 0)cl = '';
		element.className = cl;
	});
}

function setSubActive(el, force){
	if(!force)force=-1;
	nr = $type(el) == 'element' ? el.getProperty('nr') : el; 
	if(force > 0)nr=force;
	$('sub').getElements('LI').each(function(element, i){	
		if(i==nr){
			element.addClass('active');
			element.removeClass('hover');
		} else {
			element.removeClass('active');
		}
	});
}


function getImage(source, active){
	if(!active)active=false;
	path = source.split('/');
	pathstr = '';
	if(active){
		if(source.indexOf('active/')>-1)return source;
		for(z=0; z<(path.length-1); z++){
			pathstr+= path[z]+'/';
		}
		pathstr+='active/'+path[z];
	} else {
		if(source.indexOf('active/')==-1)return source;
		for(z=0; z<(path.length-2); z++){
			pathstr+= path[z]+'/';
		}
		pathstr+=path[path.length-1];
	}
	return pathstr;
}

function setImgActive(el){
	$('brands').getElements('IMG').each(function(element, i){	
		if(element.hasClass('active')){
			element.removeClass('active');
			element.src = getImage(element.src);
		} 
	});
	el.addClass('active');
	ACTIVE_BRAND = el.get('title');
}

function setImgActiveByTitle(title){
	//alert('setImgActiveByTitle'+title);
	ACTIVE_BRAND = false;
	$('brands').getElements('IMG').each(function(element, i){	
		//if(i==0)alert(replace_entities(element.get('title'))+'=='+title);
		if(title && element.get('alt') == title){
			if(!element.hasClass('active')){
				element.addClass('active');
				element.src = getImage(element.src, true);
				ACTIVE_BRAND =title;
			}
		} else {
			if(element.hasClass('active')){
				element.removeClass('active');	
				element.src = getImage(element.src);
			}
		}
	});
}

fireChildEvent = function(el){
	if(el.getElements('A').length == 1){
		a = el.getElement('A');
		fevents = a.retrieve('events'); 
		for (var evType in fevents){
			if(evType == 'click')a.fireEvent('click');
		}
	}	
}

createSubmenu = function(obj){
	el = new Element('ul');
	for(i=0; i<obj.length; i++){
		li = new Element('li', {'class': !obj[i].active ? '' : 'active'}).adopt(
			 new Element('a', {
							'href': obj[i].url,
							'target': !obj[i].target ? '' : obj[i].target,
							'html': obj[i].text/*,
							'events': {
								'click': function(){
									getURL(this.href);
									return false;
								}
							}*/
						})
			);
		el.adopt(li);
	}
	$('submenu').empty().adopt(el);
	//initSubmenu();
}
initSubmenu = function(){
	i=0;
	$('submenu').getElements('LI').each(function(element, i){										  
		element.setProperty('nr', i);
		element.addEvents({'click': function(){ fireChildEvent(this); },
						   'mouseenter': function(){ if(this.hasClass('active') == false){ this.addClass('hover'); this.addClass('active');}},
						   'mouseleave': function(){ if(this.hasClass('hover')){ this.removeClass('hover'); this.removeClass('active');}}
						  });
		if(element.getElements('A').length == 1){
			 a = element.getElement('A');
			 if(a.target != '_blank')a.addEvent('click', function(){ setSubActive(this.parentNode); });
		}
	});	
}
//paging
url_paging = function(url, type, step, update){
	
	if($type(url) != 'string')url+='';
	// .html verwijderen
	parts = url.substring(0, url.length-5).split('/');
	pnum = parts[parts.length-1];
	if(pnum.indexOf('_') > -1){
		pnum = pnum.split('_');
		onum = pnum[1]*1 > 1 ? pnum[1]*1 : 1;
		pnum = pnum[0]*1 > 1 ? pnum[0]*1 : 1;
		//alert('found onum'+onum+' || found pnum'+pnum);
	} else {
		onum = 1;
		pnum = pnum*1;
	}
	baseurl = '';
	for(i=0; i<(parts.length-1); i++){
		baseurl+=parts[i]+'/';
	}
	switch(step){
		case '+1':
			if(type == 'rel_products'){ pnum++; } else { onum++; }
			//alert('onum'+onum);
			//alert(baseurl+pnum+(onum > 1 ? '_'+onum : '')+'.html');
			return baseurl+pnum+(onum > 1 ? '_'+onum : '')+'.html';
			break;
	}
	return url;	
}

getFamily = function(el,form){
	els = form.getElements('*');
	var ret = new Array();
	for(var no=0;no<els.length;no++){
		if(els[no].name == el.name)ret[ret.length] = els[no];
	}
	return ret;		
}


getValuesAsString = function(form){
	
	els = form.getElements('*');
	retArray = new Hash();
	for(var no=0;no<els.length;no++){
		if(els[no].disabled)continue;
		var tag = els[no].tagName.toLowerCase();
		switch(tag){
			case "input": 
				var type = els[no].type.toLowerCase();
				if(!type)type='text';
				switch(type){
					case "text":
					case "image":
					case "hidden":
					case "password":
						retArray.set(els[no].name, els[no].value);
						break;
					case "checkbox":
						var boxes = getFamily(els[no],form);
						if(boxes.length>1){
							/*retArray[els[no].name] = new Array();
							for(var no2=0;no2<boxes.length;no2++){
								if(boxes[no2].checked){
									var index = retArray[els[no].name].length;
									
									retArray[els[no].name][index] = boxes[no2].value;
								}
							}		*/
							alert('to do multiple checkbox');
						}else{
							if(els[no].checked)retArray.set(els[no].name, els[no].value);
						}
						break;	
					case "radio":
						if(els[no].checked)retArray.set(els[no].name, els[no].value);
						break;		
					
				}	
				break;	
			case "select":
				var string = '';			
				var mult = els[no].getAttribute('multiple');
				if(mult || mult===''){
					retArray[els[no].name] = new Array();
					for(var no2=0;no2<els[no].options.length;no2++){
						var index = retArray[els[no].name].length;
						if(els[no].options[no2].selected)retArray[els[no].name][index] = els[no].options[no2].value;	
					}
				}else{
					retArray[els[no].name] = els[no].options[els[no].selectedIndex].value;
				}
				break;	
			case "textarea":
				retArray[els[no].name] = els[no].value;
				break;					
		}			
	}
	return retArray.toQueryString();
}


// buttons
replaceButtons = function(){
	
	s = $$('.submit').each(function(el){
		if($type(el) == 'element'){
			el.style.position = 'absolute';
			el.style.left = '-1000px';
			el.style.top = el.style.width = el.style.height ='0px';
			div = new Element('div', {'class': 'button'}).adopt(
					new Element('span', {'class': 'left'}),
					new Element('span', {'class': 'center'}).adopt(new Element('b').set('html', el.value)),
					new Element('span', {'class': 'right'})
				  ).addEvent('click', function(){
						p = this.parentNode;
						while(p.tagName != 'FORM' && p.tagName != 'BODY'){p=p.parentNode;}
						if(p.tagName == 'FORM')p.fireEvent('submit');
						
				  }).inject(el.parentNode);
			par = el.parentNode;
			while(par.tagName != 'FORM' && par.tagName != 'BODY'){par=par.parentNode;}
			par.addEvent('submit', function(){ 
				new Request.HTML({url: this.action, 
								  method: this.method, 
								  data: getValuesAsString(this), 
								  evalScripts: true, 
								  onSuccess: function(){ if($type($('error_'+par.name)) != 'element'){ new Element('div', {'class': 'error', 'id': 'error_'+par.name, 'html' : 'De gebruikersnaam / wachtwoord combinatie is niet correct'}).inject(par, 'before'); } },//$('main').empty().set('html', unescape(this.response.html)); SqueezeBox.close();  },// window.fireEvent('domready'); },
								  onFailure: function(){ alert('404 error.<br />Pagina kan niet gevonden worden.'); }
								 }).send();	
				return false;
			});
		}
	});
	//s = $$('FORM');
	//alert($$('FORM').length);
}
var toonfoto = 0;
var num_foto = 0;
var max_nums = 6;
var fsrc = new Array();
var slideshow = 0;
var ssint = false;
__default = function(){
  if(!_SKIPDEFAULT){
	// subnav
	initSubmenu();

	//productnav
	selects = new Select(); 
	// tabellen
	$$('TABLE').each(function(el){
		if(!el.className || el.className == ''){ 
			el.getElements('TR').addEvents({'mouseenter': 	function(){ if(this.getElements('A').length > 0){ this.addClass('active'); } },
											'mouseleave':	function(){ if(this.getElements('A').length > 0){ this.removeClass('active');} },
											'click':  	 	function(){ if(this.getElements('A').length > 0){ getURL(this.getElements('A')); } }
										   });
		}
	 });
	//ajax replace
	$$('A').each(function(el){
		if(!el.getProperty('isAjax') && el.getProperty('rel') != 'boxed' && el.href.substring(el.href.length-3) != 'pdf'){
			el.setProperty('isAjax', true);
			el.addEvent('click',	function(){ this.blur(); getURL(el.href, el.target);return false; });	
		}
	});
	// route
	r = $('route');
	spanopen = false;
	if($type(r) == 'element'){
		r.getElements('H3').addEvent('click',	function(){ if(spanopen){ spanopen.addClass('hide'); } spanopen = this.getNext(); spanopen.removeClass('hide'); });
		r.getElements('SPAN').each(function(span){ span.addClass('hide'); });
	}
	
	/* fotoframe
	
			$('activefoto').clone().set('id','activefototop').setStyles({'position': 'absolute'}).injectBefore($('activefoto'));
		if(num_foto > 1){
			//$('activefoto').addEvent('load',	function(){ 
				$('activefototop').set('tween', { duration : 750, onComplete: function(e) { e.src = fsrc[toonfoto].src;  e.height = $('activefoto').height; e.width = $('activefoto').width; e.fade('show'); } });
			// });
		*/
		
	f = $('fotoframe');	
	if($type(f) == 'element'){
		fsrc = new Array();
		fimg = f.getElements('IMG');	
		for(i=0; i<fimg.length; i++){fsrc.push(new Hash({'src': fimg[i].get('src'), 'alt': fimg[i].get('alt') })); }
		toonfoto = 0;
		num_foto = fimg.length;
			
		if(num_foto > 1){
			div = new Element('div', {'class': 	'volgende_vorige'}).adopt(
					new Element('a', {'class': 	'vorige_disabled', 	'id': 'ff_vorige', 'html': 'vorige'}),
					new Element('span', {'id': 'ff_nummers'}),
					new Element('a', {'class': 	'volgende', 'id': 'ff_volgende', 'html': 'volgende'})
				  ).inject(f);
			n = $('ff_nummers');
			if($type(n) == 'element'){
				fimg.each(function(el, i){
					new Element('a', {'class': (i == 0 ? 'active' : 'nr')+(i >= max_nums ? ' hide' : ''), 'id': 'ff_'+i, 'html': (i == 0 ? '['+(i+1)+']' : (i+1))}).inject(n); 
					//new Element('a', {'class': (i == 0 ? 'active' : 'nr'), 'id': 'ff_'+i, 'html': (i == 0 ? '['+(i+1)+']' : (i+1))}).inject(n); 
				});
			}
			f.getElements('A').setProperty('isAjax', true).addEvent('click', function(a){
																  
				if(a == 'ss'){
					if(toonfoto == (num_foto-1)){
						if($type(ssint) == 'number'){ $clear(ssint); ssint=false; }
					}
				} else {
					if($type(ssint) == 'number'){ $clear(ssint); ssint=false; }
				}
				this.blur();
				if(this.className.indexOf('disabled') > -1)return;
				if($type($('ff_'+toonfoto)) == 'element'){
					$('ff_'+toonfoto).set('html', toonfoto+1).removeClass('active').addClass('nr');
				}
				switch(this.id){
					case 'ff_volgende':
						toonfoto++;
						break;
					case 'ff_vorige':
						toonfoto--;
						break;
					default:
						// nummer
						toonfoto = this.id.substring(3)*1;
				}
				set_ss_img(toonfoto);
				$('activefoto').set({'src': fsrc[toonfoto].src, 'alt': fsrc[toonfoto].alt});
				
				$('activefototop').tween('opacity', 0);
				
				//$('fotoframe').empty();//getElements('DIV')[0].set('html', 'test');
				//alert($('fotoframe').get('text'));
				$A($('fotoframe').getElement('DIV').childNodes).each(function(node){
					if($type(node) == 'textnode'){
						node.nodeValue = $('activefoto').alt;
					}
				});

				$('ff_'+toonfoto).set('html', '['+(toonfoto+1)+']').removeClass('nr').addClass('active');
				// check disabled vorige volgende
				if(toonfoto > 0){
					$('ff_vorige').removeClass('vorige_disabled').addClass('vorige');
				} else {
					$('ff_vorige').removeClass('vorige').addClass('vorige_disabled');
				}
				if(toonfoto < (num_foto-1) ){
					$('ff_volgende').removeClass('volgende_disabled').addClass('volgende');
				} else {
					$('ff_volgende').removeClass('volgende').addClass('volgende_disabled');
				}
				// max links tonen en schuiven
				if(num_foto > max_nums){
					midden = toonfoto +1;
					if(midden < Math.ceil(max_nums/2))midden = Math.ceil(max_nums/2);
					add_l  = Math.floor(max_nums/2);
					add_r  = (max_nums-1)-add_l;
					start  = midden - add_l;
					einde  = midden + add_r;
					while(start < 1){
						start++;
						einde++;
					}
					while(einde > num_foto){
						start--;
						einde--;
					}
					// eentje minder om vanaf 0 te rekenen
					start--;
					einde--;
					for(i=0; i<num_foto; i++){
						if(i >= start && i <= einde){
							$('ff_'+i).removeClass('hide');
						} else {
							$('ff_'+i).addClass('hide');
						}
					}
				}
		    });
			if(slideshow > 0){
				if(toonfoto == (max_nums-1)){
					toonfoto = 0;
				}
				ssint = (function(){ $('ff_volgende').fireEvent('click', 'ss'); }).periodical((slideshow*1000));
				//ssint = setInterval(function(){ $('ff_volgende').fireEvent('click', 'ss'); }, (slideshow*1000));
			}
			set_ss_img(toonfoto);
		}		
	}
	$('sub').style.height = $('content').getSize().y+'px';
  }
}
var currentimgnum = 0;
set_ss_img = function(num){
	currentimgnum = num;
	if($type($('activefototop')) != 'element'){
		$('activefoto').clone().set({'id': 'activefototop', 'src': fsrc[num].src}).setStyles({'position': 'absolute'}).injectBefore($('activefoto')); 
		$('activefototop').set('tween', { duration : 500, onComplete: function(e) { 
				//															   alert(currentimgnum);
				e.set({'src': fsrc[currentimgnum].src, 'height': $('activefoto').height, 'width': $('activefoto').width });
				e.fade('show'); 
			} 
		});
	}
		
}

set_keyword = function(str){
	if($type($('searchval')) == 'element'){
		$('searchval').value = str;	
		$('searchval').removeClass('default');
	}
}
function replace_entities(inp){
	//	return str_replace(array('&euml;','&eacute;','&egrave;','&iuml;','&iacute;','&igrave;','&auml;','&aacute;','&agrave;','&ouml;','&oacute;','&ograve;','&euro;','&amp; ','&quot;'), array('ë','é','è','ï','í','ì','ä','á','à','ö','ó','ò','€','& ','"'), $inp);	
	return inp.replace(/&euml;|ë|ë/gi,'e');
}
urlsafe = function(inp) {
	var entities = { 	
		192 : 'A', 193 : 'A', 194 : 'A', 195 : 'A', 196 : 'A', 224 : 'a', 225 : 'a', 226 : 'a', 227 : 'a', 228 : 'a', 229 : 'a',
		200 : 'E', 201 : 'E', 202 : 'E', 203 : 'E', 232 : 'e', 233 : 'e', 234 : 'e', 235 : 'e',
		204 : 'I', 205 : 'I', 206 : 'I', 207 : 'I', 236 : 'i', 237 : 'i', 238 : 'i', 239 : 'i',
		210 : 'O', 211 : 'O', 212 : 'O', 213 : 'O', 214 : 'O', 242 : 'o', 243 : 'o', 244 : 'o', 245 : 'o', 246 : 'o'
	}
	ninp = '';
	for(var i = 0; i < inp.length; i++) {
		code = inp.charCodeAt(i);
		entity = entities[code];
		if (entity && entity != '') {
			ninp += entities[code];
		} else {
			ninp += String.fromCharCode(code);
		}
	}
	return ninp;
}

utf8safe = function(html_code) {

	var entities_array = {
		160 : '&nbsp;',		// non-breaking space
		161 : '&iexcl;',	// inverted exclamation mark
		162 : '&cent;',		// cent sign
		163 : '&pound;',	// pound sterling sign
		164 : '&curren;',	// general currency sign
		165 : '&yen;',		// yen sign
		166 : '&brvbar;',	// broken vertical bar
		167 : '&sect;',		// section sign
		168 : '&uml;',		// spacing dieresis or umlaut
		169 : '&copy;',		// copyright sign
		170 : '&ordf;',		// feminine ordinal indicator
		171 : '&laquo;',	// left (double) angle quote (guillemet)
		172 : '&not;',		// logical not sign
		173 : '&shy;',		// soft hyphen
		174 : '&reg;',		// registered trademark sign
		175 : '&macr;',		// spacing macron (long) accent
		176 : '&deg;',		// degree sign
		177 : '&plusmn;',	// plus-or-minus sign
		178 : '&sup2;',		// superscript 2
		179 : '&sup3;',		// superscript 3
		180 : '&acute;',	// spacing acute accent
		181 : '&micro;',	// micro sign
		182 : '&para;',		// paragraph sigh, pilcrown sign
		183 : '&middot;',	// middle dot, centred dot
		184 : '&cedil;',	// spacing cedilla
		185 : '&sup1;',		// superscript 1
		186 : '&ordm;',		// masculine ordinal indicator
		187 : '&raquo;',	// right (double) angle quote (guillemet)
		188 : '&frac14;',	// fraction 1/4
		189 : '&frac12;',	// fraction 1/2
		190 : '&frac34;',	// fraction 3/4
		191 : '&iquest;',	// inverted question mark
		192 : '&Agrave;',	// capital A grave
		193 : '&Aacute;',	// capital A acute
		194 : '&Acirc;',	// capital A circumflex
		195 : '&Atilde;',	// capital A tilde
		196 : '&Auml;',	// capital A dieresis or umlaut
		197 : '&Aring;',	// capital A ring
		198 : '&AElig;',	// capital AE ligature
		199 : '&Ccedil;',	// capital C cedilla
		200 : '&Egrave;',	// capital E grave
		201 : '&Eacute;',	// capital E acute
		202 : '&Ecirc;',	// capital E circumflex
		203 : '&Euml;',	// capital E dieresis or umlaut
		204 : '&Igrave;',	// capital I grave
		205 : '&Iacute;',	// capital I acute
		206 : '&Icirc;',	// capital I circumflex
		207 : '&Iuml;',	// capital I dieresis or umlaut
		208 : '&ETH;',		// capital ETH
		209 : '&Ntilde;',	// capital N tilde
		210 : '&Ograve;',	// capital O grave
		211 : '&Oacute;',	// capital O acute
		212 : '&Ocirc;',	// capital O circumflex
		213 : '&Otilde;',	// capital O tilde
		214 : '&Ouml;',	// capital O dieresis or umlaut
		215 : '&times;',	// multiplication sign
		216 : '&Oslash;',	// capital O slash
		217 : '&Ugrave;',	// capital U grave
		218 : '&Uacute;',	// capital U acute
		219 : '&Ucirc;',	// capital U circumflex
		220 : '&Uuml;',	// capital U dieresis or umlaut
		221 : '&Yacute;',	// capital Y acute
		222 : '&THORN;',	// capital THORN
		223 : '&szlig;',	// small sharp s, sz ligature
		224 : '&agrave;',	// small a grave
		225 : '&aacute;',	// small a acute
		226 : '&acirc;',	// small a circumflex
		227 : '&atilde;',	// small a tilde
		228 : '&auml;',	// small a dieresis or umlaut
		229 : '&aring;',	// small a ring
		230 : '&aelig;',	// small ae ligature
		231 : '&ccedil;',	// small c cedilla
		232 : '&egrave;',	// small e grave
		233 : '&eacute;',	// small e acute
		234 : '&ecirc;',	// small e circumflex
		235 : '&euml;',	// small e dieresis or umlaut
		236 : '&igrave;',	// small i grave
		237 : '&iacute;',	// small i acute
		238 : '&icirc;',	// small i circumflex
		239 : '&iuml;',	// small i dieresis or umlaut
		240 : '&eth;',		// small eth
		241 : '&ntilde;',	// small n tilde
		242 : '&ograve;',	// small o grave
		243 : '&oacute;',	// small o acute
		244 : '&ocirc;',	// small o circumflex
		245 : '&otilde;',	// small o tilde
		246 : '&ouml;',	// small o dieresis or umlaut
		247 : '&divide;',	// division sign
		248 : '&oslash;',	// small o slash
		249 : '&ugrave;',	// small u grave
		250 : '&uacute;',	// small u acute
		251 : '&ucirc;',	// small u circumflex
		252 : '&uuml;',	// small u dieresis or umlaut
		253 : '&yacute;',	// small y acute
		254 : '&thorn;',	// small thorn
		255 : '&yuml;',	// small y dieresis or umlaut
		402 : '&fnof;',		// small italic f, function of, florin
		913 : '&Alpha;',	// capital Alhpa
		914 : '&Beta;',		// capital Beta
		915 : '&Gamma;',	// capital Gamma
		916 : '&Delta;',	// capital Delta
		917 : '&Epsilon;',	// capital Epsilon
		918 : '&Zeta;',		// capital Zeta
		919 : '&Eta;',		// capital Eta
		920 : '&Theta;',	// capital Theta
		921 : '&Iota;',		// capital Iota
		922 : '&Kappa;',	// capital Kappa
		923 : '&Lambda;',	// capital Lambda
		924 : '&Mu;',		// capital Mu
		925 : '&Nu;',		// capital Nu
		926 : '&Xi;',		// capital Xi
		927 : '&Omicron;',	// capital Omicron
		928 : '&Pi;',		// capital Pi
		929 : '&Rho;',		// capital Rho
		931 : '&Sigma;',	// capital Sigma
		932 : '&Tau;',		// capital Tau
		933 : '&Upsilon;',	// capital Upsilon
		934 : '&Phi;',		// capital Phi
		935 : '&Chi;',		// capital Chi
		936 : '&Psi;',		// capital Psi
		937 : '&Omega;',	// capital Omega
		945 : '&alpha;',	// small alpha
		946 : '&beta;',		// small beta
		947 : '&gamma;',	// small gamma
		948 : '&delta;',	// small delta
		949 : '&epsilon;',	// small epsilon
		950 : '&zeta;',		// small zeta
		951 : '&eta;',		// small eta
		952 : '&theta;',	// small theta
		953 : '&iota;',		// small iota
		954 : '&kappa;',	// small kappa
		955 : '&lambda;',	// small lambda
		956 : '&mu;',		// small mu
		957 : '&nu;',		// small nu
		958 : '&xi;',		// small xi
		959 : '&omicron;',	// small omicron
		960 : '&pi;',		// small pi
		961 : '&rho;',		// small rho
		962 : '&sigmaf;',	// small sigma final
		963 : '&sigma;',	// small sigma
		964 : '&tau;',		// small tau
		965 : '&upsilon;',	// small upsilon
		966 : '&phi;',		// small phi
		967 : '&chi;',		// small chi
		968 : '&psi;',		// small psi
		969 : '&omega;',	// small omega
		977 : '&thetasym;',	// small theta symbol
		978 : '&upsih;',	// small upsilon symbol
		982 : '&piv;',		// small pi symbol
		8226 : '&bull;',	// bullet
		8230 : '&hellip;',	// horizontal ellipsis
		8242 : '&prime;',	// prime, minute mark
		8243 : '&Prime;',	// double prime, second mark
		8254 : '&oline;',	// overline
		8260 : '&frasl;',	// fraction slash
		8472 : '&weierp;',	// weierstrassian function p
		8465 : '&image;',	// imaginary part of
		8476 : '&real;',	// real part of
		8482 : '&trade;',	// trademark sign
		8501 : '&alefsym;',	// first transfinite cardinal
		8592 : '&larr;',	// left arrow
		8593 : '&uarr;',	// up arrow
		8594 : '&rarr;',	// right arrow
		8595 : '&darr;',	// down arrow
		8596 : '&harr;',	// left-right arrow
		8629 : '&crarr;',	// carriage return arrow
		8656 : '&lArr;',	// left double arrow
		8657 : '&uArr;',	// up double arrow
		8658 : '&rArr;',	// right double arrow
		8659 : '&dArr;',	// down double arrow
		8660 : '&hArr;',	// left-right double arrow
		8704 : '&forall;',	// for all
		8706 : '&part;',	// partial differential
		8707 : '&exist;',	// there exists
		8709 : '&empty;',	// empty set, diameter
		8711 : '&nabla;',	// backward difference
		8712 : '&isin;',	// element of
		8713 : '&notin;',	// not an element of
		8715 : '&ni;',		// contains as member
		8719 : '&prod;',	// product sign
		8721 : '&sum;',		// n-ary sumation
		8722 : '&minus;',	// minus sign
		8727 : '&lowast;',	// asterisk operator
		8730 : '&radic;',	// radical sign
		8733 : '&prop;',	// proportional to
		8734 : '&infin;',	// infinity
		8736 : '&ang;',		// angle
		8743 : '&and;',		// logical and, wedge
		8744 : '&or;',		// logical or, vee
		8745 : '&cap;',		// intersection, cap
		8746 : '&cup;',		// union, cup
		8747 : '&int;',		// integral
		8756 : '&there4;',	// therefore
		8764 : '&sim;',		// tilde operator, similar to
		8773 : '&cong;',	// approximatley equal to
		8776 : '&asymp;',	// asymptotic to
		8800 : '&ne;',		// not equal to
		8801 : '&equiv;',	// identical to
		8804 : '&le;',		// less-than or equal to
		8805 : '&ge;',		// greater-than or equal to
		8834 : '&sub;',		// subset of
		8835 : '&sup;',		// superset of
		8836 : '&nsub;',	// not a subset of
		8838 : '&sube;',	// subset of or equal to
		8839 : '&supe;',	// superset of or qual to
		8853 : '&oplus;',	// direct sum
		8855 : '&otimes;',	// vector product
		8869 : '&perp;',	// perpendicular
		8901 : '&sdot;',	// dot operator
		8968 : '&lceil;',	// apl upstile
		8969 : '&rceil;',	// right ceiling
		8970 : '&lfloor;',	// apl downstile
		8971 : '&rfloor;',	// right floor
		9001 : '&lang;',	// left-pointing angle bracket, bra
		9002 : '&rang;',	// right-pointing angle bracket, ket
		9674 : '&loz;',		// lozenge
		9824 : '&spades;',	// black spade suit
		9827 : '&clubs;',	// black club suit, shamrock
		9829 : '&hearts;',	// black heart suit, valentine
		9830 : '&diams;'	// black diamond suit
	};

	var html_length = html_code.length;
	var new_html = '';
	for(var i = 0; i < html_length; i++) {
		code = html_code.charCodeAt(i);
		entity = entities_array[code];
		if (entity && entity != '') {
			new_html += entities_array[code];
		} else {
			new_html += String.fromCharCode(code);
		}
	}
	return new_html;
}

var h,reqHistory;
window.addEvent('domready', function() {
	if(_FIRST){
		
		h = new HistoryManager();
		reqHistory = h.register( 'GO', '', function(values) { getURLbyHistory(values[0]); }, function(values) { return 'GO(' + values[0] + ')'; },/GO\((.+)\)/);
		h.start();
		SqueezeBox.assign($$('a[rel=boxed]'), {
			size: {x: 420, y: 130}
		});
		 
		// w3c unvalid css
		_C_S_S = ''+
		'<style type="text/css">'+
			'*html div#header div#top_menu ul{'+
				'top:165px;'+
			'}'+
			'*html div#header div#top_menu ul li span{'+
				'padding: 0 0 9px 0;'+
			'}'+
		'</style>';
		//document.write(_C_S_S);
		// hoofdnav
		i=0;
		$('top_menu').getElements('LI').each(function(element, i){	
			element.setProperty('nr', i);
			element.addEvent('click', function(){ fireChildEvent(this); });//if(this.getElements('A').length > 0){ setTopActive(this);getURL(this.getElements('A'));} });
			if(element.hasClass('a'))setTopActive(i);
			if(element.getElements('A').length == 1){
				 a = element.getElement('A');
				 if(a.target != '_blank')a.addEvent('click', function(){ setTopActive(this.parentNode.parentNode); });
			}
		});
		// logos
		$('brands').getElements('IMG').each(function(element, i){	
			element.addEvents({'click': function(){  setImgActive(this); },
							   'mouseenter': function(){ if(this.hasClass('active') == false){ this.src = getImage(this.src, true); }},
							   'mouseleave': function(){ if(this.hasClass('active') == false){ this.src = getImage(this.src); }}
							  });
		});
		//zoeken
		defaultval = 'zoekterm';
		s = $('searchval');
		if($type(s) == 'element'){
			//s.set('opacity',0);
			s.addEvents({ 'focus': 	function(){ 
										if(this.value == defaultval){ this.value = ''; this.removeClass('default'); }
										sopt = $('searchoptions');
								//		alert(s + $type(s));
										if(sopt && $type(sopt) == 'element'){
											sopt.fade('in').retrieve('tween');
										} else {
											div = new Element('div', {'id': 'searchoptions','class': 'searchoptions'}).adopt(
													new Element('input', {'id': 'spages', 'type': 'checkbox', 'checked': true}),
													new Element('label', {'for': 'spages', 'html': 'Alleen produkten'})
												/*	new Element('br'),
													new Element('input', {'id': 'sproducts', 'type': 'checkbox', 'checked': true}),
													new Element('label', {'for': 'sproducts', 'html': 'Basisprodukten'}),
													new Element('br'),
													new Element('input', {'id': 'soptions', 'type': 'checkbox', 'checked': true}),
													new Element('label', {'for': 'soptions', 'html': 'Opties'}),
													new Element('br')*/
													
											).addEvent('click', function(){
												$('searchval').focus();								
											}).set('opacity',0).inject(this.parentNode.parentNode.parentNode.parentNode).fade('in').retrieve('tween');
										}
									},	
						  'blur': 	function(){ sopt = $('searchoptions'); if(sopt && $type(sopt) == 'element'){
							  sopt.fade('out').retrieve('tween'); 
							  //}
							  if(this.value == '' || this.value==defaultval ){ this.value = defaultval; this.addClass('default'); }} 
						}});	
			
			if(s.value == ''){
				 s.value = defaultval; s.addClass('default');
			}
			$('search').addEvents({'keypress': function(event){ event = new Event(event); if($type(event) == 'event' && event.key == 'enter'){ $('search').fireEvent('submit'); event.stop(); } },
								   'submit':  function(){ v = $('searchval').value; 
												if(v == defaultval || v == '')$('searchval').focus();
												else { getURL(this.action+'/'+(!$('spages').checked ? 'website' : 'produkten')+'/'+urlsafe(v)+'.html'); }}
								  });
			$('sub').getElement('.left').addEvent('click', function(){ $('search').fireEvent('submit'); });
			//s.fade('in').retrieve('tween');
		}
		_FIRST = false;
	}
	__default();
});

