
$(function() {
	
	/* 
	 * Set up scrollable gallery
	 * 
	 */
	var scrollable = $("div.scrollable").scrollable({ size: 8 });
	var scrollableApi = scrollable.data('scrollable');
	$('ul.items a').click(function() {
		$('ul.items a').removeClass('current');
		$(this).addClass('current');
		var img = $(this).find('img');
		$('.img img').fadeOut(function() {
			$(this).attr('src', img.attr('src').replace('rc:63:62', 'rc:636:447:FaFaFa'));
			$(this).load(function() { $(this).fadeIn(); });
		});
		
	});
	$('ul.items a:first').click();
	
	$('.img-container .next').click(function(e) {
		e.preventDefault();
		var next = $('ul.items a.current').parent().next();
		if (!next.length) next = $('ul.items li:first');
		next.find('a').click();
		scrollableApi.seekTo($('ul.items li').index($('a.current').parent()));
	});
	
	$('.img-container .previous').click(function(e) {
		e.preventDefault();
		var prev = $('ul.items a.current').parent().prev();
		if (!prev.length) prev = $('ul.items li:last');
		prev.find('a').click();
		var api = scrollable.data('scrollable');
		scrollableApi.seekTo($('ul.items li').index($('a.current').parent()));
		
	});
	
	
	$('#sidebar form.password input.txt').defaultValue({ value: 'Insert your password' });
	
	//$('ul.items').width($('ul.items li').length * 82);
	
});
