
var wndtop;
var newtop;
var onceload=false;

var lp=document.getElementById("backgal");
var pu=document.getElementById("scrollspan");
var pos;
  

function getPos(){

	if (window.innerHeight)
	{
		  pos = window.pageYOffset
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{
		pos = document.documentElement.scrollTop
	}
	else if (document.body)
	{
		  pos = document.body.scrollTop
	}
	//alert(pos)
	return pos;
}

var x=lp.offsetLeft;
var y=lp.offsetTop+getPos();

pu.style.left=x+'px';
pu.style.top=y+'px';



	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';
			}
			//alert(newtop);
			//getPos()
			setTimeout(function () {keepwindow2();}, 10);
		
	}



	function keepwindow()
	{
		
		var lp=document.getElementById("bodyportal");
	    var temp=getPos();
		newtop=lp.offsetTop+temp+30;
		setTimeout(function () {keepwindow();}, 10);
			
			
	}



	function opisWindow()
	{
     
  
	var lp=document.getElementById("bodyportal");
   	var x=lp.offsetLeft;
	var y=lp.offsetTop+getPos()+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);
	
                                                                                                                                         
	}

