// class for photo gallert
var Gallery = new Class({
	options: {},
	
	initialize: function(options){
		this.setOptions(options);		
		this.photos_div = $('photos');
		this.init_photos();	
	},
	
	init_photos: function() {
		
		// reload Slimbox
		Slimbox.scanPage();
		
		// extend pager links
		$$('.photoPager a').each(function(btn){
			btn.onclick = this.photos_update.bind(this, btn);
		}, this);
		
	},
		
	photos_update: function(btn) {
			
		// get the url for the updates
		var url = btn.href + '&ajax_update=photos';
		url = this.cache_bust(url);
		
		// send the request
		var myHTMLRequest = new Request.HTML({
			onSuccess: this.photos_update_success.bind(this),
			headers: {
				'X-Update-Block': 'photos'
			}
		}).get(url);
		
		return false;
	},
	
	photos_update_success: function(responseTree, responseElements, responseHTML, responseJavaScript) {
		this.photos_div.set('html', responseHTML);
		this.init_photos();		
	},
	
	cache_bust: function(url) {
		if (url.indexOf("?") != -1)
			url += "&";
		else
			url += "?";
		url += 'rnd=' + Math.random()*99999;
		return url;
		
	}	
	
	
});

Gallery.implement(new Options, new Events);

window.addEvent('domready', function() {
	var MyGallery = new Gallery();
});

