var pleft = 0;
var ptop = 0;
var incr = 0;
var id_pic = 0;
var bwidth = 0;
var show = 1;
var pic = null;
var bpic = null;


// Подгрузка middle-картинок в списке
function showpicture(prefix, id, pos, mwidth, mheight, file_img, pic_path, domain) 
{
	host = "http://www."+domain+"/"+pic_path;
	host_url = "http://"+domain+"/";
	img_small = host+"small/"+file_img+".jpg";
	img_big	= host+"middle/"+file_img+".jpg";
	url = host_url+"picture.php?id_picture="+id;
        //размеры до которых увеличиваем фотки
	bw = 300;
	bh = 431;
        proto_showpicture(prefix+id, bw, bh, pos, mwidth, mheight, img_small, img_big, url, "bigpic", prefix);
}

function proto_showpicture(id, bw, bh, pos, mwidth, mheight, img_small, img_big, url, pic_divname) 
{


		id_pic = id;
		bwidth = bw;
		if (mwidth<mheight) { bwidth = Math.round(bh*mwidth/mheight);}
		
		picturediv = document.getElementById(pic_divname);
		pic_href = url;
	
		pleft = pos.x;
		ptop = pos.y;
		if (navigator.userAgent.indexOf("MSIE 7.0")!=-1) { pleft -= 11; }
		picturediv.style.left = pleft + 'px';
		picturediv.style.top = ptop + 'px';
		sm_src = img_small;
		//picturediv.innerHTML = "<div onmouseout='hidepicture()' onmousemove='show=1'><a href='" + pic_href + "'><img border='0' id='"+id_pic+"' src='"+sm_src+"''></a></div>";
		picturediv.innerHTML = "<div onmouseout='hidepicture()' onmousemove='show=1'><img border='0' id='"+id_pic+"' src='"+sm_src+"''></div>";
		bpic = new Image();
		bpic.src = img_big;
	
		pic = document.getElementById(id_pic);
		pic.width = mwidth;
		picturediv.style.display = "block";
		increase();

}

function hidepicture() 
{
 show = 0;
 setTimeout('starthide()', 20);
}

function starthide() 
{
 if(show == 0) 
   {
    pic.width = pic.width - 10;
    pleft = pleft + 5;
    ptop = ptop + 5;
    picturediv.style.left = pleft + 'px';
    picturediv.style.top = ptop + 'px';
    if (pic.width > 100) setTimeout('starthide()', 0); else picturediv.style.display = "none";
   }
}

function increase() 
{
	if ((pic.width + incr)>bwidth) incr = (bwidth-pic.width); else incr = 20;
	pic.width = pic.width + incr;
	
	pleft = pleft - Math.round(incr/2);
	ptop = ptop - Math.round(incr/2);
	picturediv.style.left = pleft + 'px';
	picturediv.style.top = ptop + 'px';
	
	if (pic.width < bwidth) { setTimeout('increase()', 0); }
	else { if (bpic.complete) pic.src = bpic.src;}
	
	//if (pic.width > 100) document.getElementById("loading-pic").style.display = "block";
}



function absPosition(obj) 
{
 var x = y = 0;
 while(obj) {
		x += obj.offsetLeft;
		y += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return {x:x, y:y};
}
