var NewsUpDown = Class.create(
{
	upbtn: null,
	downbtn: null,
	pageid: 1,
	numperpage: 3,
	initialize: function(upbtn, downbtn)
	{
		this.upbtn = $(upbtn);
		this.downbtn = $(downbtn);
		this.upbtn.observe('click', this.onUpClick.bindAsEventListener(this));
		this.downbtn.observe('click', this.onDownClick.bindAsEventListener(this));
	},
	onUpClick : function(e)
	{
		if (this.pageid > 1)
		{
			this.pageid--;
		}
		
		var options = 
			{
				method : 'post',
				//parameters: 'pageid=' + this.pageid + '&' + 'numperpage=' + this.numperpage,
				parameters: $H({pageid: this.pageid, numperpage: this.numperpage}).toQueryString(),
				onSuccess: this.onSucc.bind(this)
			};
		new Ajax.Request('/index/getnews', options);
	},
	onDownClick: function(e)
	{
		this.pageid++;
		var options = 
			{
				method : 'post',
				parameters: $H({pageid: this.pageid, numperpage: this.numperpage}).toQueryString(),
				onSuccess: this.onSucc.bind(this)
			};
		new Ajax.Request('/index/getnews', options);
	},
	onSucc: function(transport)
	{
		var json = transport.responseText.evalJSON(true);
		this.pageid = json.pageid;
		var news = json.news;
		var array_story = $('news_content').getElementsByClassName('story');
		for (var i = 0; i < array_story.length; i++)
		{
			if ( i >= news.length )
			{
				array_story[i].hide();
			}
			else
			{
				
				array_story[i].getElementsByClassName('title')[0].update(news[i]['title']);
				array_story[i].getElementsByClassName('date')[0].update(news[i]['ts_toshow']);
				array_story[i].getElementsByClassName('content')[0].update(news[i]['content']);
				array_story[i].show();
			}
		}
		//news.each (function(pair){alert(pair.key + pair.value);});
	}
}
);
