//Created By MR
document.write('<div id="imgLoader" style="position:absolute; visibility:hidden; z-index:99;"><img src="/images1/loading82.gif" border=0></div>');
document.write('<div id="imgHolder" style="position:absolute; visibility:hidden; z-index:100;">');
/*if (navigator.userAgent.indexOf("MSIE") >= 0) {
      document.write('<table border="0" cellpadding="0" cellspacing="0"><tr><td><img src="spacer.gif" border="0" width="0" height="0" id="imgBig" onclick="closeImage();" style="border:1px solid black; cursor:pointer"></td><td valign=top height=100%><table border="0" cellpadding="0" cellspacing="0" height=100%><tr><td style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/innerpopmr/ramis_02.png\');width:8px;height:8px" height="8" nowrap></td></tr><tr><td style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/innerpopmr/ramis_03.png\',sizingMethod=scale);width:8px;height:100%"></td></tr></table></td></tr><tr><td><table border="0" cellpadding="0" cellspacing="0" width=100%><tr><td style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/innerpopmr/ramis_04.png\');width:8px;height:8px" width=8 nowrap></td><td style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/innerpopmr/ramis_05.png\',sizingMethod=scale);width:100%;height:8px"></td></tr></table></td><td style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/innerpopmr/ramis_06.png\');width:8px;height:8px" width="8" height="8" nowrap></td></tr></table>');
} else {  */
      //document.write('<table border="0" cellpadding="0" cellspacing="0"><tr><td rowspan=2 height=100%><img src="spacer.gif" border="0" width="0" height="0" id="imgBig" onclick="closeImage();" style="border:1px solid black; cursor:pointer"></td><td style="background:url(\'/innerpopmr/ramis_02.png\') no-repeat; width:8px; height:8px"></td></tr><tr><td style="background:url(\'/innerpopmr/ramis_03.png\') repeat-y;"></td></tr><tr><td><table border="0" cellpadding="0" cellspacing="0" width=100%><tr><td background="/innerpopmr/ramis_04.png" width="8" height="8" nowrap></td><td style="background:url(\'/innerpopmr/ramis_05.png\') repeat-x; width:100%; height:8px"></td></tr></table></td><td background="/innerpopmr/ramis_06.png" width="8" height="8" nowrap></td></tr></table>');
      document.write('<table cellpadding="0" cellspacing="0" border="0" class="bilzux"><tr class="t"><td class="l"></td><td class="m"></td><td class="r"></td></tr><tr class="m"><td class="l"></td><td class="m"><img src="spacer.gif" border="0" width="0" height="0" id="imgBig" onclick="closeImage();" style="cursor:pointer"></td><td class="r"></td></tr><tr class="b"><td class="l"></td><td class="m"></td><td class="r"></td></tr></table>');
//}
document.write('</div>');

var imgSmall, waitObj, waitId, waitDirection;
var growing=0;

function findPos_mr(el) {
      x=0; y=0; var temp
      if(el.offsetParent) {
            temp = el
            while(temp.offsetParent) {
                  temp=temp.offsetParent;
                  x+=temp.offsetLeft
                  y+=temp.offsetTop;
            }
      }
      x+=el.offsetLeft
      y+=el.offsetTop
      return [x,y,el.offsetWidth,el.offsetHeight]
}

function openImage(obj, id, direction) {
//alert(document.body.clientHeight + ' ' + window.innerHeight);
      if(growing==0){
            if(imgSmall) {
                  waitObj=obj;
                  waitId=id;
                  waitDirection=direction;
                  closeImage();
            } else {
                  imgSmall=document.getElementById(id);
                  pos=findPos_mr(imgSmall);
                  imgSmall.width = pos[2] ? pos[2] : parseInt(imgSmall.style.width);
                  imgSmall.height = pos[3] ? pos[3] : parseInt(imgSmall.style.height);
                  
                  loadLeft = pos[0] + imgSmall.width / 2 - 38;
                  loadTop = pos[1] + imgSmall.height / 2 - 18;
                  document.getElementById('imgLoader').style.left = loadLeft + 'px';
                  document.getElementById('imgLoader').style.top = loadTop + 'px';
                  document.getElementById('imgLoader').style.visibility = 'visible';
                  
                  imgLarge = new Image();
                  imgLarge.onload = function() {
                        imgLarge.onload = null;
                        
                        document.getElementById(id).style.visibility='hidden';
                        document.getElementById('imgLoader').style.visibility = 'hidden';
                        
                        document.getElementById('imgBig').width=imgSmall.width;
                        document.getElementById('imgBig').height=imgSmall.height;
                        document.getElementById('imgBig').src=obj.href;
                        
                        document.getElementById('imgHolder').style.left=pos[0]+'px';
                        document.getElementById('imgHolder').style.top=pos[1]+'px';
                        document.getElementById('imgHolder').style.visibility='visible';
                        
                        CW=navigator.userAgent.indexOf("MSIE") >= 0 ? document.documentElement.clientWidth : window.innerWidth;
                        CH=navigator.userAgent.indexOf("MSIE") >= 0 ? document.documentElement.clientHeight : window.innerHeight;
                        CW -= 50;
                        CH -= 50;
                        //alert(window.innerHeight);

                        //imgLarge.width -= 40;
                        LW=Math.floor(imgLarge.width);
                        LH=Math.floor(imgLarge.height);
                        if(LW>CW || LH>CH) {
                              if(LW/LH>=CW/CH) {
                                    LH=CW*LH/LW;
                                    LW=CW;
                              } else {
                                    LW=CH*LW/LH;
                                    LH=CH;
                              }
                        }

                        if(direction=='TL') {
                              endX = pos[0];
                              endY = pos[1];
                        } else if(direction=='T') {
                              endX = pos[0] - (LW - imgSmall.width)/2;
                              endY = pos[1];
                        } else if(direction=='TR') {
                              endX = pos[0] - (LW - imgSmall.width);
                              endY = pos[1];
                        } else if(direction=='L') {
                              endX = pos[0];
                              endY = pos[1] - (LH - imgSmall.height)/2;
                        } else if(direction=='C') {
                              endX = pos[0] - (LW - imgSmall.width)/2;
                              endY = pos[1] - (LH - imgSmall.height)/2;
                        } else if(direction=='R') {
                              endX = pos[0] - (LW - imgSmall.width);
                              endY = pos[1] - (LH - imgSmall.height)/2;
                        } else if(direction=='BL') {
                              endX = pos[0];
                              endY = pos[1] - (LH - imgSmall.height);
                        } else if(direction=='B') {
                              endX = pos[0] - (LW - imgSmall.width)/2;
                              endY = pos[1] - (LH - imgSmall.height);
                        } else if(direction=='BR') {
                              endX = pos[0] - (LW - imgSmall.width);
                              endY = pos[1] - (LH - imgSmall.height);
                        } else {
                              endX = pos[0];
                              endY = pos[1];
                        }

                        imageGrow(imgSmall.width, imgSmall.height, LW, LH, pos[0], pos[1], endX, endY, 20, imgSmall.width, imgSmall.height, pos[0], pos[1]);
                        //alert(imgSmall.width + ' ' + imgSmall.height + ' ' + LW + ' ' + LH + ' ' + pos[0] + ' ' + pos[1] + ' ' + endX + ' ' + endY + ' ' + imgSmall.width + ' ' + imgSmall.height + ' ' + pos[0] + ' ' + pos[1]);
                  }
                  imgLarge.src = obj.href;
            }
      }
}
                //300 200 450 300 559 1045 484 995 300 200 559 1045
function closeImage() {
      if(growing==0){
            pos=findPos_mr(imgSmall);
            imgLarge=document.getElementById('imgBig');
            x=parseFloat(document.getElementById('imgHolder').style.left);
            y=parseFloat(document.getElementById('imgHolder').style.top);
            imageGrow(imgLarge.width, imgLarge.height, imgSmall.width, imgSmall.height, x, y, pos[0], pos[1], 10, imgLarge.width, imgLarge.height, x, y);
      }
}

function imageGrow(startW, startH, endW, endH, startX, startY, endX, endY, speed, w, h, x, y) {
      growing=1;
      scrTop = navigator.userAgent.indexOf("MSIE") >= 0 ? document.documentElement.scrollTop : window.scrollY;
      //alert(scrTop);
      if((w<endW && startW<endW) || (w>endW && startW>endW)) {
            w += (endW-startW)/speed;
            h += (endH-startH)/speed;
            
            CW=navigator.userAgent.indexOf("MSIE") >= 0 ? document.documentElement.clientWidth : window.innerWidth;
            CH=navigator.userAgent.indexOf("MSIE") >= 0 ? document.documentElement.clientHeight : window.innerHeight;
            CW -= 50;
            CH -= 50;
            
            ttt = 20;
            x += (endX-startX)/speed;
            y += (endY-startY)/speed;
            x = x > ttt ? x : ttt;
            y = y > ttt + scrTop ? y : ttt + scrTop;
            //x = x+w>CW ? CW-w : x;
            y = y - scrTop + h > CH ? CH + scrTop - h : y;
            //x = x>ttt ? x : ttt;
            y = y > ttt + scrTop ? y : ttt + scrTop;
            document.getElementById('imgHolder').style.left=Math.floor(x)+'px';
            document.getElementById('imgHolder').style.top=Math.floor(y)+'px';
            document.getElementById('imgBig').width=Math.floor(w);
            document.getElementById('imgBig').height=Math.floor(h);
            
            window.setTimeout("imageGrow(" + startW + ", " + startH + ", " + endW + ", " + endH + ", " + startX + ", " + startY + ", " + endX + ", " + endY + ", " + speed + ", " + w + ", " + h + ", " + x + ", " + y + ")",25);
      } else {
            growing=0;
            document.getElementById('imgBig').width=endW;
            document.getElementById('imgBig').height=endH;
            if(startW<endW) {
                  waitObj='';
                  waitId='';
                  waitDirection='';
                  //imgSmall.title='';
                  document.getElementById('imgBig').title='Aizvērt';
            } else {
                  document.getElementById('imgHolder').style.visibility='hidden';
                  imgSmall.style.visibility='visible';
                  //imgSmall.title='Palielināt';
                  imgSmall='';
                  document.getElementById('imgBig').title='';
                  if(waitObj && waitId && waitDirection) {
                        openImage(waitObj, waitId, waitDirection);
                  }
            }
      }
}

