
 function getBodyScrollTop()
 {
    return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
 }

 function getyScroll()
 {
  yScroll = 0;

  if (window.innerHeight && window.scrollMaxY || window.innerWidth && window.scrollMaxX)
   {
    yScroll = window.innerHeight + window.scrollMaxY;
    xScroll = window.innerWidth + window.scrollMaxX;

    var deff = document.documentElement;
    var wff = (deff&&deff.clientWidth) || document.body.clientWidth || window.innerWidth || self.innerWidth;
    var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;

    xScroll -= (window.innerWidth - wff);
    yScroll -= (window.innerHeight - hff);
   } 
  else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth)
   { // all but Explorer Mac
    yScroll = document.body.scrollHeight;
    xScroll = document.body.scrollWidth;
   } 
  else 
   { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    yScroll = document.body.offsetHeight;
    xScroll = document.body.offsetWidth;
   }

  return yScroll;
 }


function pageScroll()
{
    var d = document;
    var top_correct = (d.getElementById('html').clientHeight - 640)/2;
    d.getElementById('popup_viewver').style.top = (top_correct+getBodyScrollTop())+'px';
}

function SetImg(iid,change)
{
    for (i=0;i<Imagelist.length;i++)
    {
        if (Imagelist[i]==iid)
        {
            document.getElementById('link_full').href=FullUrllist[i];
            break;
        };
    }
    w=screenSize().w-300;
    h=screenSize().h-300;
    if (!change) document.getElementById('largeimg').src = "/images/preloader.gif";
    new Ajax.Request('/ajax.php?mode=getimgurl&dw='+w+'&dh='+h+'&iid='+iid+'&key=1',
    {     
        method:'get',
        onSuccess: function(transport)
        {       
          document.getElementById('largeimg').src = transport.responseText || "/images/nofoto.gif";
        },
        onFailure: function()
        { document.getElementById('laregimg').src="/images/img_err.gif"; 
        }
    });     
}


function showImageViewer(iid)
{
    var top_correct = (document.getElementById('html').clientHeight - 640)/2;
    SetImg(iid);
    document.getElementById('popup_viewver').style.top = (top_correct+getBodyScrollTop())+'px';
    document.getElementById('popup_viewver').style.display = 'block';
    document.getElementById('screen').style.height = getyScroll() + 'px'; 
    document.getElementById('screen').style.display = 'block';
}

function closeImageViewer()
{
    var d = document;
    d.getElementById('popup_viewver').style.display = 'none';
    d.getElementById('screen').style.display = 'none';  
}


function hideCompareList()
{
    var d = document;
    d.getElementById('popup_compare').style.display = 'none';
    d.getElementById('screen').style.display = 'none';  
}


function screenSize() {
    var w, h;
    w = (window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth));
    h = (window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight));
    return {w:w, h:h}; 
}




if (window.addEventListener) //DOM method for binding an event
    window.addEventListener("scroll", pageScroll, false)
else if (window.attachEvent) //IE exclusive method for binding an event
    window.attachEvent("onscroll", pageScroll)
else if (document.getElementById) //support older modern browsers
    window.onscroll=pageScroll;
