(function($){
var placeToCenter = false; // этот параметр отвечает за размещение картинки
var bpOff = 0;
var bpWidth = 0;
var bpHeight = 0;
var bpcLeft = 0;
var bpcTop = 0;
var zoomWidth = 0;
var zoomHeight = 0;
var width_array = new Array();
var height_array = new Array();
var screenWidth = 0;
var screenHeight = 0;
var screenScroll = 0;
var scrLeft = 0;
var scrTop = 0;
var localTop = 0;
var localLeft = 0;
var zoomTrash = '<div id="bigGrey"></div>\r<div class="zoomShadow"><table><tr><td class="zs1"><b></b></td><td class="zh1"><b></b></td><td class="zs2"><b></b></td></tr><tr><td class="zv1"><b></b></td><td><div class="zoomBase"></div></td><td class="zv2"><b></b></td></tr><tr><td class="zs3"><b></b></td><td class="zh2"><b></b></td><td class="zs4"><b></b></td></tr></table></div>\r';
var zoomX = '<a href="#" class="zoomX"></a>\r';
var firstClick = true;
var galNum = 0;
var oldZoom = 0;
var currentZoom = 0;
var oldW = 0;
var oldH = 0;
var oldOf = 0;
var clicked = false;
var strashno = false;
var allLoaded = false;
var loadStatus = 0;
$("a.zoom").live("click", function(event) {
event.preventDefault();
$(this).blur();
$("a.zoomX").remove();
$("select").addClass("selOff");
bpOff = $(this).offset();
bpWidth = $(this).find("img").width();
bpHeight = $(this).find("img").height();
if(bpWidth === null) {
bpWidth = $(this).width();
bpHeight = $(this).height();
}
bpcLeft = Math.round(bpOff.left + (bpWidth / 2));
bpcTop = Math.round(bpOff.top + (bpHeight / 2));
screenScroll = $(window).scrollTop();
screenWidth = $("body").innerWidth();
screenHeight = $(window).height();
scrLeft = Math.round(screenWidth / 2);
scrTop = Math.round(screenScroll + (screenHeight / 2));
if(firstClick === true){
$("body").append(zoomTrash);
galNum = $(".zoom").length;
for(var i = 0; i < galNum; i++) {
$(".zoom:eq(" + i + ")").addClass("myZoom" + i);
}
$("body").append('<img id="zoomLoading" src="zoom/zoom-load.gif" />\r')
$("#zoomLoading").css("left", bpcLeft - 11).css("top", bpcTop - 11);
for(var i = 0; i < galNum; i++) {
var zoomUrl = $(".myZoom" + i).attr("href");
$("body").append('<img class="zoomPic" src="' + zoomUrl + "?" + Math.random()*10 + '" id="zoomPic' + i + '" />\r')
}
currentZoom = $(this).attr("class");
currentZoom = currentZoom.slice(currentZoom.indexOf("myZoom"));
currentZoom = currentZoom.slice(6);
oldZoom = currentZoom;
for(var i = 0; i < galNum; i++) {
$("#zoomPic" + i).load(function() {
loadStatus++;
var localId = $(this).attr("id").slice(7);
width_array[localId] = $(this).width();
height_array[localId] = $(this).height();
});
}
var loading = setInterval(waitForPics, 50);
firstClick = false;
} else {
oldZoom = currentZoom;
currentZoom = $(this).attr("class");
currentZoom = currentZoom.slice(currentZoom.indexOf("myZoom"));
currentZoom = currentZoom.slice(6);
showPic();
}
function waitForPics() {
if(loadStatus === galNum) {
$("#zoomLoading").remove();
clearInterval(loading);
showPic();
}
}
});
...