/*
* News
* @Author: Alexander Gavazov
* @Site: www.studio.bg
*/


var News = function(details, list) {
	this.details = details;
	this.list = list;

	this.lastNews = null;
	this.firstIsShowed = false;

	this.setBehaviour();
}


News.prototype.setBehaviour = function() {
	this.details.select('.news').each(function(node) {
		node.setOpacity(0);
		node.hide();
	});

	this.list.select('a').each(function(node) {
		node.observe('click', Event.stop);
		node.observe('click', this.showNews.bind(this, node));

		// Show first
		if (!this.firstIsShowed) {
			this.showNews(node);
			this.firstIsShowed = true;
		}
	}.bind(this));
}


News.prototype.showNews = function(node) {
	var news = $(node.href.replace(/.*#/gi, ''));

	if (this.lastNews) {
		this.hide(this.lastNews, this.lastNews.link);
	}

	this.show(news, node);

	this.lastNews = news;
	this.lastNews.link = node;
}


News.prototype.hide = function(node, link) {
	node.setOpacity(0);
	node.hide();

	link.removeClassName('active');
}


News.prototype.show = function(node, link) {
	node.show();
	new Effect.Opacity(node, {to: 1, from: 0, duration: .8});

	link.addClassName('active');

	this.fixScroll();

	$('scroll_conatiner').style.top = 0;
}


News.prototype.fixScroll = function() {
	setScroll();
	$('scrollbar').style.left = '485px';
	$('scrollbar').style.top = '0';
	$('scroll_conatiner').style.top = '0';
}