_Lightbox = function(_obW) {
this.obW = _obW;
this.div_background = null;
this.div_container = null;
this.div_photos = null;
this.image = null;
this.loading = null;
this.o = this;
var id = this.obW.id;
this.destroy = function() {
this.div_background.parentNode.removeChild(this.div_background);
this.div_container.parentNode.removeChild(this.div_container);
this.div_photos.parentNode.removeChild(this.div_photos);
delete this;
}
this.init = function() {
var img_href = document.getElementById(id);
var ob = this.o;
var href = img_href;
var body = document.getElementsByTagName('body')[0];
this.loading = document.createElement('span');
this.loading.className = 'gallery_loading';
this.obW.appendChild(this.loading);
this.image = new Image();
this.image.onload = function () {
ob.loading.parentNode.removeChild(ob.loading);
ob.loading = null;
ob.div_background = document.createElement('div');
ob.div_background.className = 'gallery_background';
ob.div_background.style.width = window.innerWidth;
ob.div_background.style.height = window.innerHeight;
ob.div_background.title = "Kliknij aby zamknąć";
ob.div_background.onclick = function() {
ob.destroy();
}
body.appendChild(ob.div_background);
ob.div_container = document.createElement('div');
ob.div_container.className = 'gallery_container';
ob.div_container.id = 'gallery_container';
ob.div_container.style.width = 92 + '%';
ob.div_container.style.marginLeft = -46 + '%';
ob.div_photos = document.createElement('div');
ob.div_photos.className = 'gallery_photos';
ob.div_photos.id = 'gallery_container';
ob.div_photos.appendChild(ob.image);
var btnClose = document.createElement('input');
btnClose.type = "button";
btnClose.className = "close";
btnClose.value = "x";
btnClose.onclick = function() {
ob.destroy();
}
ob.div_container.appendChild(btnClose);
var before = document.createElement('input');
before.type = "button";
before.className = "before";
before.id = "before";
before.style.marginTop = -30 + 'px';
before.value = "<";
before.onclick = function() {
$("#before").click(function() {
$('#gallery_container').fadeToggle(200);
});
if (id == 0) {
}
else{
ob.destroy();
id--;
ob.init();
}
}
ob.div_container.appendChild(before);
var next = document
.createElement
('input'); next.style
.marginTop
= -30 + 'px'; next.onclick
= function() { var i = document.getElementById("gallery").getElementsByTagName("img").length;
$("#next").click(function() {
$('#gallery_container').fadeToggle(200);
});
if (id == i-1) {
}
else{
ob.destroy();
id++;
ob.init();
}
}
ob
.div_container
.appendChild
(next);
body.appendChild(ob.div_container);
ob.div_container.appendChild(ob.div_photos);
}
this.image.src = img_href;
}
this.init();
}
Node.prototype.lightbox = function() {
if (!(new RegExp('^.+jpg|png|jpeg|gif$', 'gi')).test(this.href)) return
this.onclick = function() {
var lighbox = new _Lightbox(this);
return false;
}
}
window.onload = function() {
var a = document.getElementsByTagName('a');
for (i=0; i<a.length; i++) {
if (a[i].className == 'gallery_photo') {
a[i].lightbox();
}
}
}