$(function() {


	$("a.fancybox").fancybox( {
		zoomSpeedIn : 300,
		zoomSpeedOut : 300,
		overlayShow : true
	});
	
	$('.thumbnail').mouseover(function() {
		var image = '.view-outer .' + $(this).attr('class').split(" ")[0];
	
		if ($(image).css("display") == "none") {
			$('.view').hide();
			$(image).fadeIn('slow');
		}
		

		// clear all hovers
		$('.thumbnail', $(this).closest('div')).css('border', '1px solid #555').removeClass('box');
		// add hover state to one that we are showing;
		$(this).css('border', '1px solid #222').addClass('box');
	});

	$('.photonav a').click(function() {
		var gallery = '.' + $(this).attr('id');
		// creates a selected state
			$('.photonav a').removeClass('selected');
			$(this).addClass('selected');
			
			$('#main div.gallery').hide();
			$(gallery).fadeIn('slow');
		});
		

	var item_width = $('#main .thumbnails').outerWidth();
	var left_value = item_width;

	$("a.left").click(function() {
		var ul = $('.thumbnails ul', $(this).parent().parent());
		//console.log(ul.text());
		var left_indent = parseInt(ul.css('left')) + item_width;
		if (((left_indent - item_width) * -1) <= 0) {
		} else {
			ul.animate( {'left' : left_indent}, 500);
		}
	});

	$("a.right").click( function() {
		var ul = $('.thumbnails ul', $(this).parent().parent());
		//console.log(ul.html());
		var left_indent = parseInt(ul.css('left'))- item_width;
		if (((left_indent + item_width) * -1) >= ul.outerWidth()- item_width) {
		} else {
			ul.animate( {'left' : left_indent}, 500);
		}
	});

});