var MAG = Object.extend({}, MAG || {});
MAG.Pictures = {

	initialize: function(options)
	{
		this.options = {};
		Object.extend(this.options, options || {});

		img = $$('.gallery img');
		this.img = img[0];

		this.parentUl = $$('.gallery ul');
		this.num = $('current');

		prev = $$('.gallery ul .previous_img a');
		this.prev = prev[0];
		next = $$('.gallery ul .next_img a');
		this.next = next[0];

		this.prev.style.visibility = 'hidden';
		this.current = 0;


		$(this.next).observe('click', function (){
			this.next_img();
		}.bind(this));

		$(this.prev).observe('click', function (){
			this.previous_img();
		}.bind(this));

	},

	next_img: function (){
		this.current ++;
		setTimeout(function (){this.img.src = this.options.root+'public/files/'+this.options.img_folder+'/'+this.options.all_imgs[this.current]}.bind(this), 10);

		if (this.current == (this.options.all_imgs.length - 1)){
			this.next.style.visibility = 'hidden';
		}

		this.num.innerHTML = (this.current + 1);
		if(this.prev.style.visibility == 'hidden')this.prev.style.visibility = 'visible';
	},

	previous_img: function (){
		this.current --;
		setTimeout(function (){this.img.src = this.options.root+'public/files/'+this.options.img_folder+'/'+this.options.all_imgs[this.current]}.bind(this), 10);
		if(this.current == 0){
			this.prev.style.visibility = 'hidden';
		}

		this.num.innerHTML = (this.current + 1);
		if(this.next.style.visibility == 'hidden')this.next.style.visibility = 'visible';
	}

};



