$(function() {
	// Main Slider
	$('.switcher')
		.localScroll({
	   		target:'#main-carousel',
			axis:'x'
		})
		.find('li').eq(0).addClass('selected');
		
	$('.switcher a')
		.click(function() {
			$(this).parent('li').siblings().removeClass('selected');
			$(this).parent('li').addClass('selected');
		})
	
	// Gallery
	$('#gallery-carousel .thumbs').width($('#gallery .thumbs > div').length * $('#gallery .thumbs > div').width())

	$('#gallery .next').click(function(e) {
		e.preventDefault();
		$('#gallery-carousel').scrollTo('+=540', 500);
	});
	
	$('#gallery .previous').click(function(e) {
		e.preventDefault();
		$('#gallery-carousel').scrollTo('-=540', 500);
	});	
	
	// Flickr
	$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=25249807@N07&lang=en-us&format=json&jsoncallback=?", function(data){
		$.each(data.items, function(i,item){
			$("<img/>").attr("src", item.media.m)
				.appendTo("#flickr .thumbs")
				.wrap("<a href='" + item.link + "'></a>");
		});
		
		imageWidth = $('#flickr .thumbs > a').outerWidth(true);
		imageCount = $('#flickr .thumbs > a').length;
		
		$('#flickr .thumbs').width(imageCount * imageWidth);
	});
	
	$('#flickr .next').click(function(e) {
		e.preventDefault();
		$('#flickr-carousel').scrollTo('+=' + imageWidth, 500);
	});
	
	$('#flickr .back').click(function(e) {
		e.preventDefault();
		$('#flickr-carousel').scrollTo('-=' + imageWidth, 500);
	});
	
})