// JavaScript Document

$(function() {	
	$('.images .next').click(function(event) {
		event.preventDefault();
		$(this).parents(".images").nextImage();
	});
	$('.images .prev').click(function(event) {
		event.preventDefault();
		$(this).parents(".images").prevImage();
	});
	$("a.iframe").fancybox({
		'width': 880,
		'height': 544,
		'hideOnContentClick': false,
		'overlayColor': '#000'
	});
});

$.fn.nextImage = function() {
	var curImg = $(this).children('div.current');
	var nextImg = curImg.next('.image');
	if (nextImg.length == 0) {
		nextImg = $(this).children('.image:first');
	}
	swapImage(curImg,nextImg);
}

$.fn.prevImage = function() {
	var curImg = $(this).children('div.current');
	var nextImg = curImg.prev('.image');
	if (nextImg.length == 0) {
		nextImg = $(this).children('.image:last');
	}
	swapImage(curImg,nextImg);
}

function swapImage(curImg,nextImg) {
	curImg.addClass('previous').animate({opacity:0}, 500).removeClass('current');
	nextImg.css({opacity: 0}).addClass('current').animate({opacity: 1.0}, 500, 
		function() {
			curImg.removeClass('previous');
		}
	);	
}
