function initWScroll(){
 _p = document.getElementById("sub-gallery");
 if(_p){
	 var _offset = getCurrentYPos();
	 var _top = _offset;
	 _p.style.marginTop = _top + "px";
 }
 window.onscroll = function(){
 if(_p){
	 var _offset = getCurrentYPos();
	 var _top = _offset;
	// if(document.documentElement.clienHeight > _p.clienHeight + _top)
	 _p.style.marginTop = _top + "px";
	 }
 }
}
function getCurrentYPos(){
 var _offset = 0;
 if (document.body && document.body.scrollTop)
 _offset = document.body.scrollTop;
 if (document.documentElement && document.documentElement.scrollTop)
 _offset = document.documentElement.scrollTop;
 if (window.pageYOffset)
 _offset = window.pageYOffset;

 return _offset;
 }

if (window.addEventListener){
 window.addEventListener("load", initWScroll, false);
 window.addEventListener("resize", initWScroll, false);
}
else if (window.attachEvent){
 window.attachEvent("onload", initWScroll);
 window.attachEvent("onresize", initWScroll);
}