/**
* Содержит функции для отображения подсказок
*
* @package stockphoto
* @author Igor Palchik <viper@uptsoft.com>
* @copyright UPT Ltd 2007
* @version $Id: hint.js,v 1.11 2008/04/09 17:00:36 viper Exp $
*/

var x, y;
var stop = false;

try 
{ 
	//window.captureEvents(Event.MOUSEMOVE); 
} 
catch(e) 
{

}

function getPos(el)
{
	var r = { x: el.offsetLeft, y: el.offsetTop };
	if (el.offsetParent)
	{
		var tmp = getPos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}

function listenEvents(evt) 
{
	var fDisableElements = function(pElementName, pEnabled)
	{
		var arrayOfElements = document.getElementsByTagName(pElementName);
		if (arrayOfElements != 'undefined' && arrayOfElements != null)
		{
			for(var i = 0; i <= arrayOfElements.length; i++)
			{
				//alert(arrayOfElements[i].style);
				if (arrayOfElements[i] != 'undefined' && arrayOfElements[i] != null && arrayOfElements[i].style != 'undefined' && arrayOfElements[i].style != null)
				{
					arrayOfElements[i].style.visibility = (pEnabled == false)? 'hidden' : 'visible';
				}
			}
		}
	};
	if (stop) return;
	evt = (evt) ? evt : ((window.event) ? window.event : null);
	if (evt)
	{
		var el = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
		cn = document.getElementById('hint');
		
		if (el && cn)
		{
			//if (el.shape && /alt([01-9]+)/.test(el.id)) 

			if (/image([0-9]+)/.test(el.id)) 
			{
				Element.hide('exifInfo');
				box = document.getElementById('hint'+el.id.substr(5));

				box.height = Element.getHeight(box) + 20;
				box.width = 400 + 20; 
				if (evt.x)
				{
					x = evt.x;
					y = evt.y;
		
					if ((window.innerWidth && (x > window.innerWidth/2)) || (document.body.clientWidth && (x > document.body.clientWidth/2))) 
					{
						x = x - box.width;
					}
		
					if ((window.innerHeight && (y > window.innerHeight/2)) || (document.body.clientHeight && (y > document.body.clientHeight/2))) 
					{
						y = y - box.height;
					}
		
					if (window.pageXOffset || window.pageYOffset) 
					{
						x-= window.pageXOffset;
						y-= window.pageYOffset;
					}
					if (document.body.scrollTop)
					{
						x += document.body.scrollLeft;
						y += document.body.scrollTop;
					}
				}
				else if (evt.pageX)
				{
					x = evt.pageX;
					y = evt.pageY;
					if ((window.innerWidth && (x > window.innerWidth/2)) || (document.body.clientWidth && (x > document.body.clientWidth/2)))
					{
						x = x - box.width;
					}
					if ((window.innerHeight && (y > window.innerHeight/2)) || (document.body.clientHeight && (y > document.body.clientHeight/2))) {
						y = y - box.height;
					}
				}
				else if (evt.clientX)
				{
		
					dx = 0;
					x = evt.clientX;
					y = evt.clientY;
		
					if ((window.innerWidth && (x > window.innerWidth/2)) || (document.body.clientWidth && (x > document.body.clientWidth/2)))
					{
						x = x - box.width;
					}
		
					if ((window.innerHeight && (y > window.innerHeight/2)) || (document.body.clientHeight && (y > document.body.clientHeight/2)))
					{
						y = y - box.height;
					}
					if (window.pageXOffset || window.pageYOffset) 
					{
						x-= window.pageXOffset;
						y-= window.pageYOffset;
					}
					if (document.body.scrollTop)
					{
						x += document.body.scrollLeft;
						y += document.body.scrollTop;
					}
				}
				//box.style.visibility = 'visible';
				//cn.appendChild(box);
				//cn.innerHTML = "";
				//cn.innerText = "";
				//table = document.createElement('TABLE');
				//table.setAttribute('border', 1);
				//tr = document.createElement('TR');
				//td = document.createElement('TD');
				//td.innerHTML = 'test';
				//td.innerText = 'test';
				//tr.appendChild(td);
				//table.appendChild(tr);
				//cn.appendChild(table);
				cn.innerHTML = box.innerHTML;
				//box.style.visibility = 'hidden';
				cn.style.display = 'inline';
				cn.style.top  = y+10+'px';
				cn.style.left = x+10+'px';
				fDisableElements('select', false);
			}
 			else
 			{//box.style.visibility = 'hidden';
   				cn.style.display = 'none';
   				fDisableElements('select', true);
 			}
		}
			
			//if (document.getElementById('hint') == 'undefined' || document.getElementById('hint') == null)
   			
	}
}

document.onmousemove=listenEvents;