var AjaxControls={
	init: function(){
		this.scroll=new Fx.Scroll(window,{ wait: false, duration: 800, offset: {'y': -50}, transition: Fx.Transitions.Quad.easeInOut });
		this._chkLoader();
		this.fs=[]; this.es=[];	this.initAll();
	},
	add: function(fs,es){
		for(x=0;x<fs.length;x++)	this.fs.push(fs[x]);
		for(x=0;x<es.length;x++)	this.es.push(es[x]);
		this.initAll();
	},
	_chkLoader: function(){
		if(!$defined($('loader')))	new Element('img',{'styles':{'display':'none'},'src':'/images/ajax-loader.gif','id':'loader','alt':'preloader'}).injectAfter('wrapper');	
	},
	initAll: function(){
		this.active=1;
		this.hideLoader();
		
		$$('.getPg').each(function(e){
			
			if((e.rel)==null)	e.rel=1;	
			
			this._checkPL(e.rel);
			e.removeEvents('click').addEvent('click',function(e){
				new Event(e).stop();
				HM.setValue(0, this.href);
				
				AjaxControls._start(this.href,this.rel);
			});
		},this);
		
		$$('.bottom').each(function(e){
			e.getElements('a').each(function(e){
				e.addEvent('click',function(e){
					new Event(e).stop();	AjaxControls.scroll.toElement('pl'+this.rel);
				});
		 	});
		},this);
		
		this.fs.each(function(e){	e();	});
		dil();
	},
	stopAllD: function(){
		this.active=0;
		$$('.getPg',this.es).each(function(e){
			e.removeEvents('click').addEvent('click',function(e){	new Event(e).stop();	});	//Add blank event
		},this);
	},	//Stop All Events
	stopAll: function(){
		this.active=0;
		$$('.getPg').each(function(e){
			e.removeEvents('click').addEvent('click',function(e){	new Event(e).stop();	});	//Add blank event
		});
		this.es.each(function(e){
			$$(e).each(function(e){
				e.removeEvents('click').addEvent('click',function(e){	new Event(e).stop();	});	//Add blank event
			});
		});
	},	//Stop All Events
	call: function(href,rel){
		this._checkPL(rel);
		this._start(href,rel);
	},
	_start: function(href,rel){
		var p=new URL(href.split('?')[1]).getParams('*','ajax='+rel);
		this.showLoader(rel);
		new Ajax(href.split('?')[0], {method: 'get', update:$('cc'+rel), onComplete:this.initAll.bind(this)}).request(p);
	},
	showLoader: function(rel){
		if(!$defined(rel))	rel=1;
		$('loader').injectInside('pl'+rel).setStyle('display','block');	this.stopAll();
	},
	hideLoader: function(rel){
		if(!$defined(rel))	rel=1;
		this._chkLoader();
		$('loader').setStyle('display','none');
	},
	_checkPL: function(rel){
		var pl='pl'+rel;
		if(!$defined($(pl))){
			//'<div style="position:relative; top:0; left:0; width: 16px; height:16px; margin: 16px 0 16px '+(  $('paginating'+e.rel).style.width/2  ).round()+'px;" id="'+pl+'"></div>'.injectBefore('cc'+e.rel);
			//<div style="position:relative; top:0; left:0; width: 16px; height:16px; margin: 16px 0 16px 315px;" id="pl1"></div>
			new Element('div',{'id':pl,'styles':{	'position':'relative',
													'top':'0',
													'left':'0',
													'width':'16px',
													'height':'16px',
													'margin':'16px 0 0 '+((  $('paginating'+rel).getStyle('width').toInt()/2  ).round()+16)+'px'}
								}).injectBefore('cc'+rel);
		}
	}
	
};
