function setIMG(m,b)
{
  $('miniaturka').src = m;
  $('miniaturka').onclick = function() {
     fullIMG(b);
  };

   
}

function nextImg() {
                
                
  if( domki.length > current + 1 )
      ++current;
  else current = 0;
  
  setIMG( domki[current], full[current] );
}

function prevImg() {
  
  if( current - 1 < 0 )
      current = domki.length - 1;
  else --current;
  
  setIMG( domki[current], full[current] );
  
}

function fullIMG(src) {
  //showLayerWithImage($('formblack_layer'), $('loader'), 'images/loading.gif');
  showLayerWithImage($('formblack_layer'), $('photo_container'), src);
}

function showLayer(layerElement)
{
	var tohide = document.getElementsByTagName('select');
	for (i = 0; i < tohide.length; i++)
		tohide[i].style.visibility = 'hidden';
	var tohide = document.getElementsByTagName('input');
	for (i = 0; i < tohide.length; i++)
		tohide[i].style.visibility = 'hidden';
	var tohide = document.getElementsByTagName('textarea');
	for (i = 0; i < tohide.length; i++)
		tohide[i].style.visibility = 'hidden';
	window._scrollPositionV = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
	window._scrollPositionH = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
	resizeLayer(layerElement);
	document.documentElement.scrollTop = window._scrollPositionV;
	document.documentElement.scrollLeft = window._scrollPositionH;
	window._layer = layerElement;
	window.onscroll = function () {
		window._scrollPositionV = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
		window._scrollPositionH = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
		if (window._centered)
			showElementCenter(window._centered);
	}
	window.onresize = function () {
		window._scrollPositionV = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
		window._scrollPositionH = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
		if (window._layer)
			resizeLayer(window._layer);
		if (window._centered)
			showElementCenter(window._centered);
	};
}

function resizeLayer(layerElement)
{
	var docHeight = document.documentElement.scrollHeight;
	var docWidth = document.documentElement.scrollWidth;
	var bodyHeight = document.body.scrollHeight;
	var bodyWidth = document.body.scrollWidth;
	layerElement.style.visibility = 'visible';
	layerElement.style.width = Math.max(document.viewport.getWidth(), Math.max(docWidth, bodyWidth)) + 'px';
	layerElement.style.height = Math.max(document.viewport.getHeight(), Math.max(docHeight, bodyHeight)) + 'px';
	layerElement.style.display = 'block';
}

function hideLayer(layerElement)
{
	var tohide = document.getElementsByTagName('select');
	for (i = 0; i < tohide.length; i++)
		tohide[i].style.visibility = 'visible';
	var tohide = document.getElementsByTagName('input');
	for (i = 0; i < tohide.length; i++)
		tohide[i].style.visibility = 'visible';
	var tohide = document.getElementsByTagName('textarea');
	for (i = 0; i < tohide.length; i++)
		tohide[i].style.visibility = 'visible';
	
	if (window._centered)
		$(window._centered).hide();
	$(layerElement).hide();
	window._layer = null;
	window._centered = null;
	window._scrollPositionV = null;
	window._scrollPositionH = null;
	window.onresize = function () {};
	window.onscroll = function () {};
}

function showElementCenter(element)
{
	if (window._centered)
		$(window._centered).hide();
	element.style.position = 'absolute';
	element.style.display = 'block';
	element.style.left = (window._scrollPositionH?window._scrollPositionH:0) + (document.viewport.getWidth() - element.getWidth()) / 2 + 'px';
	element.style.top = (window._scrollPositionV?window._scrollPositionV:0) + (document.viewport.getHeight() - element.getHeight()) / 2 + 'px';
	element.style.visibility = 'visible';
	window._centered = element;
}

function loadImage(imageElement, imageURL)
{
	imageElement.src = ' ';
	imageElement.onload = function() {
		showElementCenter( $('container') );
		
		//showElementCenter( $('container') );
		
		this.onload = function() {};
	}
	imageElement.src = imageURL;
}

function showLayerWithImage(layerElement, imageElement, imageURL)
{
	showLayer(layerElement);
	loadImage(imageElement, imageURL);
}

function setPoziom( r, p )
{
      $('rzut').src = r;
      $('rzutlink').href = p;
      $('druk').href = p;   
}



