function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function setCookie(name, value) {
//	cswitch = getCookie("cswitch");
//	if (!cswitch) 
{
		var today = new Date();d = new Date(today.getTime() + 86400000); // 1 сутки
		var newCookie1 = name + "=" + escape(value) + ";expires=" + d.toGMTString() ;//+ ";path=/ ;domain=www.art-catalog.ru;";
		var newCookie2 = name + "=" + escape(value) + ";expires=" + d.toGMTString();// + ";path=/ ;domain=art-catalog.ru;";
		document.cookie = newCookie2;
		document.cookie = newCookie1;
		//var newCookie3 = name + "=" + escape(value) + ";expires=" + d.toGMTString() + ";path=/ ;domain=192.168.2.252;";
		//document.cookie = newCookie3;
	}
}

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;


// Подгрузка small-картинок в списке
function showpicture_lite(debug, prefix, id, pos, id_artist, file_img) 
{
	if (!debug) // 1
	{
		host = "http://www.art-catalog.ru/data_picture_new/artist_"+id_artist+"/picture/";
		host_url = "http://www.art-catalog.ru/";
	}
	else
	{
		host = "http://localhost/art-catalog-6/data_picture_new/artist_"+id_artist+"/picture/";
		host_url = "http://localhost/art-catalog-6/";
	}
	
	img_small	= host_url + "_img/clr.gif";
	img_big		= host + "small/"+file_img+".jpg";
	url			= host_url+"picture.php?id_picture="+id;
	bw			= 130;
	bh			= 130;
	id_pic		= prefix+id;
	pic_divname = "middlepic";
	
	picturediv = document.getElementById(pic_divname);
	picturediv.style.left	= pos.x + 'px';
	picturediv.style.top	= pos.y + 'px';
	picturediv.style.width	= bw + 'px';
	picturediv.style.height = bh + 'px';

	picturediv.innerHTML = "<a href='" + url + "'><div><img border='0' onmuseout='hidepicture_lite()' id='"+id_pic+"' src='"+img_small+"'></div></a>";

	bpic = new Image();
	bpic.src = img_big;
	pic = document.getElementById(id_pic);
	picturediv.style.display = "block";
	increase_lite();

}
function hidepicture_lite() 
{
	show = 0;
	picturediv.innerHTML = "";
	picturediv.style.display = "none";	
}

function increase_lite() 
{
	if (bpic.complete) 
	{
		pic.src = bpic.src;
		picturediv.style.width = bpic.width+'px';
		picturediv.style.height = bpic.height+'px';
	}
	else
		setTimeout('increase_lite()', 0); 
}


// Подгрузка middle-картинок в списке
function showpicture(debug, prefix, id, pos, mwidth, mheight, id_artist, file_img) 
{
	if (!debug) // 1
	{
		host = "http://www.art-catalog.ru/data_picture_new/artist_"+id_artist+"/picture/";
		host_url = "http://www.art-catalog.ru/";
	}
	else
	{
		host = "http://localhost/art-catalog-6/data_picture_new/artist_"+id_artist+"/picture/";
		host_url = "http://localhost/art-catalog-6/";
	}
	
	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	= 300;
	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) 
{
if (getCookie("dontshowbig") != 1)
	{
		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><div id='loading-pic' onmouseout='hidepicture()' onmousemove='show=1'>Загружается...</div><div id='noshow' style='width:"+bwidth+"px' onmouseout='hidepicture()' onmousemove='show=1'><input type='checkbox' onChange='dontshowbig(this.checked)' onmousemove='show=1'> Не показывать всплывающие картинки</div>";
	
		bpic = new Image();
		bpic.onload = function () {
				document.getElementById("loading-pic").innerHTML = "";
				pic.src = bpic.src;
			}
		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) {
		document.getElementById("noshow").style.display = "none";
		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 = 10;
	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;
		document.getElementById("noshow").style.display = "block";
	}
	
	if (pic.width > 100) document.getElementById("loading-pic").style.display = "block";
}



function dontshowbig(dontshow) {
	UserSes = getCookie("UserSes");
	if (dontshow) {
		setCookie("dontshowbig", "1"); 
	//	big_pics_stat(UserSes, "dontshow");
	}
	else {
		setCookie("dontshowbig", "0");
	//	big_pics_stat(UserSes, "show");
	}
}

function absPosition(obj) {
	var x = y = 0;
	while(obj) {
		x += obj.offsetLeft;
		y += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return {x:x, y:y};
}

