$(function(){
	$('.galImages div').each(function(num){
		$('span.total').text(num + 1);
		findFirst();
		getViewingNum();
	});
	$('a.next').click(function(){
		var imgWidth = $('.galImages div.active').width();
		var calcWidth = '-' + (imgWidth + 28) + 'px';
		$('.galImages div.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 div.active').prev().width();
		var calcWidth = imgWidth + 28 + 'px';
		$('.galImages div.active:not(:first-child)').prev().animate({marginLeft:0},600).addClass('active').next().removeClass('active');
		getViewingNum();
		findFirst();
		findLast();
		return false;
	});
	function getViewingNum(){
		var numOf = $('div.active').attr('id').slice(2);
		$('span.viewin').text(numOf);
	}
	function findLast(){
		$('.galImages div: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 div:first').hasClass('active') ? $('a.prev').css({opacity:'0.4', textDecoration:'none',cursor:'default'}) : $('a.prev').css({opacity:'1.0', textDecoration:'underline',cursor:'pointer'});
	}
	$('.galImages div').click(function(){
		$('a.next').trigger('click');
	});
});

