var printid=0;

var windowopen=0;
var wndtop;
var newtop;
var onceload=false;

var lp=document.getElementById("backgal");
var pu=document.getElementById("scrollspan");
var hm=document.getElementById("thehtml");

var x=lp.offsetLeft;
var y=lp.offsetTop+document.scrollTop;

pu.style.left=x+'px';
pu.style.top=y+'px';

//var pu=document.getElementById("scrolldiv");
//var hm=document.getElementById("aaahtml");


	function keepwindow2()
	{
		
			if ((newtop-wndtop)<5 && (newtop-wndtop)>-5)
			{
				wndtop=newtop;
			}
			if (newtop>wndtop)
			{
				wndtop+=5;
				pu.style.top=wndtop+'px';
			}
			if (newtop<wndtop)
			{
				wndtop-=5;
				pu.style.top=wndtop+'px';
			}
			setTimeout(function () {keepwindow2();}, 40);
		
	}



	function keepwindow()
	{
		
		
		  var lp=document.getElementById("backgal");
			newtop=lp.offsetTop+hm.scrollTop+30;
			setTimeout(function () {keepwindow();}, 40);
			
			
	}



	function opisWindow()
	{
  
	var lp=document.getElementById("backgal");
   	var x=lp.offsetLeft;
	var y=lp.offsetTop+document.getElementById('thehtml').scrollTop+30;

	onceload=true;
    //var y=screen.height/2;
    //alert("Pozycja x:"+x);
    //alert("Pozycja y:"+y);	

	pu.style.left=x+'px';
	pu.style.top=y+'px';

	wndtop=y;
	newtop=y;

	
	setTimeout(function () {keepwindow();}, 100);
	setTimeout(function () {keepwindow2();}, 10);
	
                                                                                                                                         
	}

