2008-05-22 21:43:42 +00:00
|
|
|
var Album = {
|
|
|
|
|
|
|
|
|
|
pictures: [],
|
2008-11-24 19:54:24 +00:00
|
|
|
queue: { position: 'end', scope: 'album' },
|
2008-05-22 21:43:42 +00:00
|
|
|
|
|
|
|
|
cubic: function(pos) {
|
|
|
|
|
pos /= 0.5;
|
|
|
|
|
return pos < 1 ? 0.5*pos*pos*pos : 0.5*((pos-2)*(pos-2)*(pos-2) + 2);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
spacerEvent: function (spacer, direction) {
|
|
|
|
|
var width = (direction < 0 ? _pictures[spacer].width : _pictures[spacer + 1].width) + 65;
|
2008-11-25 06:10:06 +00:00
|
|
|
new Effect.HScroll(width * direction, { queue: Album.queue, duration: 0.5, transition: Album.cubic });
|
2008-05-22 21:43:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
|
|
|
|
|
|
$$('div.picturebox div.picture img').each( function(img, idx) {
|
|
|
|
|
var container = img.parentNode;
|
|
|
|
|
container.addClassName('highlight');
|
|
|
|
|
container.setAttribute('id', 'pic' + idx);
|
|
|
|
|
// var darkener = $(document.createElement('div')).addClassName('darkening').setOpacity(0);
|
|
|
|
|
// container.appendChild(darkener);
|
|
|
|
|
// Event.observe(darkener, 'click', function() {
|
|
|
|
|
// Album.showProduct(this);
|
|
|
|
|
// }.bind(img));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$$('div.spacer-column').each(function(spacer, idx) {
|
|
|
|
|
|
|
|
|
|
spacer.setAttribute('id', 'spacer' + idx);
|
|
|
|
|
|
|
|
|
|
Event.observe(spacer, 'click', function(event) {
|
|
|
|
|
Album.spacerEvent(idx, Event.localPointer(event)[0] < 33 ? 1 : -1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Event.observe(spacer, 'mousemove', function(event) {
|
|
|
|
|
var d = Event.localPointer(event)[0]<33 ? '-65' : '-130';
|
|
|
|
|
spacer.style.backgroundPosition = d + 'px 0px';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Event.observe(spacer, 'mouseout', function(event) {
|
|
|
|
|
spacer.style.backgroundPosition = '0px 0px';
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
initializeThumbsFromPictureList: function(list) {
|
|
|
|
|
|
|
|
|
|
_pictures = list;
|
|
|
|
|
|
|
|
|
|
var imgtags = $$('div.picturebox div.picture img');
|
|
|
|
|
|
|
|
|
|
var totalWidth = 0;
|
|
|
|
|
var pictureCount = 0;
|
|
|
|
|
|
|
|
|
|
imgtags.each(function(img, index) {
|
|
|
|
|
var container = img.parentNode;
|
|
|
|
|
var picturebox = container.parentNode;
|
2008-11-24 19:54:24 +00:00
|
|
|
// var darkener = img.next();
|
2008-05-22 21:43:42 +00:00
|
|
|
|
|
|
|
|
var picture = _pictures[container.id.substr(3)];
|
|
|
|
|
$(img).setStyle({ width: picture.width + 'px', height: picture.height + 'px' });
|
|
|
|
|
$(container).setStyle({ width: picture.width + 'px' });
|
|
|
|
|
$(picturebox).setStyle({ width: picture.width + 'px' });
|
2008-11-25 06:10:06 +00:00
|
|
|
$(container).onclick = function() { Album.moveIntoView(container); };
|
2008-05-22 21:43:42 +00:00
|
|
|
totalWidth += picture.width;
|
|
|
|
|
pictureCount += 1;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
totalWidth += (pictureCount - 1) * 65;
|
|
|
|
|
|
|
|
|
|
$('layout').setStyle({ width: totalWidth + 'px' });
|
|
|
|
|
$('content').setStyle({ width: totalWidth + 'px' });
|
|
|
|
|
$('page-body').setStyle({ width: (totalWidth + 2 * 65) + 'px' });
|
|
|
|
|
|
|
|
|
|
Loader.reset();
|
|
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
this._loaderPause = false;
|
|
|
|
|
this.loadVisibleThumbs();
|
2008-11-25 06:10:06 +00:00
|
|
|
}.bind(this), 500);
|
2008-05-22 21:43:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
loadVisibleThumbs: function() {
|
|
|
|
|
|
|
|
|
|
if (this._loaderPause) return;
|
|
|
|
|
if (this._loaderTimeout) clearTimeout(this._loaderTimeout);
|
|
|
|
|
|
|
|
|
|
this._loaderTimeout = setTimeout(function() {
|
|
|
|
|
|
|
|
|
|
var w = Position.getPageSize().window.width;
|
|
|
|
|
|
|
|
|
|
var visibles = [];
|
|
|
|
|
$$('div.picturebox div.picture img').each(function(img) {
|
|
|
|
|
|
|
|
|
|
var container = img.parentNode;
|
|
|
|
|
var x0 = Position.page(container)[0];
|
|
|
|
|
var picture = _pictures[container.id.substr(3)];
|
|
|
|
|
var x1 = x0 + picture.width;
|
|
|
|
|
if ((x0 >= 0 && x0 < w) || (x1 >=0 && x1 < w)) {
|
|
|
|
|
visibles.push(img);
|
|
|
|
|
} else {
|
|
|
|
|
Loader.remove(picture.url);
|
2008-11-24 19:54:24 +00:00
|
|
|
img.src = 'assets/empty.gif';
|
2008-05-22 21:43:42 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
visibles.each(function(img, idx) {
|
|
|
|
|
|
|
|
|
|
var id = img.parentNode.id;
|
|
|
|
|
var picture = _pictures[id.substr(3)];
|
|
|
|
|
|
|
|
|
|
if (img.src == picture.url) return;
|
|
|
|
|
|
|
|
|
|
var imageObj = picture.url;
|
|
|
|
|
|
|
|
|
|
if (Loader.isQueued(imageObj)) return;
|
|
|
|
|
|
2008-11-24 19:54:24 +00:00
|
|
|
// alert('Loading: ' + imageObj + '\nsrc: ' + img.src + '\nurl: ' + picture.url + '\nmatch: ' + img.src.match('assets/empty\.gif$') + '\nloader: ' + Loader.isQueued(imageObj));
|
2008-05-22 21:43:42 +00:00
|
|
|
|
|
|
|
|
// $(img).setStyle({ position: 'relative', left: ('-' + picture.width + 'px') });
|
|
|
|
|
Loader.cacheOrLoad(imageObj, {
|
|
|
|
|
|
|
|
|
|
onComplete: function(obj) {
|
|
|
|
|
// $(img).setStyle({ position: 'relative', left: '0px'}).setOpacity(0);
|
2008-11-24 19:54:24 +00:00
|
|
|
img.setOpacity(0);
|
|
|
|
|
// alert(obj);
|
2008-05-22 21:43:42 +00:00
|
|
|
img.src = obj;
|
2008-11-25 06:10:06 +00:00
|
|
|
new Effect.Opacity(img, { from: 0, to: 1, delay: 0.1, transition: Album.cubic, duration: 0.4 });
|
2008-05-22 21:43:42 +00:00
|
|
|
}});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}, 100);
|
|
|
|
|
},
|
|
|
|
|
|
2008-11-25 06:10:06 +00:00
|
|
|
moveIntoView: function(container) {
|
|
|
|
|
|
|
|
|
|
container = $(container);
|
|
|
|
|
var picture = _pictures[container.id.substr(3)];
|
2008-05-22 21:43:42 +00:00
|
|
|
|
|
|
|
|
var windowWidth = Position.getPageSize().window.width;
|
|
|
|
|
var windowLeft = Position.scrollX();
|
|
|
|
|
var windowRight = windowLeft + windowWidth;
|
2008-11-25 06:10:06 +00:00
|
|
|
var pictureboxLeft = Position.page(container)[0] - 32 + windowLeft;
|
|
|
|
|
var pictureboxRight = pictureboxLeft + picture.width;
|
|
|
|
|
|
|
|
|
|
var desiredCenter = (windowLeft + windowRight) / 2;
|
|
|
|
|
var actualCenter = (pictureboxLeft + pictureboxRight) / 2;
|
|
|
|
|
var delta = actualCenter - desiredCenter;
|
|
|
|
|
|
|
|
|
|
new Effect.HScroll(delta, { queue: Album.queue, duration: 0.5, transition: Album.cubic });
|
2008-05-22 21:43:42 +00:00
|
|
|
|
2008-11-25 06:10:06 +00:00
|
|
|
/*
|
2008-05-22 21:43:42 +00:00
|
|
|
if (pictureboxRight > windowRight) {
|
|
|
|
|
if (pictureboxRight > Position.getPageSize().page.width)
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
new Effect.HScrollTo(pictureboxRight - windowWidth, { duration: 0.5, transition: Album.cubic });
|
|
|
|
|
}, 1000);
|
|
|
|
|
else
|
|
|
|
|
new Effect.HScrollTo(pictureboxRight - windowWidth, { queue: Album.queue, duration: 0.5, transition: Album.cubic });
|
|
|
|
|
}
|
|
|
|
|
else if (pictureboxLeft < windowLeft)
|
|
|
|
|
new Effect.HScrollTo(pictureboxLeft, { queue: Album.queue, duration: 0.5, transition: Album.cubic });
|
2008-11-25 06:10:06 +00:00
|
|
|
*/
|
2008-05-22 21:43:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
initializeThumbsLoader: function() {
|
|
|
|
|
Event.observe(window, 'scroll', this.loadVisibleThumbs.bindAsEventListener(this));
|
|
|
|
|
Event.observe(window, 'resize', this.loadVisibleThumbs.bindAsEventListener(this));
|
|
|
|
|
Event.observe(window, 'beforeunload', this.unloadThumbs.bindAsEventListener(this));
|
|
|
|
|
this.loadVisibleThumbs();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
unloadThumbs: function(){
|
|
|
|
|
$$('div.picturebox div.picture img').each(function(image) { image.src = 'assets/empty.gif' });
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|