var BelinkGlossary = {
	loading: false,
	isShow: false,
	idCurrent: null,
	positionLeft: '',
	positionTop: '',

	show: function (event, url, id){
		event = Event.extend(event);
		if(BelinkGlossary.isShow){
			return;
		}
		BelinkGlossary.positionLeft = event.pointerX()+'px';
		BelinkGlossary.positionTop = event.pointerY()+'px';
		BelinkGlossary.idCurrent = id;

		if($(id+'_word') == undefined){
			BelinkGlossary.send(url);
		} else{
			$(id+'_word').setStyle({
				left: event.pointerX()+'px',
				top: event.pointerY()+'px'
			});
			$(id+'_word').show();
		}
	},

	send: function (url) {
		//*** Prevents multiple submit
		if(!BelinkGlossary.loading){
			//** Set flag
			BelinkGlossary.loading = true;


			//** Launch request
			new Ajax.Request(url, {
				method: 'get',
				onComplete: BelinkGlossary.onCompleteCallback
			});
		}
	},
	
	onCompleteCallback: function (transport) {
		if(200 == transport.status){
			divCreated = $(document.createElement('DIV'));
			divCreated.addClassName('popup');
			divCreated.id = BelinkGlossary.idCurrent+'_word';
			divCreated.setStyle({
				left: BelinkGlossary.positionLeft,
				top: BelinkGlossary.positionTop
			});
			divCreated.show();
			divCreated.update(transport.responseText);

			// Append it in the DOM tree
			document.body.appendChild(divCreated);
		}
		BelinkGlossary.loading = false;
	},

	hide: function (id){
		if($(id+'_word') != null){
			$(id+'_word').hide();
			BelinkGlossary.isShow = false;	
		}
	}
}
