$(document).ready(function(){

var animation_speed = 600;
var gallery_width = 502;
var image_border = 8;
var num_photos
var bump;
var counter_separator = " of ";
var slideshow_position = 1;

/* path variables */
var gallery_chooser = $("#gallery-chooser");
var gallery_holder = $("#gallery-holder");
var controls = $("#controls");
var heading = $("h2");

$("#gallery-chooser a").click(function(){
	gallery_to_load = $(this).attr("href");
	gallery_name = $(this).text();
	gallery_chooser.slideUp(animation_speed, loadGallery);
	function loadGallery(){
		gallery_holder.load(gallery_to_load).fadeIn(animation_speed);
		controls.fadeIn(animation_speed);
	};
	heading.text(gallery_name);
	slideshow_position = 1;
	bump = -502;
	return false;
});

$("#next a").click(function(){
	var num_photos = $("#gallery-holder li").length;
	if (slideshow_position < num_photos){
		$("#gallery-holder ul").animate(
			{left: bump}, animation_speed
		);
		slideshow_position = slideshow_position + 1;
		bump = bump - gallery_width;
	};
	return false;
});

$("#prev a").click(function(){
	if (bump < -502) {
		bump = bump + (gallery_width * 2);
		$("#gallery-holder ul").animate(
			{left: bump}, animation_speed
		);
		slideshow_position = slideshow_position - 1;
		bump = bump - gallery_width;
	}
	return false;
});

$("#rewind a").click(function(){
		$("#gallery-holder ul").animate(
			{left: image_border}, animation_speed
		);
		bump = (gallery_width * (-1));
		return false;
	});
	
$("#close a").click(function(){
	gallery_holder.fadeOut(animation_speed, showMenu);
	function showMenu(){
		gallery_chooser.slideDown(animation_speed);
	};
	controls.fadeOut();
	heading.text("Choose a gallery");
	return false;
});

});