var objheight;
var objwidth;
function showBigPic(image, width, height) 
{  
    
	objheight = height;
	objwidth = width;
		var win = document.createElement("div");
		var podol = document.createElement("div");
		win.setAttribute("id", "bigpic");
		podol.setAttribute("id", "podol");
		document.body.appendChild(win);
		document.body.appendChild(podol);
/*
		var bigimg = document.createElement("img");
		bigimg.setAttribute("id", "bigimg");
		bigimg.style.width =  '0px';
		bigimg.style.height = '0px';
		bigimg.setAttribute("src", "../merch/pictures/" + image);
		win.appendChild(bigimg);
	*/

    podol.style.visibility = 'visible';
	podol.style.display = 'block';
	podol.style.width = getDocumentWidth() + 'px';
	podol.style.height = getDocumentHeight()  + 'px';
	
	//win.style.background = "url('../pictures/load.gif') center no-repeat";

	win.style.visibility = 'visible';
	win.style.display = 'block';
	wtop  = getClientCenterY() - 16 + "px";
	wleft = getClientCenterX() - 16 + "px";
	win.style.top = wtop;
	win.style.left = wleft;

	//win.style.width = (width + 2) +'px';
	//win.style.height = (height + 2) + 'px';
	
	win.innerHTML = "<img src='../pictures/loading.gif' id='loading'><img width='0px' height='0px' src='../merch/pictures/" + image + "' id='bigimg'  onLoad='PicOnLoad("+ width+","+height+")'>";


	win.onmousedown = closePic;
	podol.onmousedown = closePic;

	setElementOpacity("podol", 0.5);	

	
	if(document.body.scroll != null) {// для ie
		document.body.setAttribute("scroll", "no");
		InputLayer();
	} else {
		window.onscroll = notscroll; 
	}
	
}

 function PicOnLoad(width, height) {
    win = document.getElementById("bigpic");
    wtop  = getClientCenterY() - parseInt((height + 2)/2) + "px";
	wleft = getClientCenterX() - parseInt((width + 2)/2)  + "px";
	win.style.top = wtop;
	win.style.left = wleft;
	big = document.getElementById("bigimg");
	big.style.width =  width;
	big.style.height = height;
	loadpic = document.getElementById("loading");
	loadpic.style.width =  0;
	loadpic.style.height = 0;
}

function notscroll(top, left) {
	win = document.getElementById('bigpic');
	wtop  = getClientCenterY() - parseInt((objheight + 2)/2) + "px";
	wleft = getClientCenterX() - parseInt((objwidth + 2)/2)  + "px";
	win.style.top = wtop;
	win.style.left = wleft;
}

function InputLayer() {
	selectlist = document.body.getElementsByTagName('select');
	for (var i=0;i<selectlist.length;i++)
	{
		el = selectlist[i];
		if (el.style.visibility != 'hidden') {
		  el.style.visibility = 'hidden';
		}  else {
		  el.style.visibility = 'visible';
		}

	}
}

function closePic() 
{


	if(document.getElementById('bigpic')) {
		win = document.getElementById('bigpic');
	}

	if(document.getElementById('podol')) {
		p = document.getElementById('podol');
	}

	if(document.getElementById('bigimg')) {
		big = document.getElementById('bigimg');
	}
	
	if(document.getElementById('loading')) {
		load = document.getElementById('loading');
	}
   
	if(document.body.scroll) {
		document.body.setAttribute("scroll", "");
		InputLayer();
		big.removeNode();
		load.removeNode();
		win.removeNode();
		p.removeNode();
	} else {
		win.removeChild(load);
		win.removeChild(big);
		document.body.removeChild(win);
		document.body.removeChild(p);
		window.onscroll = ""; 
	}
}


function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}


function getClientCenterX()
{
	return parseInt(getClientWidth()/2)+getBodyScrollLeft();
}

function getClientCenterY()
{
	return parseInt(getClientHeight()/2)+getBodyScrollTop();
}


function setElementOpacity(sElemId, nOpacity)
{
  var opacityProp = getOpacityProperty();
  var elem = document.getElementById(sElemId);

  if (!elem || !opacityProp) return; 
  
  if (opacityProp=="filter")  
  {
    nOpacity *= 100;
	
    var oAlpha = elem.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha;
    if (oAlpha) oAlpha.opacity = nOpacity;
    else elem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";
  }
  else
    elem.style[opacityProp] = nOpacity;
}

function getOpacityProperty()
{
  if (typeof document.body.style.opacity == 'string') // CSS3 compliant (Moz 1.7+, Safari 1.2+, Opera 9)
    return 'opacity';
  else if (typeof document.body.style.MozOpacity == 'string') // Mozilla 1.6 и младше, Firefox 0.8 
    return 'MozOpacity';
  else if (typeof document.body.style.KhtmlOpacity == 'string') // Konqueror 3.1, Safari 1.1
    return 'KhtmlOpacity';
  else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) // Internet Exploder 5.5+
    return 'filter';

  return false;
}

function getBodyScrollTop()
{
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function getBodyScrollLeft()
{
  return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}


function getDocumentHeight()
{
	return (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
}

function getDocumentWidth()
{
	return (document.body.scrollWidth > document.body.offsetWidth)?document.body.scrollWidth:document.body.offsetWidth;
}
