var current_index;	
var image_descriptions = new Array();
image_descriptions['01_abaondonedcity.gif']  = 'Chickenfoot: Music Video';
image_descriptions['citywide.gif']  = 'Chickenfoot: Music Video';
image_descriptions['alley.gif']  = 'Chickenfoot: Music Video';
image_descriptions['monkeyisland01.gif']  = 'Monkey Island 2: Video Game';
image_descriptions['monkeyisland02.gif']  = 'Monkey Island 2: Video Game';
image_descriptions['monkeyisland03.gif']  = 'Monkey Island 2: Video Game';
image_descriptions['monkeyisland04.gif']  = 'Monkey Island 2: Video Game';
image_descriptions['monkeyisland05.gif']  = 'Monkey Island 2: Video Game';
image_descriptions['halcyon.gif']  = 'Film Concept Art';
image_descriptions['08_cavebackground.gif']  = 'Grossology: TV Series';
image_descriptions['legocover.gif']  = 'LEGO Product Catalog Cover';
image_descriptions['maneli.gif']  = 'Maneli Jamal, Oil 13x24"';
image_descriptions['harbourmatte.gif'] = '3D Matte Painting from Plate';
image_descriptions['05_labcheese_BG.gif'] = 'Grossology Background';
image_descriptions['24_minie.gif'] 			= 'Design by Nick Kilislian';
image_descriptions['23_hatch.gif'] 			= 'Design by Nick Kilislian';
image_descriptions['13_backyardigansposter.gif']  = 'Backyardigans: TV Series';
image_descriptions['17_backyardiganstasha.gif']  = 'Backyardigans: TV Series';
image_descriptions['04_iggy.gif']  = 'Iggy Arbuckle: TV Series';
image_descriptions['mudpit_docks.gif']  = 'Mudpit: TV Series';
image_descriptions['mudpit_docks2.gif']  = 'Mudpit: TV Series';
image_descriptions['mudpit_bandroom.gif']  = 'Mudpit: TV Series';
image_descriptions['castlewalls.gif']  = 'Personal Matte Painting';
image_descriptions['citydownshot.gif']  = 'Video Game 3D Matte Painting';
image_descriptions['01_sarah.gif']  = 'Sarah, Oil 18x24"';
image_descriptions['fernando.gif']  = 'Fernando Rego, Oil 30x40"';
image_descriptions['jessie.gif']  = 'Jessie, Oil 24x30"';
image_descriptions['03_jaquelynne.gif']  = 'Jaquelynne, Oil 16x20"';
image_descriptions['02_bridgetandveronica.gif']  = 'Sisters, Oil 30x40"';
image_descriptions['06_gabriel.gif']  = 'Gabriel, Oil 9x12"';
image_descriptions['05_logan.gif']  = 'Logan, Oil 9x12"';
image_descriptions['11_modelinclass.gif']  = 'Classroom Study, Oil 8x10"';
image_descriptions['08_adam.gif']  = 'Adam, Oil 9x12"';
image_descriptions['18_pleinair_oldboat.gif']  = 'Plein Air, Oil 6x8"';
image_descriptions['pleinairs.gif']  = 'Plein Air Studies, Oil & Watercolour';
image_descriptions['16_landscape_sketches.gif']  = 'Small Plein Air Studies, Oil';
image_descriptions['europe1.gif']  = 'Sketchbook Studies, Watercolour/Gouache';
image_descriptions['europe2.gif']  = 'Sketchbook Studies, Watercolour/Gouache';
image_descriptions['flipkey.gif']  = '3D Character Color Key';



	
	$(document).ready(function () 
	{
		//gather all our galleries into an array
		galleries = $('table.gallery');
		
		//iterate through our galleries
		for(var i = 0; i < galleries.length; i++)
		{
			//determine which gallery is active by default
			if(galleries[i].className == 'active gallery')
			{
				//keep track of where we are
				current_index = i;
				
				break;
			}
		}
		
		//hide description box
		$("#description").css("display", "none");
		
		//display the default image 
		$.showImage($("img.active").attr("src"));

		//show only the active gallery, hide others
		$("table:not(.active).gallery").css("display","none");
		
		//show default thumbnail as active and mark it as default for that gallery
		$("td > img:not(.active)").fadeTo("slow", 0.33)
 
		//preload gallery images!
		var gallery_images = $("table.active tr td > img");

		for(i = 0; i < gallery_images.length; i++)
		{
			$("<img />").attr("src", gallery_images[i].src.replace("gif", "jpg"));
		}
		
		//image in gallery was clicked
		$(".gallery td > img").click(function() 
		{
			if(!$(this).hasClass("active"))
			{ 
				image_path = $(this).attr("src").split("/");
				if(image_descriptions[image_path[1]] != null)
				{
					$("#description").css("display", "block");
					$("#description").text(image_descriptions[image_path[1]]);
				}
				
				else
				{
					$("#description").css("display", "none");
				}
				//if()
				//remove the current active thumbnail
				$("table img.active").fadeTo("slow", .33).removeClass("active");

				//show this thumbnail as active
				$(this).fadeTo("slow", 1);
				
				//see it active
				$(this).addClass("active");

				//display new image
				$.showImage($(this).attr("src"));
			}
		});

		//thumbnail hover function
		$(".gallery td > img").hover(function() 
		{
			$(this).fadeTo("fast", 1)
		},

		//thumbnail hover-off function
		function () 
		{
			if(!$(this).hasClass("active"))
			{
				$(this).fadeTo("fast", .33);
			}
		});



	});
   
	//assign image to the #image div based on the thumbnail src
	$.showImage = function(src)
	{
		$("#image").children("img").remove();
		var new_image = $(document.createElement("img"));
		new_image.attr("src", src.replace("gif", "jpg"));
		$("#image").append(new_image.fadeIn("slow"))
	};
   
	$.swapGallery = function(direction)
	{
		//move our index over accordingly (previous will move it back one, next will move it forward)
		current_index += direction == 'prev' ? - 1 : 1;
		
		//determine whether index is out of bounds
		if(current_index < 0 || current_index >= galleries.length)
		{
			current_index += direction == 'prev' ? 1 : -1;
		}
		
		else
		{
			//make old gallery unactive
			$("table.active").css("display", "none");
			$("table.active").removeClass("active");
			
			//make new gallery active
			galleries[current_index].className = 'active gallery';
			
			//make gallery visible
			$("table.active").css("display","block");
			
			//preload new galleries images
			var gallery_images = $("table.active tr td > img");

			for(i = 0; i < gallery_images.length; i++)
			{
				$("<img />").attr("src", gallery_images[i].src.replace("gif", "jpg"));
			}
			
		}
	}

	

