var timer = new Array;

var el = null;
var im = null;

var img_el = null;

var start_width = 160;
var start_height = 114;
	
var end_width = 700;
var end_height = 500;
	
var left_cur = null;
var top_cur = null;

var coords = null;

function stop()
{
	for (var i=0;i<timer.length;i++)
		window.clearTimeout(timer[i]);
}
function showIt(obj,link)
{
	if(im)
		return false;
		
	im = new Image();
	im.onload = operations;
	im.src = link;
	el = obj.firstChild;
}
function operations()
{
	scrolled = document.documentElement.scrollTop
	
	darkenPage();
	
	left_cur = getPosition(el).x;
	top_cur = getPosition(el).y;
	
	el.style.display = 'none';	
	
	img_el = document.createElement("img");
	img_el.id = "image";
	img_el.style.top = top_cur+"px";
	img_el.style.left = left_cur+"px";
	img_el.style.width = start_width+"px";
	img_el.style.height = start_height+"px";
	img_el.src = im.src;

	document.body.appendChild(img_el);
	coords = centerElCoords(img_el);
	
	action();
}
function action()
{	
	var box = new animation(img_el);
	box.addAnimation("top",top_cur,coords.y,1000,50,0);
	box.addAnimation("left",left_cur,coords.x,1000,50,0);
	delay = box.endframe;
	box.addAnimation("width",start_width,end_width,500,50,delay);
	box.addAnimation("left",coords.x,coords.x-(end_width-start_width)/2,500,50,delay);
	box.addAnimation("top",coords.y,coords.y-(end_height-start_height)/2,500,50,delay);
	box.addAnimation("height",start_height,end_height,500,50,delay);
	box.animate();

	delay = box.endframe;
	setTimeout(set,delay);
}
function set()
{
	img_el.onclick = hide;
	img_el.style.cursor = 'pointer';
}
function hide()
{
	img_el.onclick = null;
	
	var box = new animation(img_el);
	box.addAnimation("width",end_width,start_width,500,50,0);
	box.addAnimation("left",coords.x-(end_width-start_width)/2,coords.x,500,50,0);
	box.addAnimation("top",coords.y-(end_height-start_height)/2,coords.y,500,50,0);
	box.addAnimation("height",end_height,start_height,500,50,0);
	delay = box.endframe;
	box.addAnimation("top",coords.y,top_cur,1000,50,delay);
	box.addAnimation("left",coords.x,left_cur,1000,50,delay);
	box.animate();
	
	delay = box.endframe;
	setTimeout(rem,delay);
}
function rem()
{
	darkenPage();
	document.body.removeChild(img_el);
	el.style.display='block';
	im = null;
}
