function News(){	
	var _this=this;
	this.ListContainerDiv=document.createElement('DIV');
	
	this.PrevButtonDiv=document.createElement('DIV');
	this.PrevButtonDiv.innerHTML="<center><img src='Images/upbw.gif' style='padding-bottom:3px;' /></center>";
	this.PrevButtonDiv.onclick=function(){		
		if (_this.Page==0)
			return;
		if (_this.Page==1)
			_this.PrevButtonDiv.innerHTML="<center><img src='Images/upbw.gif' style='padding-bottom:3px;' /></center>";
		
		_this.NextButtonDiv.innerHTML="<center><img src='Images/down.gif' style='padding-bottom:3px;' /></center>";
		_this.LoadNewsList(_this.Page-1,_this.SortBy, _this.Lang);
	}
	
	this.NextButtonDiv=document.createElement('DIV');
	this.NextButtonDiv.innerHTML="<center><img src='Images/downbw.gif' /></center>";	
	this.NextButtonDiv.onclick=function(){			
		if (_this.Count<=_this.NewsPerPage*(_this.Page+1))		
			return;
		if (_this.Count<=_this.NewsPerPage*(_this.Page+2))
			_this.NextButtonDiv.innerHTML="<center><img src='Images/downbw.gif' style='padding-bottom:3px;' /></center>";
			
		_this.PrevButtonDiv.innerHTML="<center><img src='Images/up.gif' style='padding-bottom:3px;' /></center>";
		_this.LoadNewsList(_this.Page+1,_this.SortBy, _this.Lang);
	}
	
	this.StyledDiv=document.createElement('DIV');
	this.StyledDiv.className="shaded_div";
	
	this.StyledDiv.appendChild(this.PrevButtonDiv);
	this.StyledDiv.appendChild(this.ListContainerDiv);
	this.StyledDiv.appendChild(this.NextButtonDiv);
	
	this.newsList=null;
	
	this.ListDOMObject=this.StyledDiv;
	this.DOMObject=document.createElement('DIV');
	
	this.Page=0;	
	this.SortBy="date";
	this.Lang="arm";
	this.Count=-1;	
	this.NewsPerPage=5;
}

News.prototype={

	LoadNewsList: function(page, sortBy, lang){		
		this.Page=page;
		this.SortBy=sortBy;
		this.Lang=lang;
		if (this.Count==-1)
			AjaxEngine.sendGETRequest("ajaxControl.php?action=getNewsCount&lang="+this.Lang, this.newsCount_loader, 0, this);
			
		AjaxEngine.sendGETRequest("ajaxControl.php?action=getNewsList&page="+page+"&sortBy="+sortBy+
			"&lang="+lang, this.newsList_loader, 0, this);
	},

	LoadNews: function(id, lang){				
		AjaxEngine.sendGETRequest("ajaxControl.php?action=getNews&id="+id+"&lang="+lang, this.news_loader, 0, this);
	},

	newsList_loader: function (xmlHttp, _this){	
		_this.newsList=eval('('+xmlHttp.responseText+')');
		_this.ListContainerDiv.innerHTML="";
		//var newsDiv=document.createElement('DIV');	
		//newsDiv.className="shaded_div";
		
		var div;
		var str;
		
		if (_this.newsList.length==0)
			return;
		var i;
		for (i=0;i<_this.newsList.length;i++){
			div=document.createElement('DIV');
			div.className="news";
			//{id,title,description,date,popularity,lang
			str="<strong>"+_this.newsList[i]['date']+" "+_this.newsList[i]['title']+"</strong><br />";
			str+="<a href=\"#/news/"+_this.newsList[i]['id']+"\" >";
			str+=_this.newsList[i]['description']+"</a><p />";
			div.innerHTML=str;

			_this.ListContainerDiv.appendChild(div);
		}
		//News.ListHolder.appendChild(newsDiv);
	},

	news_loader: function (xmlHttp, _this){	
		_this.DOMObject.innerHTML=xmlHttp.responseText;	
	},
	newsCount_loader: function (xmlHttp, _this){	
		_this.Count=parseInt(xmlHttp.responseText);	
		if (_this.Count>_this.NewsPerPage)
			_this.NextButtonDiv.innerHTML="<center><img src='Images/down.gif' /></center>";
	}	
}

