$(function() {
		
	// Create variables
	var num_projects = $('.gallery_image').children().size();
	var thumb_list = $('#gallery li');
	var current_project = 1;
	
	//console.log($('.project:nth-child(3)'));
    //console.log(num_projects);
	//console.log(thumb_list.size());
	
	// Loop through the projects and set their visibility
	for (var e = 0; e < num_projects; e++) {
		if (e!=0){
			$('.gallery_image:nth-child(' + (e+1) + ')').hide();
		}
		
		// Set the backgrounds of the thumbnails
		//var thumbpath = $('#gallery li:nth-child(' + (e+1) + ')').attr("thumb");
		//$('#gallery li:nth-child(' + (e+1) + ')').css('background','url('+thumbpath+')');
        
        var thumbpath = $(thumb_list[e]).attr("thumb");
		$(thumb_list[e]).css('background','url('+thumbpath+')');
	}
	
	// Mouse over & out functions
	$("#gallery li").hover(
      function () {
		$(this).css('background-position','0px -75px');
      }, 
      function () {
		$(this).css('background-position','0px 0px');
      }
    );
	
	// Thumb click function
	$("#gallery li").click(function () {

		// Swap the projects
		swapProjects(thumb_list.index(this));
		
    });
	
	// Function used to swap projects
	function swapProjects(pos) {
		
		var curr_pic = $('.gallery_image:eq(' + (current_project) + ')');
		var new_pic = $('.gallery_image:eq(' + (pos) + ')');
		
		var image_list = $(new_pic).parent().children();
		
		for (var e = 0; e < image_list.size(); e++) {

			if($(image_list[e]) != new_pic.children()){
			
				// Fade out the current project
				$(image_list[e]).fadeOut("slow");
			
			}
		}

		// Stop any current animations
		//$(new_pic).stop(false);
			
		// Fade in the new project
		$(new_pic).fadeIn("slow");
	}
	
	// Mouse over & out functions
	$("#gallery_menu_container li").hover(
      function () {
        //$(this).css({'border' : 'yellow', 'border-style' : 'solid', 'border-width' : '5px'})
      }, 
      function () {
      	//$(this).css('border','none')
      }
    );
	
	$("#gallery_menu_container li").click(function(event) {
	  event.preventDefault();
	  window.location = $(this).attr("url");
	  //console.log($(this).attr("url"));
	});
});