var OLGNewsLoad=Class.create();
var CurLoad=false;

OLGNewsLoad.prototype = {
	a:'',
	href:'',
	loading:loadingBar,
	loadingDiv:'',
	bgDiv:'',
	oldDiv:'',
	initialize:function(a){
		this.a=a;
		this.href=this.a.href;
		Event.observe(this.a,'click',this.initLoad.bindAsEventListener(this));
	},
	initLoad:function(e){
		if (CurLoad!=false){
			CurLoad.close();
		}
		this.mainDiv=Event.findElement(e,'div').parentNode;
		
		this.oldDiv=this.mainDiv.firstChild;
		var w=this.mainDiv.clientWidth;
		var h=this.mainDiv.clientHeight;
		var wh=this.mainDiv.getDimensions();
		
		var Mpos=Position.cumulativeOffset(this.mainDiv);
		this.loadingDiv=document.createElement('div');
		this.bgDiv=document.createElement('div');
		
		this.bgDiv.className='nwLoadBg';

		/*this.mainDiv.style.width=wh.width+'px';
		this.mainDiv.style.height=wh.height+'px';*/
		this.bgDiv.style.width=wh.width+'px';
		this.bgDiv.style.height=wh.height+'px';
		
		this.loadingDiv.style.left=(Mpos[0]+Math.round((wh.width/2)-(loadingBarWidth/2)))+'px';
		this.loadingDiv.style.top=(Mpos[1]+Math.round((wh.height/2)-(loadingBarHeight/2)))+'px';
		
		this.loadingDiv.className='nwLoad';
		this.loadingDiv.appendChild(this.loading);
		
		this.mainDiv.insertBefore(this.bgDiv,this.mainDiv.firstChild);
		this.mainDiv.insertBefore(this.loadingDiv,this.mainDiv.firstChild);
		CurLoad=this;
		new Ajax.Request(this.href,{method:'get',onSuccess:this.finishLoad.bind(this)});
		Event.stop(e);
	},
	finishLoad:function(tr){
		this.mainDiv.removeChild(this.loadingDiv);
		this.mainDiv.removeChild(this.oldDiv);
		this.bgDiv.className='nwLoadComp';
		this.bgDiv.style.height='';
		//this.bgDiv.style.border="1px sold #FFFFFF";
		this.bgDiv.innerHTML=tr.responseText;
		this.mainDiv.style.height='';
		//this.bgDiv.style.height='100px';
		
	},
	close:function(){
		this.mainDiv.removeChild(this.bgDiv);
		this.mainDiv.appendChild(this.oldDiv);
	}
}

function initNewsLoad(){
	nw = document.getElementsByClassName('nwOn');
	for(i = 0; i < nw.length; i++) {
		valid = new OLGNewsLoad(nw[i]);
	}
}

//Event.observe(window, 'load', initNewsLoad, false);
