$(function(){
	$('.galImages img').each(function(num){
		$('span.total').text(num + 1);
		findFirst();
		getViewingNum();
	});
	$('a.next').click(function(){
		var imgWidth = $('.galImages img.active').width();
		var calcWidth = '-' + (imgWidth + 14) + 'px';
		$('.galImages img.active:not(:last-child)').animate({marginLeft:calcWidth},600).removeClass('active').next().addClass('active');
		getViewingNum();
		findFirst();
		findLast();
		return false;
	});
	$('a.prev').click(function(){
		var imgWidth = $('.galImages img.active').prev().width();
		var calcWidth = imgWidth + 14 + 'px';
		$('.galImages img.active:not(:first-child)').prev().animate({marginLeft:0},600).addClass('active').next().removeClass('active');
		getViewingNum();
		findFirst();
		findLast();
		return false;
	});
	function getViewingNum(){
		var numOf = $('img.active').attr('id').slice(1);
		$('span.viewin').text(numOf);
		var textInfo = $('.galImages img.active').attr('alt');
		$('p.info').text(textInfo);
	}
	function findLast(){
		$('.galImages img:last').hasClass('active') ? $('a.next').css({opacity:'0.4', textDecoration:'none',cursor:'default'}) : $('a.next').css({opacity:'1.0', textDecoration:'underline',cursor:'pointer'});
		
	}
	function findFirst(){
		$('.galImages img:first').hasClass('active') ? $('a.prev').css({opacity:'0.4', textDecoration:'none',cursor:'default'}) : $('a.prev').css({opacity:'1.0', textDecoration:'underline',cursor:'pointer'});
	}
	$('.galImages').click(function(){
		$('a.next').trigger('click');
	});
	
});

