
function myGoodPreviewer(sName)
{
var gp = this;
var 
goodPreview	= document.getElementById('goodPreview')
,loading	= document.getElementById('loading')
,placeholder 	= document.getElementById('placeholder');
var maxsize 	= 500;

gp.previewed 	= "";	// list of already loaded and previewed images


gp.images = document.getElementsByName(sName);

gp.show = function(argEvent)
{
//goodPreview.src = '/images/ui/loading.gif';

	try {
	argEvent.type;
	event = argEvent;
	}
	catch(e4){}

var smallimg = event.srcElement?event.srcElement:event.target;

gp.currentSmallImage = smallimg;

/*
gp.currentSmallImage.style.cursor = 
document.body.style.cursor = "wait";
*/
loading.style.visibility = 'visible';





var aspect_ratio 	= smallimg.height/smallimg.width; 

	if (smallimg.height>=smallimg.width)
	{
	goodPreview.height = maxsize;
	goodPreview.width  = maxsize/aspect_ratio;
	}
	else
	{
	goodPreview.width  = maxsize;
	goodPreview.height = maxsize*aspect_ratio;
	}

goodPreview.src = smallimg.src;
//var isPreviewedNow = gp.isPreviewed(smallimg.src);


var bigImageUrl = smallimg.src.replace("small_", '');

	if (gp.isPreviewed(smallimg.src))
	{
	goodPreview.src = 
	gp.bigSrc = 
	bigImageUrl;
	}
	else
	{
	gp.previewed += smallimg.src + "\n";

	var bigImage = new Image();
	bigImage.src = smallimg.src.replace("small_", '');
	bigImage.onload = function()
		{
		goodPreview.src = 
		gp.bigSrc = 
		this.src;
		bigImage = null;
		};
	
	}



/*
goodPreview.src = 
gp.bigSrc = 
smallimg.src.replace("small_", '');
*/


var pos = getElementPosition(document.getElementById(smallimg.id));
//alert(pos.x)
placeholder.style.top = document.body.scrollTop+10;
placeholder.style.left =  pos.x + smallimg.clientWidth - 10;
	if (gp.hideTimer)
	{
	clearTimeout(gp.hideTimer);
	}
changeOpac(0, placeholder.id);
placeholder.style.display = 'block';
opacity(placeholder.id, 0, 100, 200); 
}


gp.hide = function()
{
/*
gp.currentSmallImage.style.cursor = 
document.body.style.cursor = "auto";
*/
loading.style.visibility = 'hidden';

gp.currentSmallImage = false;


opacity(placeholder.id, 100, 0, 200); 

gp.hideTimer = setTimeout(function()
{
placeholder.style.display = 'none';
}, 210);

//goodPreview.src = '/images/strut.gif'
/*
goodPreview.src = '/images/ui/loading.gif';
everything hovered is guaranteed loaded
*/
}

gp.isPreviewed = function(sUrl)
{
return gp.previewed.indexOf(sUrl+'\n')!=-1;
}

gp.imageOnload = function()
{

if (goodPreview.src==gp.bigSrc)
{
/*
gp.currentSmallImage.style.cursor = 
document.body.style.cursor = "auto";
*/
loading.style.visibility = 'hidden';

}

}

var s= '';

	for (i=0, maxi=gp.images.length; i<maxi; i++)
	{
	var image1 = gp.images.item(i);

		if (image1.id)
		{
		EventManager.Add(image1.id, "mouseover", gp.show);
		EventManager.Add(image1.id, "mouseout", gp.hide);
		
		}
	s+=		image1.id + '\n';

	}
//alert(s);
EventManager.Add("goodPreview", "load", gp.imageOnload);
}



