var DJS = {
	currentPreview: 0,
	previewImages: null,
	noPreview: 0,
	periodicPreview: null
}

window.addEvent('domready', function() {
	DJS.previewImages = $$('div#img-previews img');
	DJS.noPreview = DJS.previewImages.length;
	changePreview(true);
	DJS.periodicPreview = changePreview.periodical(4000, false);
	
	new XtLightbox('div#videos a', {
        adaptors: ['YouTube']
    });

	new XtLightbox('#gallery a.file', {
		loop: true,
		adaptorOptions: {
			Image: {
				lightboxCompat: false
			}
		}
	});
});


var backPreview = function() {
	DJS.previewImages[DJS.currentPreview].tween('opacity', 0.0)

	DJS.currentPreview--;
	
	if(DJS.currentPreview == -1)
		DJS.currentPreview = DJS.noPreview-1;

	DJS.previewImages[DJS.currentPreview].tween('opacity', 0.0, 1.0);
};

var changePreview = function(first) {
	if(!first)
		DJS.previewImages[DJS.currentPreview].tween('opacity', 0.0)

	DJS.currentPreview++;
	
	if(DJS.currentPreview == DJS.noPreview)
		DJS.currentPreview = 0;

	DJS.previewImages[DJS.currentPreview].tween('opacity', 0.0, 1.0);
};
