/**
 * Initialize the Plag object.
 */
Photos = {
	thumbList: null,
	thumbTotal: null,
	thumbCurrent: null,
    init: function() {
		this.thumbList = $('.thumb-list-wrapper .thumb-list');
		this.thumbTotal = parseInt(this.thumbList.find('.thumb').length - 1);		
		this.thumbCurrent = 0;
		$(this.thumbList.find('.thumb:first')).animate({opacity: '0.3'}, 200);
		
		if ($('.thumb-list-wrapper .thumb-list .thumb').length <= 3) {
			$('.thumb-list-nav-down, .thumb-list-nav-up').each(function(i, el) {
				el = $(el);
				el.css('visibility', 'hidden');
			});
		}
    },
	scrollThumbUp: function() {
		if ((this.thumbCurrent - 1) >= 0) {
			this.thumbCurrent--;			
			this.scrollTo(this.thumbCurrent);
		}
	},
	scrollThumbDown: function() {
		if ((this.thumbCurrent + 1) < this.thumbTotal) {
			this.thumbCurrent++;
			this.scrollTo(this.thumbCurrent);
		}
	},
	scrollTo: function(i) {
		var iNewTop = -(i * 107) + 107;
		
		// Set current thumb
		this.thumbCurrent = i;
		
		// Scroll the thumbs
		if (iNewTop < 107 && iNewTop > -(107*(this.thumbTotal-1))) this.thumbList.animate({'top': iNewTop+'px'}, 200);
	},	
	show: function(sImageUrl) {
		$('#big-photo').attr('src', sImageUrl);

		// Set class on current thumb
		this.thumbList.find('.thumb').animate({opacity: '1'}, 200);		
		$(this.thumbList.find('.thumb')[this.thumbCurrent]).animate({opacity: '0.3'}, 200);
	}
}

// Run any/all init functions.
$(document).ready(function() {	
	Photos.init();
});
