var tmr;
var t;
var obj;

function openpopup() {
	obj = gObj();
	sLft();
	shw(true);
	t = 0;
	sTmr();
}

function closepopup() {
	t = -100;
	sTmr();
	document.getElementById("divimg").style.display='none';
	return false;
}

function sTmr() {
	tmr = setInterval("fd()",20);
}

function fd() {
	var amt = Math.abs(t+=10);
	if(amt == 0 || amt == 100) clearInterval(tmr);
	amt = (amt == 100)?99.999:amt;
  	
	obj.style.filter = "alpha(opacity:"+amt+")";
	obj.style.KHTMLOpacity = amt/100;
	obj.style.MozOpacity = amt/100;
	obj.style.opacity = amt/100;
	
	if(amt == 0) shw(false);
}

function sLft() {
	var w = 160;	// set this to 1/2 the width of the 'fa' div defined in the style sheet 
			// there's not a reliable way to retrieve an element's width via javascript!!
					
	var l = (document.body.innerWidth)? document.body.innerWidth / 2:document.body.offsetWidth / 2;

	obj.style.left = (l - w)+"px";
}

function gObj() {
	return document.getElementById("fa");
}

function shw(b) {
	(b)? obj.className = 'show':obj.className = '';	
}


/*-------*/

var whichImage;
var timerid;

function replace_img()
{
    if (load_img.complete)
    {
        //document.getElementById("loading").style.display='none';
        document['target_img'].src = load_img.src;
        clearInterval(timerid);
    }
}

function GetFullImage(e, LowQimgPath, FullQimgPath)
{
document.getElementById("divimg").style.display='block';
    document['target_img'].src = LowQimgPath;
    
    if(FullQimgPath == "StopLoading")
    {
        // DO NOT DELETE THIS LINE!
    }
    else if(whichImage != FullQimgPath)
    {
        whichImage = FullQimgPath;
        //Full size quality image
        load_img = new Image();
        load_img.src = FullQimgPath;
        timerid = setInterval("replace_img()", 500);
        
        // Begin - Get mouse coordinates relative to the document
        var posx = 0;
        var posy = 0;
        if (!e) var e = window.event;
        if (e.pageX || e.pageY)
        {
            posx = e.pageX;
            posy = e.pageY;
        }
        else if (e.clientX || e.clientY)
        {
            posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
            posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
        }
        // End - Get mouse coordinates relative to the document

        //document.getElementById("fa").style.top = posy-50;
        //document.getElementById("fa").style.left = posx;

        document.getElementById("fa").style.top = posy-340;
        document.getElementById("fa").style.left = document.body.scrollTop + document.documentElement.scrollTop;
    }
}


function changeimg(img){
	document.getElementById("bigimg").innerHTML="<img src='"+img+"' />";
}
