...
function showPic() {
zoomWidth = width_array[currentZoom];
zoomHeight = height_array[currentZoom];
var ratio = zoomWidth / zoomHeight;
//check size
if(zoomHeight > screenHeight - 45) {
zoomHeight = screenHeight - 45;
zoomWidth = zoomHeight * ratio;
} else if(zoomWidth > screenWidth - 50) {
zoomWidth = screenWidth - 50;
zoomHeight = zoomWidth / ratio;
}
oldW = $(".myZoom" + oldZoom + " img").width();
oldH = $(".myZoom" + oldZoom + " img").height();
oldOf = $(".myZoom" + oldZoom + " img").offset();
if(oldW === null) {
oldW = $(".myZoom" + oldZoom).width();
oldH = $(".myZoom" + oldZoom).height();
oldOf = $(".myZoom" + oldZoom).offset();
}
if(placeToCenter === false) {
// in place
//check place
localTop = bpcTop - (zoomHeight / 2);
if(localTop < screenScroll + 20) {localTop = screenScroll + 20};
if(localTop + zoomHeight > screenScroll + screenHeight - 20) {localTop = screenScroll + screenHeight - zoomHeight - 20};
localLeft = bpcLeft - (zoomWidth / 2);
if(localLeft < 20) {localLeft = 20};
if(localLeft > screenWidth - zoomWidth - 25) {localLeft = screenWidth - zoomWidth - 25};
$("#zoomPic" + currentZoom).css("top", bpOff.top).css("left", bpOff.left).css("width", bpWidth).css("height", bpHeight);
$("#zoomPic" + currentZoom).animate({
width:zoomWidth,
height:zoomHeight,
left:localLeft,
top:localTop
}, 200, setShadow);
if(currentZoom !== oldZoom && strashno === false) {
removeShadow();
$("#zoomPic" + oldZoom).animate({
width:oldW,
height:oldH,
left:oldOf.left,
top:oldOf.top
}, 200, removeOld);
}
strashno = false;
} else {
// in center
//check place
localTop = (screenHeight / 2) - (zoomHeight / 2);
localLeft = (screenWidth / 2) - (zoomWidth / 2);
$("#bigGrey").addClass("bigGrey").height($("body > div").innerHeight());
$("#zoomPic" + currentZoom).css("top", bpOff.top).css("left", bpOff.left).css("width", bpWidth).css("height", bpHeight);
$("#zoomPic" + currentZoom).animate({
width:zoomWidth,
height:zoomHeight,
left:localLeft,
top:localTop + $(window).scrollTop()
}, 200, setShadow);
if(currentZoom !== oldZoom && strashno === false) {
removeShadow();
$("#zoomPic" + oldZoom).animate({
width:oldW,
height:oldH,
left:oldOf.left,
top:oldOf.top
}, 200, removeOld);
}
strashno = false;
}
};
function setShadow() {
clicked = false;
var zsLeft = localLeft - 6;
var zsTop = localTop - 6;
if(placeToCenter === false) {
$("div.zoomShadow").css("left", zsLeft).css("top", zsTop);
} else {
$("div.zoomShadow").css("left", zsLeft).css("top", zsTop).css("position", "fixed");
}
$("div.zoomShadow div.zoomBase").width(zoomWidth - 8).height(zoomHeight - 8);
for(var i = 0; i < galNum; i++) {
if(i !== parseInt(currentZoom)) {
$("#zoomPic" + i).css("top", -9999).css("left", -1000).css("width", width_array[i]).css("height", height_array[i]);
}
}
$("#zoomPic" + currentZoom).click(function(event){
$("a.zoomX").remove();
hideCurrent();
});
$("body").append(zoomX);
if(placeToCenter === false) {
$("a.zoomX").css("left", localLeft + zoomWidth - 16).css("top", localTop - 17);
} else {
$("a.zoomX").css("left", localLeft + zoomWidth - 16).css("position", "fixed").css("top", localTop - 17);
}
$("a.zoomX").click(function(event){
event.preventDefault();
$("a.zoomX").css("position", "absolute").remove();
hideCurrent();
});
$("select").addClass("selOff");
if(placeToCenter === true) {
$("#zoomPic" + currentZoom).css("position", "fixed").css("top", localTop);
}
}
function removeShadow() {
$("div.zoomShadow").css("top", -9999).css("left", -1000).css("position", "absolute");
}
function removeOld() {
$("#zoomPic" + oldZoom).css("top", -9999).css("left", -1000).css("width", width_array[oldZoom]).css("height", height_array[oldZoom]).css("position", "absolute");
}
function hideCurrent() {
if(clicked === false) {
$("#bigGrey").removeClass("bigGrey").height(0);
$("select").removeClass("selOff");
oldZoom = currentZoom;
oldWidth = width_array[oldZoom];
oldHeight = height_array[oldZoom];
oldW = $(".myZoom" + oldZoom + " img").width();
oldH = $(".myZoom" + oldZoom + " img").height();
oldOf = $(".myZoom" + oldZoom + " img").offset();
if(oldW === null) {
oldW = $(".myZoom" + oldZoom).width();
oldH = $(".myZoom" + oldZoom).height();
oldOf = $(".myZoom" + oldZoom).offset();
}
removeShadow();
if(placeToCenter === false) {
$("#zoomPic" + oldZoom).animate({
width:oldW,
height:oldH,
left:oldOf.left,
top:oldOf.top
}, 200, removeOld);
} else {
$("#zoomPic" + oldZoom).animate({
width:oldW,
height:oldH,
left:oldOf.left,
top:oldOf.top - $(window).scrollTop()
}, 200, removeOld);
}
strashno = true;
}
clicked = true;
}
$("#bigGrey").click(function() {
$("a.zoomX").remove();
hideCurrent();
});
$(window).keydown(function(event) {
if(event.keyCode == '27') {
$("a.zoomX").remove();
hideCurrent();
}
if(event.keyCode == '39' && galNum > 1) {
removeShadow();
$("a.zoomX").remove();
oldZoom = currentZoom;
if(firstClick === false) {
if(currentZoom < galNum - 1) {
currentZoom++;
} else {
currentZoom = 0;
}
}
bpOff = $(".myZoom" + currentZoom).offset()
bpWidth = $(".myZoom" + currentZoom).find("img").width();
bpHeight = $(".myZoom" + currentZoom).find("img").height();
if(bpWidth === null) {
bpWidth = $(".myZoom" + currentZoom).width();
bpHeight = $(".myZoom" + currentZoom).height();
}
bpcLeft = Math.round(bpOff.left + (bpWidth / 2));
bpcTop = Math.round(bpOff.top + (bpHeight / 2));
showPic();
}
if(event.keyCode == '37' && galNum > 1) {
removeShadow();
$("a.zoomX").remove();
oldZoom = currentZoom;
if(firstClick === false) {
if(currentZoom > 0) {
currentZoom--;
} else {
currentZoom = galNum - 1;
}
}
bpOff = $(".myZoom" + currentZoom).offset()
bpWidth = $(".myZoom" + currentZoom).find("img").width();
bpHeight = $(".myZoom" + currentZoom).find("img").height();
if(bpWidth === null) {
bpWidth = $(".myZoom" + currentZoom).width();
bpHeight = $(".myZoom" + currentZoom).height();
}
bpcLeft = Math.round(bpOff.left + (bpWidth / 2));
bpcTop = Math.round(bpOff.top + (bpHeight / 2));
showPic();
}
});
function clearCache() {
firstClick = true;
galNum = 0;
oldZoom = 0;
currentZoom = 0;
oldW = 0;
oldH = 0;
oldOf = 0;
clicked = false;
strashno = false;
allLoaded = false;
loadStatus = 0;
$("img.zoomPic").remove();
$("a.zoomX").remove();
removeShadow();
}
})(jQuery);