(function () {
function showGalleryImage(oIndex) {
for( var i = this.imLIs.length - 1; i >= 0; i-- ) {
this.imLIs[i].style.display = ( i == oIndex ) ? '' : 'none';
this.LIs[i+1].className = ( i == oIndex ) ? 'activeimage' : '';
}
this.currentImage = oIndex;
}
function changeGalleryImageBy(oStep) {
this.currentImage += oStep;
if( this.currentImage >= this.imLIs.length ) {
this.currentImage = 0;
}
if( this.currentImage < 0 ) {
this.currentImage = this.imLIs.length - 1;
}
this.showGalleryImage(this.currentImage);
}
function prepareGalleries() {
if( preparedGalleries ) { return; }
preparedGalleries = true;
if( !document.getElementById || !document.getElementsByTagName || !document.createElement || !document.childNodes ) { return; }
var allULs = document.getElementsByTagName('ul');
for( var i = allULs.length - 1; i >= 0; i-- ) {
if( allULs[i].className.match(/(^| )galleryimages($| )/) ) {
turnIntoGallery(allULs[i],allULs[i].getElementsByTagName('li'));
}
}
}
function createLI(parul,vistext,doclick,liindex) {
var li, a;
parul.appendChild(li = document.createElement('li'));
li.appendChild(a = document.createElement('a'));
a.liindex = liindex;
a.href = 'javascript:void(0);';
a.onclick = doclick;
a.appendChild(document.createTextNode(vistext));
if( vistext != '>>' ) {
parul.appendChild(document.createTextNode(' '));
} else if( window.opera ) {
a.insertBefore(document.createElement('span'),a.firstChild.splitText(1)).appendChild(document.createTextNode('='));
a.childNodes[1].style.display = 'none';
}
}
function turnIntoGallery(oUL,oLIs) {
if( !oLIs.length ) { return; }
var imgs = oUL.getElementsByTagName('img'), imlist;
for( var i = 0; i < imgs.length; i++ ) {
galleryCache[i] = new Image();
galleryCache[i].src = imgs[i].src;
}
oUL.parentNode.insertBefore(imlist = document.createElement('ul'),oUL);
imlist.className = 'galleryimagelist';
imlist.currentImage = 0;
imlist.showGalleryImage = showGalleryImage;
imlist.changeGalleryImageBy = changeGalleryImageBy;
imlist.imLIs = oLIs;
if( window.opera ) {
imlist.onmousedown = function () { return false; };
}
createLI(imlist,'<<',function () { this.parentNode.parentNode.changeGalleryImageBy(-1); return false; });
imlist.appendChild(document.createTextNode(' '));
for( var j = 0; j < oLIs.length; j++ ) {
createLI(imlist,j+1,function () { this.parentNode.parentNode.showGalleryImage(this.liindex); return false; },j);
}
createLI(imlist,'>>',function () { this.parentNode.parentNode.changeGalleryImageBy(1); return false; });
imlist.LIs = imlist.getElementsByTagName('li');
imlist.showGalleryImage(0);
}
var galleryCache = [], preparedGalleries = false;
if( window.addEventListener ) {
window.addEventListener('DOMContentLoaded',prepareGalleries,false);
window.addEventListener('load',prepareGalleries,false);
} else if( document.addEventListener ) {
document.addEventListener('DOMContentLoaded',prepareGalleries,false);
document.addEventListener('load',prepareGalleries,false);
} else if( window.attachEvent ) {
window.attachEvent('onload',prepareGalleries);
}
})();