/***************************************************************************
*
* IMPORTANT: This is a commercial product made by AntonLV and cannot be modified for other than personal usage. 
* This product cannot be redistributed for free or a fee without written permission from AntonLV. 
* This notice may not be removed from the source code.
*
***************************************************************************/

function inf_processInfo(oXML) {
	var sCaption = oXML.getElementsByTagName('items')[0].getAttribute('caption');
	var aNodes = oXML.getElementsByTagName('item');
	var oInformer = document.getElementById('informer');
	oInformer.innerHTML = "<div class=\"inf_ucell_header\">Quick informer: <span style=\"font-weight:bold\">" + sCaption + "</span></div>"; 
	for(var i=0; i<aNodes.length; i++)
		oInformer.innerHTML += "<div class=\"inf_ucell_left\">" + aNodes[i].getAttribute('caption') + "</div><div class=\"inf_ucell_right\">" + aNodes[i].firstChild.data + "</div>";	

	oInformer.style.width = 300 + 'px';
	oInformer.style.height = (29 * (aNodes.length + 1)) + 'px';
}

function inf_handleEvent(iId, sAction, oEvent) {
	oEvent = oEvent ? oEvent : window.event;
	var oInformer = document.getElementById('informer');	
	var aLocation = inf_getLocation(oInformer, oEvent);

	switch(sAction) {
		case 'in':
			inf_executeRequest('info', 'id=' + iId);
			oInformer.innerHTML = "<div class=\"inf_upreloader\">Looding...</div>";
			oInformer.style.width = 100 + 'px';
			oInformer.style.height = 100 + 'px';
			oInformer.style.display = 'block';			
		case 'move':
			oInformer.style.left = aLocation['left'] + 'px';			
			oInformer.style.top = aLocation['top'] + 'px';
			break;

		case 'out':
			oInformer.style.display = 'none';
			oInformer.style.width = 100 + 'px';
			oInformer.style.height = 100 + 'px';
			break;	
	}
	return true;
}

function inf_getLocation(oInformer, oEvent) {
	var iOffset = 10;
	var iPosX = 0, iPosY = 0;
	var iW = parseInt(oInformer.style.width), iH = parseInt(oInformer.style.height);
	var iScrollX = 0, iScrollY = 0;
	var iWindowW = 0, iWindowH = 0;
	
	//--- Calculate scroll location ---//
	if(document.body && (document.body.scrollTop || document.body.scrollLeft)) {
		iScrollX = document.body.scrollLeft;
		iScrollY = document.body.scrollTop;
	}
	else if(document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) {
		iScrollX = document.documentElement.scrollLeft;
		iScrollY = document.documentElement.scrollTop;
	}

	//--- Calculate window size ---//
	if(window.innerWidth && window.innerHeight) {
		iWindowW = window.innerWidth;
		iWindowH = window.innerHeight;
	}
	else if(document.documentElement && document.documentElement.clientWidth && document.documentElement.clientHeight) {
		iWindowW = document.documentElement.clientWidth;
		iWindowH = document.documentElement.clientHeight;
	}
	else if(document.body && document.body.clientWidth && document.body.clientHeight) {
		iWindowW = document.body.clientWidth;
		iWindowH = document.body.clientHeight;	
	}
	
	//--- Calculate location ---//
	if(typeof(oEvent.pageX) == 'number' && typeof(oEvent.pageY) == 'number') {
		iPosX = oEvent.pageX;
		iPosY = oEvent.pageY;
	}
	else if(typeof(oEvent.clientX) == 'number' && typeof(oEvent.clientY) == 'number') {
		iPosX = iScrollX + oEvent.clientX;
		iPosY = iScrollY + oEvent.clientY;					
	}	

	if(iPosX - iScrollX + iW > iWindowW) iPosX -= iW + iOffset; else iPosX += iOffset;
	if(iPosY - iScrollY + iH > iWindowH) iPosY -= iH + iOffset; else iPosY += iOffset;

	var aResult = new Array();
	aResult['left'] = 10 + iPosX;
	aResult['top'] = 10 + iPosY;

	return aResult;
}
