var checkboxHeight = "18";
var radioHeight = "18";
var selectWidth = "190";
var d=document;

document.write('<style type="text/css">input.styled { display: none; } select.styled { width: ' + selectWidth + 'px; height:16px; opacity: 0; z-index: 0; border:1px; padding:2px 3px 0px 3px }</style>');

var Custom = new Class({

	initialize: function() {		
		var inputs2 = document.getElementsByTagName("input"), span = Array(), ch = Array(), textnode, option, active, testImage;
		for(b = 0; b < inputs2.length; b++) {
			if((inputs2[b].type == "radio" || inputs2[b].type == "checkbox")  && this.hasClass(inputs2[b], "styled") && inputs2[b].added != "added") {
				inputs2[b].added = "added";				
				span[b] = document.createElement("span");
				span[b].className = inputs2[b].type;
				
				if(inputs2[b].checked == true) {
					position = "0 -" + ((radioHeight*2)) + "px";
					span[b].style.backgroundPosition = position;
				}
				inputs2[b].parentNode.insertBefore(span[b], inputs2[b]);
				span[b].onmousedown = this.pushed;
				span[b].onmouseup = this.check;
				document.onmouseup = this.clear;
				
			}
		}
		$('resultaten').style.display = 'block';
		$('loading').style.display = 'none';
	},	
	
	hasClass : function(obj, strClass) {
		if ( obj.className ){
			var arrList = obj.className.split(' ');
			var strClassUpper = strClass.toUpperCase();
			for ( var i = 0; i < arrList.length; i++ ){
				if ( arrList[i].toUpperCase() == strClassUpper ){
					return true;
				}
			}
		}
		return false;
	},
	
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true && (element.type == "radio" || element.type == "checkbox")) {
			this.style.backgroundPosition = "0 -" + ((radioHeight*3)) + "px";
		} else {
			this.style.backgroundPosition = "0 -18px";
		}
	},	
	check: function() {
		element = this.nextSibling;
		this.style.backgroundPosition = "0 -" + ((radioHeight*2)) + "px";
		group = this.nextSibling.name;
		inputs = document.getElementsByTagName("input");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].name == group && inputs[a] != this.nextSibling) {
				inputs[a].previousSibling.style.backgroundPosition = "0 -1px";			
			}
			if(inputs[a].name == group && inputs[a] == this.nextSibling) {
				if(inputs[a].onclick != undefined){
					inputs[a].onclick();
					removeAltClassRe = new RegExp('(^|\\s)alt(?:\\s|$)');
					var formitems = $$("#formRows div.form, #formRows p.form");
					counter = 0;
					formitems.each(function(formitem, i) {
						if(formitem.style.display!='none'){
							counter++;
							formitem.className = formitem.className.replace( this.removeAltClassRe, '$1').clean();
							if ( !(( counter % 2 ) == 0) ) {
						      formitem.addClass( 'alt' );   
						    }
						}						
					});
				}
			}			
		}
		
		if(element.checked==true&&element.type=="checkbox"){			
			this.style.backgroundPosition = "0 0px";
			checked = false;
		}
		if(element.checked==false&&element.type=="checkbox"){			
			this.style.backgroundPosition = "0 -" + ((radioHeight*2)) + "px";
			checked = true;
		}	
		if(element.type!="checkbox") {
			checked = true;
		}
		if(checked==true){
			element.checked = true;
		} else {
			element.checked = false;
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + ((radioHeight*2)) + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0px";
			} else if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled"){
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + ((radioHeight*2)) + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0px";
			}
		}
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
				if($("select"+this.name).onchange != undefined){
					$("select"+this.name).onchange();
				}
			}
		}
	}
});
