/**
 * Latest 3 news-blocks, allow clicking to display the selected news-item.
 **/
function initNewsBlock() {
	$('news-tabs').getChildren().each(function(el){
		el.addEvent('click', function(){
			// Get position
			var pos = this.id.substring(this.id.length-1);
			
			var tabs = ['news-tab-1', 'news-tab-2', 'news-tab-3'];
			var images = ['image_1', 'image_2', 'image_3'];
			var texts = ['text_1', 'text_2', 'text_3'];
			
			// Make the image and text belonging to this item visible, and hide the others
			for (var i = 0; i < images.length; i++) {
				if ((i + 1) == pos) {
					$(images[i]).removeClass('not-visible');
				} else if (!$(images[i]).hasClass('not-visible')) {
					$(images[i]).addClass('not-visible');
				}
			}
			for (var i = 0; i < texts.length; i++) {
				if ((i + 1) == pos) {
					$(texts[i]).removeClass('not-visible');
				} else if (!$(texts[i]).hasClass('not-visible')) {
					$(texts[i]).addClass('not-visible');
				}
			}

			// Make the current item active, and the others inactive
			for (var i = 0; i < tabs.length; i++) {
				if ($(tabs[i]).hasClass('active')) {
					$(tabs[i]).removeClass('active');
				}
			}
			this.addClass('active');
		});
	});
}
window.addEvent('domready', initNewsBlock);
