var imgNext;var imgPrev;var show=true;function closeBox(){var d=document.getElementsByTagName("body")[0];var a=document.getElementById("litebox");if(a){a.style.display="none"}var e=document.getElementById("shadow");if(e){e.style.display="none"}d.removeChild(e);var c=document.getElementsByTagName("select");var b;for(b=0;b!==c.length;b++){c[b].style.visibility="visible"}document.onkeypress="";imgPrev=imgNext="";document.onkeydown="";show=true;return false}function getPageCoords(){var c=[0,0,0];if(window.innerHeight){c[0]=window.innerHeight;c[2]=window.pageYOffset}else{if(document.documentElement&&document.documentElement.clientHeight!==0){c[0]=document.documentElement.clientHeight;c[2]=document.documentElement.scrollTop}else{if(document.body){c[0]=document.body.clientHeight;c[2]=document.body.scrollTop}}}var b=document.body.scrollHeight;var a=document.body.offsetHeight;if(b>a){c[1]=document.body.scrollHeight}else{c[1]=document.body.offsetHeight}if(c[1]<c[0]){c[1]=c[0]}return c}function showBox(g){var e=document.getElementsByTagName("body")[0];var a=getPageCoords();var h=document.createElement("div");h.id="shadow";h.style.height=(a[1]+"px");h.className="on";var d=document.getElementsByTagName("select");var c;for(c=0;c!==d.length;c++){d[c].style.visibility="hidden"}e.insertBefore(h,e.firstChild);var b=document.createElement("div");b.id="loading";b.style.top=parseInt(a[2]+(a[0]-55)/2,10)+"px";b.onclick=function(){closeBox()};h.appendChild(b);var f=new Image();f.onload=function(){var p=document.createElement("div");p.id="litebox";p.style.width=f.width+10+"px";p.style.marginTop=parseInt(a[2]+(a[0]-f.height-50)/2,10)+"px";var o=document.createElement("img");o.src=g.href;o.alt=g.title;o.width=f.width;o.onclick=function(){closeBox()};o.title="Для закрытия - щелкните по изображению или нажмите ESC";var t=document.createElement("p");t.innerHTML=(o.alt)?o.alt:"";t.innerHTML+="<em>Для закрытия - щелкните по изображению или нажмите ESC</em>";var r=[];var s=document.getElementsByTagName("a");var k=s.length;var n,m;for(n=0,m=0;n<k;n++){if(s[n].getAttribute("rel")==="lightbox"){r[m++]=s[n]}}k=r.length;for(n=0;n<k;n++){if(r[n].href===g.href){if(r[n-1]){var l=document.createElement("a");l.className="prev";l.title=r[n-1].title;l.href=r[n-1].href;l.onclick=function(){closeBox();showBox(this);return false};t.insertBefore(l,t.firstChild);imgPrev=r[n-1]}if(r[n+1]){var q=document.createElement("a");q.className="next";q.title=r[n+1].title;q.href=r[n+1].href;q.onclick=function(){closeBox();showBox(this);return false};t.insertBefore(q,t.firstChild);imgNext=r[n+1]}}}h.removeChild(b);p.appendChild(o);p.appendChild(t);h.appendChild(p);document.onkeydown=function(u){var j;u=u||window.event;var i=u.keyCode?u.keyCode:u.which;switch(i){case 27:case 32:closeBox();break;case 37:j=imgPrev?imgPrev:"";break;case 39:j=imgNext?imgNext:"";break}if(j){closeBox();showBox(j)}return false};return false};f.src=g.href}function initLitebox(){if(!document.getElementsByTagName){return}var d=document.getElementsByTagName("a");var c,a;for(c=0,a=d.length;c<a;c++){var b=d[c];if(b.getAttribute("href")&&(b.getAttribute("rel")==="lightbox")){b.onclick=function(){if(show){show=false;showBox(this);return false}else{return false}}}}}function addLoadEvent(a){var b=window.onload;if(typeof window.onload!=="function"){window.onload=a}else{window.onload=function(){b();a()}}}addLoadEvent(initLitebox);
