//initate the control div
document.write('<style>');
document.write('#dl_popup_imageloader{');
document.write('padding:30px 20px 20px 20px;');
document.write('border:2px solid black;');
document.write('background-color:white;');
document.write('display:none;');
document.write('position:absolute;');
document.write('z-index:1000;');
document.write("background-image:url('close.jpg');");
document.write('background-repeat:no-repeat;');
document.write('background-position:top;');
document.write('cursor:pointer;');
document.write('}</style>');
document.write('<img style="display:none;" onload="dl_popup_animate_img(this);" id="dl_popup_img_src" src="" />');
document.write('<div align="center" onclick="dl_popup_hide();" id="dl_popup_imageloader">');
document.write('<img id="dl_popup_img" src="loader.gif" /></div>');

var screenY,screenX;
screenY = document.body.offsetHeight;
screenX = document.body.offsetWidth;
var window_time_interval;
var scrollerPosition;
	
function dl_popup_show(val){
    try
    {
        scrollerPosition = document.body.parentElement.scrollTop;
    }
    catch(err)
    {
        scrollerPosition = window.pageYOffset;
    }
	dl_popup_hide();
	var obj;
	screenY = document.body.offsetHeight;
	screenX = document.body.offsetWidth;
	
	obj = document.getElementById('dl_popup_imageloader');
	obj.style.top = 0;//screenY/2 + "px";
	obj.style.left = screenX/2 + "px";
	obj.style.display = "block";
	document.getElementById('dl_popup_img').src = "loader.gif";
	obj.style.width = document.getElementById('dl_popup_img').width + "px";
	obj.style.height = document.getElementById('dl_popup_img').height + "px";
	//load the image
	document.getElementById('dl_popup_img_src').src = val;
}

function dl_popup_hide(){
	var obj, obj2, obj3;
	obj = document.getElementById('dl_popup_imageloader');
	obj2 = document.getElementById('dl_popup_img');
	obj3 = document.getElementById('dl_popup_img_src');
	obj.style.display = "none";
	obj2.src = "loader.gif";
	obj2.style.display = "block";
	obj3.src = "";
	obj.style.top = screenY/2 + "px";
	obj.style.left = screenX/2 + "px";
	obj.style.width = obj2.width + "px";
	obj.style.height = obj2.height + "px";
	window.clearInterval(window_time_interval);
	try
    {
        document.body.parentElement.scrollTop = scrollerPosition;
    }
    catch(err)
    {
	    window.scroll(0,scrollerPosition);
    }
}

function dl_popup_animate_img(obj3){
	var obj;
	var img_width, img_height;
	var obj2;
	obj2 = document.getElementById('dl_popup_imageloader');
	obj = document.getElementById('dl_popup_img');
	obj.style.display = "none";
	//get image details and hide the image (this is the temp image)
	obj3.style.display = "block";
	img_width = obj3.width;
	img_height = obj3.height;
	obj3.style.display = "none";
	
	//call animation to animate the div openning up 
	obj2.style.width = obj.width + "px";
	obj2.style.height = obj.width + "px";
	window_time_interval = window.setTimeout(function () { animate_div_stretch(obj,obj2,obj3);},2);
}

function animate_div_stretch(img,div,orig_img){
	var chktst;
	chktst = false;
	var speed_width, speed_height;
	
	//animate width
	if(orig_img.width>(div.style.width.replace("px","")-0))
	{
		chktst = true;
		speed_width = orig_img.width-(div.style.width.replace("px","")-0);
		if(speed_width<10)
		{
			speed_width = 1; 
		}
		else
		{
			speed_width = 20;
		}
		div.style.width = ((div.style.width.replace("px","")-0) + speed_width) + "px";
		//animate left align
		if(div.style.left.replace("px","")>0)
		{
			div.style.left = ((div.style.left.replace("px","")-0) - speed_width/2) + "px";
		}
		else
		{
			div.style.left = "0px";
		}
	}
	
	//animate height
	if(orig_img.height>(div.style.height.replace("px","")-0))
	{
		chktst = true;
		speed_height = orig_img.height-(div.style.height.replace("px","")-0);
		if(speed_height<10)
		{
			speed_height = 1; 
		}
		else
		{
			speed_height = 20;
		}
		div.style.height = ((div.style.height.replace("px","")-0) + speed_height) + "px";
		//animate top align
		if(div.style.top.replace("px","")>100)
		{
			div.style.top = ((div.style.top.replace("px","")-0) - speed_height/2) + "px";
		}
		else
		{
			div.style.top = "100px";
		}
	}
	
	if(chktst)
	{
		window_time_interval = window.setTimeout(function () { animate_div_stretch(img,div,orig_img);},2);
	}
	else
	{
		div.style.width = orig_img.width + "px";
		div.style.height = orig_img.height + "px";
		window.clearInterval(window_time_interval);
		img.src = orig_img.src;
		img.style.display = "block";
		orig_img.src = "";	
	}
}