// ******************************
// **                          **
// **      xbo - xom`s box     **
// **                          **
// ** javascript image preview **
// **  (c) Tom Hnatovsky 2006  **
// **       www.xomax.cz       **
// **                          **
// ** 27.10.2008               **
// ** PAPOUCH - uprava pres    **
// **           nahledu pres   **
// **           parametr title **
// ******************************


// ----------- Global variables ------------ //
var win;
var len;
var isIE=(document.all && !window.opera)?true:false;
var isOpera=(navigator.userAgent.indexOf("Opera")!=-1)?true:false;


// ----------- Settings ------------ //
var settings = new Array;


// ----------- xbo Functions ------------ //
function xboSetIT () 
{
	if (settings["windowID"]) 
		{
		win = document.getElementById(settings["windowID"]);
		}
		else 
	{
	win = document.createElement('DIV');
	if (settings["class"])
		{
		win.className = settings["class"];
		}
	else 
		{
		settings["classDefault"] = "position:absolute; border: 1px solid #bbb; background: #fbfbfb; padding: 5px; font-size: 80%; font-family: sans-serif;min-height:30px;text-align:center;";
		if (isOpera)
			{
			win.style = settings["classDefault"];
			}
		else 
			{
			win.style.cssText = settings["classDefault"];
			}
		}
		win.style.display = "none";
	}
	var a = document.getElementsByTagName("a");
	for (var i=0;i<a.length;i++)
		{
		if ((a[i].title.search(/.jpg/g)!=-1||a[i].title.search(/.JPG/g)!=-1)&&settings["image"])
			{
			if ((settings["elementName"] && settings["elementName"]==a[i].className)||!settings["elementName"]) 
				{
				if (settings["action"]=="click") 
					{
					if (isIE) 
						{
						a[i].onclick=function () 
							{
							return xboShowIT(this);
							}
						}
					else 
						{
						a[i].setAttribute("onclick", "xboShowIT(this); return false;");
						}
					}
				else 
					{
					if (isIE) 
						{
						a[i].onmousemove=function () 
							{
							xboShowIT(this);
							}
						}
					else 
						{
						a[i].setAttribute("onmousemove", "xboShowIT(this)");
						}
					if (settings["hide"]) 
						{
						if (isIE) 
							{
							a[i].onmouseout=function ()
								{
								xboHideIT(this);
								}
							}
						else 
							{
							a[i].setAttribute("onmouseout", "xboHideIT()");}
							}
						}
					}
			}
		}
	if (!settings["template"]||settings["template"].search(/<img/g) == -1) 
		{
		settings["template"]='<img src="%title%"/>';
		}
	if (!settings["windowID"]) 
		{
		document.getElementsByTagName('BODY')[0].appendChild(win);
		}
}

function xboShowIT (e) 
	{
	var r = settings["template"].replace(/%title%/g, e.getAttribute("title"));
	r = r.replace(/%href%/g, e.getAttribute("title"));
	r = r.replace(/%src%/g, e.getAttribute("title"));
	win.innerHTML = r;
	var t = win.getElementsByTagName('IMG');
	var width = t[0].offsetWidth+10;
	if (isIE) 
		{t[0].onload = xboVisiIT;}
	else 
		{t[0].onload = xboVisiIT();}
	win.style.width = width+"px";
	if (settings["autoPosition"]) 
		{
		win.style.left=e.offsetLeft+"px";
		if (isIE) 
			{win.style.top = e.offsetTop+e.offsetHeight+17+"px";}
		else 
			{win.style.top=e.offsetTop+e.offsetHeight+"px";}
		}
	else 
		if (settings["relativePosition"]) 
			{
			if (isIE) 
				{
				win.style.left=document.documentElement.scrollLeft+settings["relativePositionX"]+"px";
				win.style.top = document.documentElement.scrollTop+settings["relativePositionY"]+"px";
				}
			else
		 		{
				win.style.left=window.pageXOffset+settings["relativePositionX"]+"px";
				win.style.top=window.pageYOffset+settings["relativePositionY"]+"px";
				}
			}
	return false;
	}
function xboHideIT () {win.style.display = 'none';}
function xboVisiIT () {win.style.display = "block";}

// ----------- xbo Activation ------------ //
if (isIE) {window.attachEvent('onload',xboSetIT);}else {window.addEventListener('load',xboSetIT, false);}
