function FindX(obj)
{
	var curleft = 0;
	
	if (obj.offsetParent)
		while (obj.offsetParent) { curleft += obj.offsetLeft; obj = obj.offsetParent; }
	else if (obj.x)
		curleft += obj.x;
		
	return curleft;
}

function FindY(obj)
{
	var curtop = 0;
	
	if (obj.offsetParent)
		while (obj.offsetParent) { curtop += obj.offsetTop; obj = obj.offsetParent; }
	else if (obj.y)
		curtop += obj.y;

	return curtop;
}

function ProcessPhotoLinks(listid)
{
	var loading = new Image();
	loading.src = 'img/loading.gif';

	var l = document.getElementById(listid).getElementsByTagName('a');
	
	var pos = (listid == 'confirmshop') ? 2 : 1;
	
	for(var x=0; x<l.length; x++)
	{
		l[x].onmouseover = function() { ShowPhoto(this, eval(pos)); }
		l[x].onmouseout = function() { ClosePhoto(this, eval(pos)); }
	}
}

function Photo(src, w, h)
{
	this.Src = src;
	this.Width = w;
	this.Height = h;
}

var photos = new Array();

var open = '';

function ClosePhoto(o)
{
	var x = document.getElementById('photoviewer');
	x.style.display = 'none';
	
	open = '';
}

function SetViewerPosition(position)
{
	var arrow = document.getElementById('photoviewer');
	var loader = document.getElementById('photoloader');
	
	switch(position)
	{
		case 1: // Arrow bottom left (DEFAULT)
			arrow.style.backgroundImage = 'url(img/arrow_bl.gif)';
			arrow.style.backgroundPosition = 'left bottom';
			loader.style.marginTop = '0';
			loader.style.marginBottom = '25px';
			loader.style.marginLeft = '25px';
			loader.style.marginRight = '0';
			break;
		case 2: // Arrow bottom right
			arrow.style.backgroundImage = 'url(img/arrow_br.gif)';
			arrow.style.backgroundPosition = 'right bottom';
			loader.style.marginTop = '0';
			loader.style.marginBottom = '25px';
			loader.style.marginLeft = '0';
			loader.style.marginRight = '25px';
			break;
	}
}

function ShowPhoto(o, pos)
{	
	var id = o.id.split('_')[1];
		
	if(open != id)
	{
		var newX = (pos == 1) ? FindX(o) + 142 : FindX(o) - 285;
		var newY = FindY(o) - (photos[id].Height - 5);
		
		SetViewerPosition(pos); 
			
		var z = document.getElementById('photo');	
		z.src = 'img/blank.gif';

		var x = document.getElementById('photoviewer');
		x.style.top = newY + 'px';
		x.style.left = newX + 'px';
		x.style.display = 'block';
		
		var y = document.getElementById('photoloader');
		y.width = photos[id].Width;
		y.height = photos[id].Height;
			
		z.width = photos[id].Width;
		z.height = photos[id].Height;
		z.src = photos[id].Src;
		
		open = id;
	}
	else
	{
		ClosePhoto(o);
	}
}