var AjaxUpdate = {
	
	start: function(props){
		this.props = Object.extend({
			updateinterval: 0
		}, props || {});
		
		
		
		if ($$('a[rel=AjaxGet]')){
			this.update('a[rel=AjaxGet]'); //AjaxUpdate.get();
			if (props.updateinterval>0)
				this.timeout = this.update.periodical(props.updateinterval, this, 'div[rel=AjaxUpdate]');
			
		}
		
	},
	
	update: function(sSelection){
		
		var sUrl = '';
		
		var oSelection = $$(sSelection);
		oSelection.each(function(oLink, i){
			
			sUrl = oLink.getProperty('href');
			
			var oResult = new Element('div');
			oResult.setProperty('rel', 'AjaxUpdate');
			oResult.setProperty('href', sUrl);
			
			new Ajax(sUrl, {
				method: 'get',
				update: oResult,
				encoding: 'utf-8'
				, evalScripts: false,
					evalResponse: false
				, onComplete: AjaxUpdate.oncomplete.pass([oResult, oLink])
				}).request();
			
		});
	},
	
	oncomplete: function(oResult, oLink){
		if (oResult){
			regexfind = /<div.*<\/div>/i
			
			var match = regexfind.exec(oResult.innerHTML.replace(/[\n]/g,''));
			
			//strip content to content only
			oResult.innerHTML = match;
			
			oResult.injectBefore(oLink);
			oLink.remove();
		}
		
	}

	
};

window.addEvent('domready', function(){
	AjaxUpdate.start({updateinterval: 0});
});