
function scroll_news(id_scroll_block, count_show_news)
{
	this.id_scroll_block = id_scroll_block;
	this.count_show_news = count_show_news;
	this.scroll_block = document.getElementById(this.id_scroll_block);
	this.current_news = $('#' + id_scroll_block + ' div')[0]; //this.scroll_block.childNodes[0];

	this.button_top = 0;
	this.button_down = 0;

	this.setHeight();
	this.button();
}


with(scroll_news){
	prototype.getHeight = function() {
		height = 0;
		if (this.current_news)
		height = this.current_news.offsetHeight;



		//tmp = this.current_news.nextSibling;
		tmp = $(this.current_news).next()[0];
		i = this.count_show_news;

		while (tmp && --i) {
			height += tmp.offsetHeight + 15;
			//tmp = tmp.nextSibling;
			tmp = $(tmp).next()[0];
		}

		return height;
	}

	prototype.setHeight = function() {
		$(".scroll_news").animate({"height": this.getHeight() + 'px'}, 500);
	}

	prototype.toScroll = function(direction) {
		scroll_height = 0;
		if (direction == 'top' && this.button_top) {

			tmp = this.current_news.previousSibling;
			if (tmp) {
				i = this.count_show_news;
				while (tmp && --i) {
					tmp = tmp.previousSibling;
				}
				this.current_news = tmp;
			}
			scroll_height = this.getHeight() + 15;
		}

		if (direction == 'down' && this.button_down) {
			scroll_height = this.getHeight() + 15;

			tmp = this.current_news.nextSibling;
			if (tmp) {
				i = this.count_show_news;
				while (tmp && --i) {
					tmp = tmp.nextSibling;
				}
				this.current_news = tmp;
			}

			scroll_height = -scroll_height;
		}

		if (scroll_height) {
			this.button();
			if (this.scroll_block.style.marginTop == '') {
				this.scroll_block.style.marginTop = '0px';
			}
			new_marginTop = (parseInt(this.scroll_block.style.marginTop) + scroll_height) + 'px';
			$("." + this.id_scroll_block).animate({"marginTop": new_marginTop}, 1000);
			this.setHeight();
		}
	}


	prototype.button = function() {
		if (this.current_news.previousSibling) {
			this.button_top = 1;
			document.getElementById('scroll_news_button_top').style.background = 'url(/img/scroll/top.gif) no-repeat';
			document.getElementById('scroll_news_button_top').style.cursor = 'pointer';
		} else {
			this.button_top = 0;
			document.getElementById('scroll_news_button_top').style.background = 'url(/img/scroll/top_no.gif) no-repeat';
			document.getElementById('scroll_news_button_top').style.cursor = 'default';
		}

		if (this.current_news.nextSibling && this.current_news.nextSibling.nextSibling && this.current_news.nextSibling.nextSibling.nextSibling) {
			this.button_down = 1;
			document.getElementById('scroll_news_button_down').style.background = 'url(/img/scroll/down.gif) no-repeat';
			document.getElementById('scroll_news_button_down').style.cursor = 'pointer';
		} else {
			this.button_down = 0;
			document.getElementById('scroll_news_button_down').style.background = 'url(/img/scroll/down_no.gif) no-repeat';
			document.getElementById('scroll_news_button_down').style.cursor = 'default';
		}
	}
	prototype.button_hover = function(direction) {
		if (direction == 'top' && this.button_top) {
			document.getElementById('scroll_news_button_top').style.background = 'url(/img/scroll/top_act.gif) no-repeat';
		}
		if (direction == 'down' && this.button_down) {
			document.getElementById('scroll_news_button_down').style.background = 'url(/img/scroll/down_act.gif) no-repeat';
		}
	}
}
