// terms and conditions support
var ProdGalleryNav = {};
ProdGalleryNav.init = function() {
	this.ps = $$('#photo-film div p');
	this.curr = 0;
	this.idx = 0;
	this.ps[this.curr].addClass('on');
	
	if (this.ps.length > 4) {
		this.scroller = $('photo-film');
		this.scroller.scrollLeft = 0;
		this.fx = new Fx.Scroll('photo-film');
		
		$('photo-film-nav').getElement('a.left').setStyle('display', 'none');
		$$('#photo-film-nav a').addEvent('click', this.navClick.bind(this));
	}
	else
		$('photo-film-nav').getElements('a').setStyle('display', 'none');
		
	$$('#photo-film img').addEvent('click', this.imgClick.bind(this));
};

ProdGalleryNav.navClick = function(event) {
	var t = event.target;
	
	this.fx.cancel();
	this.idx = (Math.floor(this.idx / 4) + (t.hasClass('right') ? 1 : -1)) * 4;
	this.idx = this.idx > this.ps.length - 1 ? this.ps.length - 1 : this.idx;
	this.fx.toElement(this.ps[this.idx]);
	
	if (this.idx > 0)
		$('photo-film-nav').getElement('a.left').setStyle('display', 'inline');
	else
		$('photo-film-nav').getElement('a.left').setStyle('display', 'none');
	if (this.idx + 3 >= this.ps.length - 1)
		$('photo-film-nav').getElement('a.right').setStyle('display', 'none');
	else
		$('photo-film-nav').getElement('a.right').setStyle('display', 'inline');
	
	event.stop();
};

ProdGalleryNav.imgClick = function(event) {
	var t = event.target;
	
	this.ps[this.curr].removeClass('on');
	this.curr = t.get('id').replace(/p/, '');
	this.ps[this.curr].addClass('on');
	
	ImgLoader.add({ wrapper: 'photo-film-large', src: t.get('src').replace(/-f/, '-l') });
};