JABA.translation = {
	container : null,
	blocks : null,      
	msgErrorBox : null,
	msgNoticeBox : null,        
	init : function( container, blocks ) {
		this.container = $( container );
		this.blocks = blocks || {};
		this.msgErrorBox = new Roar({
			position: 'upperRight',
			className: 'roar-error',
			margin: {x: 30, y: 10}
		});
		this.msgNoticeBox = new Roar({
			position: 'upperRight',
			className: 'roar-notice',
			margin: {x: 30, y: 10}    
		});
		this.container.set('html','');
		for( i in this.blocks ){
			this.get(this.blocks[i]);
		}
		
	},
	get : function( block ){
		this.showStatus( block );
		JsHttpRequest.query(
			block.url,
			{},
			function(result, errors) { 
				JABA.translation.onLoad( result, errors, block );
			},
			true
		);
	},
	onLoad: function( result, errors, block ){
		if (!result) {
			this.msgErrorBox.alert('Error','Please try again later');           
		} else {
			if (result.bStateError) {
			} else {
                var title = '<h3>'+block.title+'</h3>';
				$(block.container).set('html', title + result.sText);
				if( typeof( block.onContentLoad ) == 'function' ){
					block.onContentLoad( result, block );
				}
			}      
		}
	},
	showStatus : function(block){
		var newDiv = new Element('div');
		//newDiv.setStyle('text-align','center');
		newDiv.set({
			'id' : block.container,
			'class' : 'block stream translationblock',
			'html' : '<img src="'+DIR_STATIC_ROOT+'/images/loader.gif" >'
		});
		newDiv.inject(this.container);
	}
}

JABA.addInitialiser( function(){
	JABA.translation.init( 'translation', {
		self : { 
			url : 'http://www.jaba.ru/include/ajax/stream_topic_jaba.php', 
			container : 'translationself',
			title: 'JABA'
		},
		social : { 
			url : 'http://www.social.jaba.ru/include/ajax/stream_topic_jaba.php	', 
			container : 'translationsocial',
			title: 'JABA SOCIAL'
		},  
		ego : { 
			url : 'http://www.ego.jaba.ru/include/ajax/stream_topic_jaba.php', 
			container : 'translationego',
			title: 'JABA EGO'
		}
	});
});
