function $(x) {
	return document.getElementById(x);
}
var news = {
	currentId: 0,
	ids: [],
	prev: function() {
		this.repl(-1);
	},
	next: function() {
		this.repl(1);
	},
	repl: function(cursor) {
		var replId = this.ids[this.indexOf(this.currentId) + cursor];

		// Update headline selection
		var curr = $('newsheadline'+this.currentId);
		var next = $('newsheadline'+replId);
		if(!next) {
			// Get the first or last element (depending on cursor)
			replId = this.ids[cursor > 0 ? 0 : (this.ids.length - 1)];
			next = $('newsheadline'+replId);
		}

		if(curr) curr.setAttribute('class', '');
		next.setAttribute('class', 'active');

		// Update content
		var curr_cnt = $('newsitem'+this.currentId);
		var next_cnt = $('newsitem'+replId);
		if(curr_cnt) curr_cnt.style.display = 'none';
		if(next_cnt) next_cnt.style.display = 'block';

		// Update state
		this.currentId = replId;
	},
	show: function(id) {
		// Update headline selection
		var curr = $('newsheadline'+this.currentId);
		var next = $('newsheadline'+id);
		if(curr) curr.setAttribute('class', '');
		if(next) next.setAttribute('class', 'active');

		// Update content
		var curr_cnt = $('newsitem'+this.currentId);
		var next_cnt = $('newsitem'+id);
		if(curr_cnt) curr_cnt.style.display = 'none';
		if(next_cnt) next_cnt.style.display = 'block';

		// Update state
		this.currentId = id;
	},
	// Used for compatibility with IE (and JSON conformity)
	indexOf: function(id) {
		var i = 0;
		for(var s in this.ids) {
			if(this.ids[i] == id) return i;
			i++;
		}
		return -1;
	}
}
