document.observe("dom:loaded", function() {

	var per_page = 3;
	var total_pages = Math.ceil(thumbnails_count / 3);
	var current_page = 1;
	var step = 83 * per_page;

	$('thumbs-holder-right').observe('click', function(){
		if(current_page < total_pages){
			new Effect.Move($('thumbs-holder'),{x: -(step), y: 0, duration: 1, mode:'relative'});
			current_page = current_page + 1;
		}
	});

	$('thumbs-holder-left').observe('click', function(){
		if(current_page > 1){
			new Effect.Move($('thumbs-holder'),{x: step, y: 0, duration: 1, mode:'relative'});
			current_page = current_page - 1;
		}
	});
	new MAG.Preview;
//	$('thumbs-holder').childElements().each(function(elem){
//		elem.observe('click', function(){
//			$('big-pic').src = elem.src.replace('_results_thumb','_large_thumb');
//		});
//	});
//	
//	$('big-pic').observe('click', function(event){
//		var as = $$('.the_thumbs');
//		var lightbox_obj = null;
//		as.each(function(elem){
//			if(elem.href == $('big-pic').src.replace('_large_thumb', '_preview_thumb')){
//				
//			}
//		});
//	});


});

var MAG = Object.extend({}, MAG || {});
MAG.Preview = Class.create();
MAG.Preview.prototype = {
	initialize: function(options)
	{
		MAG.MagPreview = this;

		this.options = {
			preview_element: $('big-pic'),
			objects: $$('.the_thumbs')
		};
		Object.extend(this.options, options || {});

		if(this.options.objects.length) this.attach_event();

		return true;
	},

	attach_event: function()
	{
		this.options.objects.each(function(el){
			el.observe('click', this.click_object.bind(this));
		}.bind(this));
	},

	click_object: function(e)
	{
		var el = Event.element(e);
		this.options.preview_element.src = el.src.toString().replace('_results_thumb', '_large_thumb');
		this.options.preview_element.parentNode.href = el.src.toString().replace('_results_thumb', '_preview_thumb');
		Event.stop(e);
	}
};

//document.observe('dom:loaded', function(){);