/**
*
*/
Drupal.Gallery = new Object;
/**
*
*/
Drupal.Gallery.init = function() {
Shadowbox.newOpen = Shadowbox.open;
Shadowbox.open = function(o) {
if (document.getElementById("sb-container").addEventListener) {
document.getElementById("sb-container").addEventListener('DOMMouseScroll', Drupal.Gallery.wheel, false);
}
document.getElementById("sb-container").onmousewheel = Drupal.Gallery.wheel;
this.newOpen(o);
$("#sb-container").append('');
if (Shadowbox.gallery.length > 1) {
var html = '
';
for (i = 0; i < Shadowbox.gallery.length ;i++) {
if (Shadowbox.gallery[i]['content'] == $(o).attr("href")) {
if (i < 1) {
var first = true;
} else {
var first = false;
}
if ((i + 2) > Shadowbox.gallery.length) {
var last = true;
} else {
var last = false;
}
var cl = 'active';
if (!last && Shadowbox.gallery[i + 1]) {
var next = Shadowbox.gallery[i + 1];
}
if (!first && Shadowbox.gallery[i - 1]) {
var previous = Shadowbox.gallery[i - 1];
}
} else {
var cl = '';
}
html += ' ';
}
html += '
';
$("#sb-container").append(html);
$("#sb-container").append('');
// Next photo
var nextHtml = '';
if (next) {
Drupal.Gallery.nextPhoto(next);
}
var previousHtml = '';
if (previous) {
Drupal.Gallery.previousPhoto(previous);
}
if (first) {
$("#sb-controls-left").css("opacity", 0.2);
}
if (last) {
$("#sb-controls-right").css("opacity", 0.2);
}
}
};
Shadowbox._change = Shadowbox.change;
Shadowbox.change = function(index) {
if (index == -1 || Shadowbox.gallery.length == index) {
return
}
$("#sb-next-photo, #sb-previous-photo").remove();
if (index < 1) {
$("#sb-controls-left").fadeTo(200, 0.2).css("cursor", "default");
} else {
$("#sb-controls-left").fadeTo(200, 1).css("cursor", "pointer");
if (Shadowbox.gallery.length == index) {
Drupal.Gallery.previousPhoto(Shadowbox.gallery[index - 2]);
} else {
Drupal.Gallery.previousPhoto(Shadowbox.gallery[index - 1]);
}
}
if ((index + 2) > Shadowbox.gallery.length) {
$("#sb-controls-right").fadeTo(200, 0.2).css("cursor", "default");
} else {
$("#sb-controls-right").fadeTo(200, 1).css("cursor", "pointer");
if (index != -1) {
Drupal.Gallery.nextPhoto(Shadowbox.gallery[index + 1]);
} else {
Drupal.Gallery.nextPhoto(Shadowbox.gallery[index + 2]);
}
}
if (index < Shadowbox.gallery.length && index != -1) {
$("#sb-controls-list li").removeClass("active");
$("#sb-controls-list-" + index).addClass("active");
}
return this._change(index);
};
Shadowbox._next = Shadowbox.next;
Shadowbox.next = function() {
Shadowbox._next();
};
Shadowbox._previous = Shadowbox.previous;
Shadowbox.previous = function() {
return Shadowbox._previous();
};
Shadowbox._close = Shadowbox.close;
Shadowbox.close = function() {
$(window).unbind(".gallery");
$("#sb-container").fadeOut(500, function(){
$("#sb-container").find(".controls").remove();
Shadowbox._close();
});
};
};
/**
* Next photo
*/
Drupal.Gallery.nextPhoto = function(object) {
if (!object) return;
$("#sb-container").append('');
var image = new Image();
$(image).load(function(){
$("#sb-next-photo a img").remove();
$("#sb-next-photo a").append(this);
Drupal.Gallery.nextPhotoDimensions();
}).error(function(){
//
}).attr("src", object.content);
};
/**
*
*/
Drupal.Gallery.nextPhotoDimensions = function() {
height = $("#sb-next-photo img").innerHeight() / 2;
width = $("#sb-next-photo img").innerWidth() / 2;
if (height > ($(window).height() / 2))
height = $(window).height() / 2;
$("#sb-next-photo img")
.attr("height", height)
.attr("width", width);
fromtop = ($(window).height() - $("#sb-container .sb-next-photo img").height()) / 2;
$("#sb-next-photo").css("top", fromtop + 'px');
};
/**
* Previous photo
*/
Drupal.Gallery.previousPhoto = function(object) {
if (!object) return;
$("#sb-container").append('');
var image = new Image();
$(image).load(function(){
$("#sb-previous-photo a img").remove();
$("#sb-previous-photo a").append(this);
Drupal.Gallery.previousPhotoDimensions();
}).error(function(){
//
}).attr("src", object.content);
};
/**
*
*/
Drupal.Gallery.previousPhotoDimensions = function() {
height = $("#sb-container #sb-previous-photo img").innerHeight() / 2;
width = $("#sb-container #sb-previous-photo img").innerWidth() / 2;
if (height > ($(window).height() / 2))
height = $(window).height() / 2;
$("#sb-container #sb-previous-photo img")
.attr("height", height)
.attr("width", width);
fromtop = ($(window).height() - $("#sb-container #sb-previous-photo img").height()) / 2;
$("#sb-container #sb-previous-photo").css("top", fromtop + 'px');
};
/**
*
*/
Drupal.Gallery.wheel = function(event) {
if (!event) {
event = window.event;
}
if (event.wheelDelta) {
wheelDelta = event.wheelDelta / 120;
} else if (event.detail) {
wheelDelta = - event.detail / 3;
}
if (wheelDelta == -1) {
Shadowbox.next();
} else {
Shadowbox.previous();
}
if (event.preventDefault) {
event.preventDefault();
}
event.returnValue = false;
};
/**
*
*/
Drupal.behaviors.Gallery = Drupal.Gallery.init;
/*
playback timings (ms):
LoadShardBlock: 1160.382 (3)
esindex: 0.011
captures_list: 1176.078
CDXLines.iter: 11.395 (3)
PetaboxLoader3.datanode: 583.129 (4)
exclusion.robots: 0.416
exclusion.robots.policy: 0.399
RedisCDXSource: 0.682
PetaboxLoader3.resolve: 655.249 (3)
load_resource: 106.058
*/