$(function(){
	$('#gallery a').css('cursor', 'pointer');
	
	$('#gallery a.next').click(function(){
		if (parseInt($('#gallery ul').css('margin-left')) > (($('#gallery li').length - 7) * 76 - 10) * -1)
		{
			$(this).removeClass('disabled');
			$('#gallery a.prev').removeClass('disabled');
			$('#gallery ul').css('margin-left', (parseInt($('#gallery ul').css('margin-left')) - 76) + 'px' );
		}
		else
		{
			$(this).addClass('disabled');
		}
	});
	
	$('#gallery a.prev').click(function(){
		if (parseInt($('#gallery ul').css('margin-left')) < 0)
		{
			$(this).removeClass('disabled');
			$('#gallery a.next').removeClass('disabled');
			$('#gallery ul').css('margin-left', (parseInt($('#gallery ul').css('margin-left')) + 76) + 'px' );
		}
		else
		{
			$(this).addClass('disabled');
		}
	});
	
	$('#gallery ul li a').click(function(){
		$('#gallery #large').attr('src', $(this).attr('href') + '/large.jpg');
		return false;
	});
	
	$('#colors .front').click(function(){
		$('#colors #large').attr('src', $('#colors ul li.active a:first').attr('href') + '/front_thumb.jpg');
		$('#colors .back').removeClass('active');
		$(this).addClass('active');
	});
	$('#colors .back').click(function(){
		$('#colors #large').attr('src', $('#colors ul li.active a:first').attr('href') + '/back_thumb.jpg');
		$('#colors .front').removeClass('active');
		$(this).addClass('active');
	});
	$('#colors ul li a').click(function(){
		$('#colors ul li').removeClass('active');
		$(this).parent().addClass('active');
		
		$('#colors span.name').text($(this).attr('title'));
	
		if ($('#colors .back').is('.active'))
		{
			file = 'back_thumb.jpg';
		}
		else
		{
			file = 'front_thumb.jpg';
		}
		$('#colors #large').attr('src', $(this).attr('href') + '/' + file);
		return false;
	});
});
