var activeGalleryGroupID;
	var galleryIndex;
	$(document).ready(function(){
		 //on document ready, display the featured item
		 activeGalleryGroupID = "featureItem";
		 galleryIndex = 0;
		 var worksOffset = $("#works").offset();
		 		 
		//$("#worksSubMenu").offset({top: worksOffset.top+100, left: worksOffset.left+20});
		$("#activeItem").hide();
		$("#activeItem").empty();	 
		$("#activeItem").append("<table style='padding:5px;margin:0 auto;' cellspacing='0'><tr><td><img src='"+ $("#featureItem .galleryItem").attr("imageURL") +"' /></td></tr><tr><td>"+ $("#featureItem .galleryItem").attr("imageDescription") +"</td></tr></table>");
		$("#activeItem").delay(500).fadeIn(500);
		 
		$("#about").click(function() {
			$("#textAbout").fadeTo(350,1);
			$("#textNews").hide();
			$("#textResume").hide();
			$("#textLinks").hide();
			$("#textTitle").empty();
			$("#textTitle").append("About Me");
			$("#TextDiv").fadeTo(250,.75,function() { 
				$("#activeItem").fadeTo(250,.25);
				$("#leftBracket").fadeTo(250,0);
				$("#rightBracket").fadeTo(250,0);
				$("#artItemGroupPreview").fadeTo(250,.25);
			});
		});
		$("#news").click(function() {
			$("#textAbout").hide();
			$("#textNews").fadeTo(350,1);
			$("#textResume").hide();
			$("#textLinks").hide();
			$("#textTitle").empty();
			$("#textTitle").append("News");
			$("#TextDiv").fadeTo(250,.75,function() { 
				$("#activeItem").fadeTo(250,.25);
				$("#leftBracket").fadeTo(250,0);
				$("#rightBracket").fadeTo(250,0);
				$("#artItemGroupPreview").fadeTo(250,.25);
			});
		});
		$("#resume").click(function() {
			$("#textAbout").hide();
			$("#textNews").hide();
			$("#textResume").fadeTo(350,1);
			$("#textLinks").hide();
			$("#textTitle").empty();
			$("#textTitle").append("Resume");
			$("#TextDiv").fadeTo(250,.75,function() { 
				$("#activeItem").fadeTo(250,.25);
				$("#leftBracket").fadeTo(250,0);
				$("#rightBracket").fadeTo(250,0);
				$("#artItemGroupPreview").fadeTo(250,.25);
			});
		});
		$("#links").click(function() {
			$("#textAbout").hide();
			$("#textNews").hide();
			$("#textResume").hide();
			$("#textLinks").fadeTo(350,1);
			$("#textTitle").empty();
			$("#textTitle").append("Links");
			$("#TextDiv").fadeTo(250,.75,function() { 
				$("#activeItem").fadeTo(250,.25);
				$("#leftBracket").fadeTo(250,0);
				$("#rightBracket").fadeTo(250,0);
				$("#artItemGroupPreview").fadeTo(250,.25);
				
			});
		});
		$("#works").click(function() {
			$("#textAbout").hide();
			$("#textNews").hide();
			$("#textResume").hide();
			$("#textLinks").hide();
			$("#TextDiv").fadeOut(250,function() {
				$("#activeItem").hide();
				$("#activeItem").empty();	 
				$("#activeItem").append("<table style='padding:5px;margin:0 auto;' cellspacing='0'><tr><td><img src='"+ $("#featureItem .galleryItem").attr("imageURL") +"' /></td></tr><tr><td>"+ $("#featureItem .galleryItem").attr("imageDescription") +"</td></tr></table>");
				$("#activeItem").fadeTo(250,1); 
				$("#leftBracket").fadeTo(250,0);
				$("#rightBracket").fadeTo(250,0);
				$("#artItemGroupPreview").fadeOut(250);
			});
		});
		
		$("#works").mouseenter(function() {
			this.src='images/roll_over_04.png';
			$("#worksSubMenu").stop(true, false); //prevent any fading from occuring
			$("#worksSubMenu").fadeTo(200,1);
		});
		$("#worksSubMenu").mouseenter(function() {
			$(this).stop(true, false); //prevent any fading from occuring
			$(this).fadeTo(100,1); //if fadeout animation was occuring, make sure to fade back to full opacity
		});
		$("#worksSubMenu").mouseleave(function() {
			$(this).delay(3000).fadeOut(200);
		});
		$("#works").mouseleave(function() {
			this.src='images/index_text_04.png';
			$("#worksSubMenu").delay(3000).fadeOut(200);
		});
		$("#about").mouseenter(function() {
			this.src='images/roll_over_06.png';
		});
		$("#about").mouseleave(function() {
			this.src='images/index_text_06.png';
		});
		$("#news").mouseenter(function() {
			this.src='images/roll_over_07.png';
		});
		$("#news").mouseleave(function() {
			this.src='images/index_text_07.png';
		});
		$("#resume").mouseenter(function() {
			this.src='images/roll_over_08.png';
		});
		$("#resume").mouseleave(function() {
			this.src='images/index_text_08.png';
		});
		$("#links").mouseenter(function() {
			this.src='images/roll_over_09.png';
		});
		$("#links").mouseleave(function() {
			this.src='images/index_text_09.png';
		});
		$("#worksSubMenu").children().mouseenter(function() {
			$(this).css("color","white");
		});
		$("#worksSubMenu").children().mouseleave(function() {
			$(this).css("color","#333333");
		});
		$("#worksSubMenu").children().click(function() {
			//find out which gallery was clicked and set the image at index 0 for that gallery as the active image
			//set the activeGalleryGroupID to the selected gallery
			//make the image selectors visible
			if ($("#gallery").find("#"+$(this).attr("target")).size() > 0) { 
				activeGalleryGroupID = $(this).attr("target");
				galleryIndex = 0;
				
				$("#TextDiv").fadeOut(250, function() {
					$("#textAbout").hide();
					$("#textNews").hide();
					$("#textResume").hide();
					$("#textLinks").hide();
					$("#activeItem").fadeOut(250,function() {
						$("#activeItem").empty();
						$("#activeItem").append("<table style='padding:5px;margin:0 auto;' cellspacing='0'><tr><td><img src='"+ $($("#"+activeGalleryGroupID).children()[galleryIndex]).attr("imageURL") +"' /></td></tr><tr><td>"+ $("#"+activeGalleryGroupID).children(galleryIndex).attr("imageDescription") +"</td></tr></table>");
						$("#activeItem").fadeTo(250,1);
					});	
				});	
				
			}
			
			$("#leftBracket").fadeTo(250,1);
			$("#rightBracket").fadeTo(250,1);
			//load the gallery previews
			$("#artItemGroupPreview").fadeOut(250, function() {
				$("#previewItems").empty();
				$("#"+activeGalleryGroupID).children().each(function() {
					//create the preview items
					$("#previewItems").append("<img src='"+$(this).attr("imageURL")+"' style='cursor:pointer;background-color:white;border:1px solid #333333;width:67px;height:53px;padding:3px;margin:20px;' />");
				});
				//bind the click events to the dynamically created gallery preview items
				$("#previewItems").children().bind('click', function() {
					//get the item's position and center it
					$("#artItemGroupPreview").stop(true,false);
					$("#artItemGroupPreview div").children().css("border","1px solid #333333"); //reset CSS on gallery items to clear other selected border
					$(this).css("border","1px solid yellow");
					galleryIndex = $(this).index();
					$("#artItemGroupPreview").scrollTo(this, {offset:-267,duration:750,easing:'easeOutBack',onAfter:function() { 
						//set the active gallery item to the preview item just clicked.
						$("#activeItem").fadeOut(250,function() {
							$("#activeItem").empty();
							$("#activeItem").append("<table style='padding:5px;margin:0 auto;' cellspacing='0'><tr><td><img src='"+ $($("#"+activeGalleryGroupID).children()[galleryIndex]).attr("imageURL") +"' /></td></tr><tr><td>"+ $($("#"+activeGalleryGroupID).children()[galleryIndex]).attr("imageDescription") +"</td></tr></table>");
							$("#activeItem").fadeTo(250,1);
						});
					}});
				});
				$("#artItemGroupPreview").fadeTo(250,1,function() {
					$("#artItemGroupPreview").scrollTo($("#artItemGroupPreview div").children(":first"),{offset:-267,duration:1}); //scroll the gallery to the first item in the list.	
					$("#artItemGroupPreview div").children(":first").css("border","1px solid yellow");		
				});
			});
		});
		$("#leftBracket").click(function() {
			//decrement the galleryIndex and update the active gallery item HTML
			if (galleryIndex > 0) { //don't do anything if the gallery is at its leftmost index
				galleryIndex--;
				var activeGalleryItemImageSrc = $("#"+activeGalleryGroupID).children(":eq("+galleryIndex+")").attr("imageURL"); //grab the image source property from the new active gallery item
				var activePreviewItem = $("#artItemGroupPreview img[src='"+activeGalleryItemImageSrc+"']");//find the gallery preview image for this item by searching for the image source property
				
				$("#artItemGroupPreview").stop(true,false);		
				$("#artItemGroupPreview div").children().css("border","1px solid #333333"); //reset CSS on gallery items to clear other selected border
				activePreviewItem.css("border","1px solid yellow");
				$("#artItemGroupPreview").scrollTo($(activePreviewItem), {offset:-267,duration:750,easing:'easeOutBack',onAfter:function() {
					$("#activeItem").fadeOut(250,function() {
						$("#activeItem").empty();
						$("#activeItem").append("<table style='padding:5px;margin:0 auto;' cellspacing='0'><tr><td><img src='"+ $($("#"+activeGalleryGroupID).children()[galleryIndex]).attr("imageURL") +"' /></td></tr><tr><td>"+ $("#"+activeGalleryGroupID).children(":eq("+galleryIndex+")").attr("imageDescription") +"</td></tr></table>");
						$("#activeItem").fadeIn(250);
					});
				}});
			}
		});
		$("#rightBracket").click(function() {
			//increment the galleryIndex and update the active gallery item HTML
			if (galleryIndex < ($("#"+activeGalleryGroupID).children().size()-1)) {
				galleryIndex++;
				var activeGalleryItemImageSrc = $("#"+activeGalleryGroupID).children(":eq("+galleryIndex+")").attr("imageURL"); //grab the image source property from the new active gallery item
				var activePreviewItem = $("#artItemGroupPreview img[src='"+activeGalleryItemImageSrc+"']");//find the gallery preview image for this item by searching for the image source property
				
				$("#artItemGroupPreview").stop(true,false);		
				$("#artItemGroupPreview div").children().css("border","1px solid #333333"); //reset CSS on gallery items to clear other selected border
				activePreviewItem.css("border","1px solid yellow");
				$("#artItemGroupPreview").scrollTo($(activePreviewItem), {offset:-267,duration:750,easing:'easeOutBack',onAfter:function() {
					$("#activeItem").fadeOut(250,function() {
						$("#activeItem").empty();
						$("#activeItem").append("<table style='padding:5px;margin:0 auto;' cellspacing='0'><tr><td><img src='"+ $($("#"+activeGalleryGroupID).children()[galleryIndex]).attr("imageURL") +"' /></td></tr><tr><td>"+ $("#"+activeGalleryGroupID).children(":eq("+galleryIndex+")").attr("imageDescription") +"</td></tr></table>");
						$("#activeItem").fadeIn(250);
					});
				}});
			}
		});
		//$("#resumeScrollDown").mousedown(function() {
//	    	//mouse pressed on scrolldown in resume page.
//			$("#resumeContent").scroll(
//		});
		
	});
