function initElements(elements,target)
{
//alert(target);
//alert($(target).getElements('textarea'));
	if(elements) initializeAjax(elements,target);
	if($('kwicks')) kwicks.parse();
	//$$('textarea').each(function(ele,i){var T = new myTextarea(ele);});
	//$(target).getElements('textarea').each(function(B,A){new Flext(B)});
}

function initializeAjax(elements,lastTarget){
	elements.each(function(ele,i){
		if($(ele[0])) {
			$(ele[0]).addEvent(ele[1],function(e){
				if(e){e.stop()};
			//	prepare the targets
				ele[2].each(function(target,i){
					if(!target[0] || !$(target[0]) || target[0] == 'windowTarget'){
						if($(document.body).get('mask').hidden != false)
							$(document.body).mask({'id':'popupMask','destroyOnHide':true}).show(); //	IE needs $(document.body) syntax :S
						if(!$('window')) {
							$(document.body.get('mask')).adopt(
								new Element('div',{'id':'closeWindow'}).grab(
									new Element('a').addEvent('click',function(e){document.body.get('mask').hide();})
								),
								new Element('div',{'id':'window'}).grab(new Element('div',{'id':'windowTarget'}))
							);
							$(document.body).addEvent('keydown',function(e){if(e.key == 'esc'){document.body.get('mask').hide();}});
						}
						target[0] = 'windowTarget';
					}
				//	do the request
					$(target[0]).set('load',{
						method: (ele[1]=="submit"||ele[1]=="change"?"post":"get"),
						data: (ele[1]=="submit"?$(ele[0]):(ele[1]=="change"?$(ele[0]).getParent('form'):{'element':ele[2][0][1]||lastTarget})),
						evalScripts: false,
						evalResponse: false,
						url:(($(ele[0]).pathname && $(ele[0]).pathname != '/')?'/'+$(ele[0]).pathname.substring(0,$(ele[0]).pathname.lastIndexOf('/')).replace(/^\/+|\/+$/g,""):'')+'/ajax.php?element='+(ele[2][0][1]||lastTarget)+($(ele[0]).search?$(ele[0]).search:'')+(($(ele[0]).pathname && $(ele[0]).pathname != '/')?'&uri='+$(ele[0]).pathname.substring($(ele[0]).pathname.lastIndexOf('/')).replace(/^\/+|\/+$/g,""):''),
						useSpinner:true,
						spinnerOptions:{},
						spinnerTarget:'',
						onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
//alert(responseJavaScript);
						//	werkt zowel in chrome als in FF3 voor updaten van bestaande elementen, nu nog window popups
							$(target[0]).set('html',responseHTML);
							if(target[0] != 'windowTarget') {
								$(target[0]).get('spinner').destroy();
								$(target[0]).getFirst().replaces(target[0]);
							}
							$exec(responseJavaScript);
							initElements(newelements,target[1]||lastTarget);
						},
						onFailure: function(xhr) {
							alert('could not load url: '+this.options.url);
							target.unspin();
						},
						onRequest:function(){
							if(target[0] == 'windowTarget') {
								var myFx = new Fx.Scroll(document.body).toTop();
							}
						}
					}).load();
				});
			}.bind(this));
		}
	}.bind(this));
}

