function hideFlashBanners(){$("iframe.iframeBanner").contents().find(".hideFlash").hide();$(".hideFlash").css("visibility","hidden");}function showFlashBanners(){$("iframe.iframeBanner").contents().find(".hideFlash").show();$(".hideFlash").css("visibility","visible");}function getPageCoords(){var coords=[0,0,0,0];if(window.innerHeight){coords[0]=window.innerHeight;coords[2]=window.pageYOffset;coords[3]=window.innerWidth;}else{if(document.documentElement&&document.documentElement.clientHeight!=0){coords[0]=document.documentElement.clientHeight;coords[2]=document.documentElement.scrollTop;coords[3]=document.documentElement.clientWidth;}else{if(document.body){coords[0]=document.body.clientHeight;coords[2]=document.body.scrollTop;coords[3]=document.body.clientWidth;}}}var test1=document.body.scrollHeight;var test2=document.body.offsetHeight;if(test1>test2){coords[1]=document.body.scrollHeight;}else{coords[1]=document.body.offsetHeight;}if(coords[1]<coords[0]){coords[1]=coords[0];}return coords;}var showBoxNotRun=true;function showBox(theTarget){if(showBoxNotRun){showBoxNotRun=false;hideFlashBanners();var theBody=document.getElementsByTagName("body")[0];var pageCoords=getPageCoords();var theShadow=document.createElement("div");theShadow.id="shadow";theShadow.style.height=(pageCoords[1]+"px");theShadow.className="on";theShadow.onclick=function(){closeBox();return false;};theBody.insertBefore(theShadow,theBody.firstChild);var imgPreload=new Image();imgPreload.onload=function(){var theBox=document.createElement("div");var imgWidth=imgPreload.width;var imgHeight=imgPreload.height;if(imgWidth>(pageCoords[3])||imgHeight>(pageCoords[0]-45)){var widthExcept=parseInt((pageCoords[3])*100/imgWidth);var heightExcept=parseInt((pageCoords[0]-45)*100/imgHeight);var minExcept=widthExcept;if(heightExcept<minExcept){minExcept=heightExcept;}imgWidth=parseInt(imgWidth*minExcept/100);imgHeight=parseInt(imgHeight*minExcept/100);}theBox.id="litebox";theBox.style.width=imgWidth+30+"px";theBox.style.marginTop=parseInt(pageCoords[2]+(pageCoords[0]-imgHeight-50)/2)+"px";var theImageLink=document.createElement("a");theImageLink.id="imageLink";var theImage=document.createElement("img");theImage.src=theTarget.href;theImage.alt=theTarget.title;theImage.width=imgWidth;theImage.height=imgHeight;var theSignature=$("<div class='signature' style='clear:both'>"+theTarget.title+"</div>");var theCaption=document.createElement("p");theCaption.id="litebox_navigation";var allThumbs=new Array();var allLinks=document.getElementsByTagName("a");var linkLen=allLinks.length;for(i=0,j=0;i<linkLen;i++){if(allLinks[i].getAttribute("rel")!="lightbox"&&allLinks[i].getAttribute("rel")==theTarget.getAttribute("rel")){allThumbs[j++]=allLinks[i];}}linkLen=allThumbs.length;for(i=0;i<linkLen;i++){if(allThumbs[i].href==theTarget.href){var flag_left_nav=0;var flag_right_nav=0;if(allThumbs[i-1]){var $l=$("<a class='prev' title='"+allThumbs[i-1].title+"' href='"+allThumbs[i-1].href+"' rel='"+allThumbs[i-1].rel+"'><img src='/img/dom/arrow_left.png' alt='&lt;&lt;'></a>").click(function(){closeBox();showBox(this);return false;});$(theCaption).prepend($l);imgPrev=allThumbs[i-1];flag_left_nav=1;}if(flag_left_nav==0){$(theCaption).prepend($("<div class='startPhotos'>&nbsp;</div>"));}if(allThumbs[i+1]){var $l=$("<a class='next' title='"+allThumbs[i+1].title+"' href='"+allThumbs[i+1].href+"' rel='"+allThumbs[i+1].rel+"'><img src='/img/dom/arrow_right.png' alt='&gt;&gt;'></a>").click(function(){closeBox();showBox(this);return false;});theImage.onclick=function(){$l.click();};$(theCaption).append($l);imgNext=allThumbs[i+1];flag_right_nav=1;}if(flag_right_nav==0){$(theCaption).append($("<div class='finishPhotos'>&nbsp;</div>"));}}}var $close=$("<em>закрыть</em>").click(function(){closeBox();return false;});var $closeDiv=$("<div></div>");$closeDiv.append($close);$(theCaption).append($closeDiv);theBox.onclick=function(event){event=event||window.event;event.stopPropagation?event.stopPropagation():(event.cancelBubble=true);};var theImageLinkContainer=document.createElement("div");theImageLinkContainer.style.width=imgWidth+"px";theImageLinkContainer.style.height=imgHeight+"px";theImageLinkContainer.style.marginTop="10px";theImageLinkContainer.style.marginRight="15px";theImageLinkContainer.style.marginLeft="15px";theShadow.appendChild(theBox);theBox.appendChild(theImageLinkContainer);$(theBox).append(theSignature);theBox.appendChild(theCaption);theImageLinkContainer.appendChild(theImageLink);theImageLink.appendChild(theImage);return false;};imgPreload.src=theTarget.href;}}function centerDialog(id){var pageCoords=getPageCoords();if(!id){id="#"+$("#shadow div").attr("id");}return $(id).css("margin-top",pageCoords[2]+(pageCoords[0]-$(id).height())/2);}function isDialogOpened(){return $("#shadow:visible").length>0;}function showDialog(id,escapeElement){var pageCoords=getPageCoords();$('<div id="shadow"></div>').height(pageCoords[1]).addClass("on").prependTo("body");id="#"+id;centerDialog(id).appendTo("#shadow").find("img").load(function(){centerDialog(id);}).end().show(1,function(){$(this).find(":input:visible:first").focus();});var ESCAPE=27;$(document).keypress(function(e){if(e.keyCode==ESCAPE){escapeElement?escapeElement.click():closeDialog();}});}function closeDialog(){$(document).unbind("keypress");$("#shadow div:first").hide().appendTo("body");$("#shadow").remove();}function closeBox(){var theBody=document.getElementsByTagName("body")[0];var theBox=document.getElementById("litebox");if(theBox){theBox.style.display="none";}var theShadow=document.getElementById("shadow");if(theShadow){theShadow.style.display="none";}theBody.removeChild(theShadow);selects=document.getElementsByTagName("select");for(i=0;i!=selects.length;i++){selects[i].style.visibility="visible";}document.onkeypress="";showFlashBanners();showBoxNotRun=true;return false;}function initLitebox(){if(!document.getElementsByTagName){return;}var anchors=document.getElementsByTagName("a");for(i=0,len=anchors.length;i<len;i++){var anchor=anchors[i];if(anchor.getAttribute("href")&&anchor.getAttribute("rel")&&anchor.getAttribute("rel").indexOf("lightbox")!=-1){anchor.onclick=function(){showBox(this);return false;};}}anchor=null;}$(document).ready(function(){initLitebox();});
