// JavaScript Document

		$(document).ready( function(){		
			var count = 0;
			
			$(".scrollable").corner('5px');
			
			$(".scrollable > div").find("img").each( function () {
				 count = count +1;
			});
			
			if(count > 7 )
				$(".scrollable > div").scrollable();
			
			count = 0;
				
				
			$(".items img").click(function() {
										   
				$("div.scrollable").find("div.items img").each( function () {
					 $(this).removeClass("active");
				});
				
				$(this).addClass("active");	

				// calclulate large image's URL based on the thumbnail URL (flickr specific)
				var url = $(this).attr("src").replace("TH_","");
			 
				// get handle to element that wraps the image and make it semitransparent
				var wrap = $(".image_wrap").fadeTo("medium", 0.5);
			 
				// the large image from flickr
				var img = new Image();
			 
				// call this function after it's loaded
				img.onload = function() {
			 
					// make wrapper fully visible
					wrap.fadeTo("fast", 1);
			 
					// change the image
					wrap.find("img").attr("src", url);
			 
				};
			 
				// begin loading the image from flickr
				img.src = url;
			 
			// when page loads simulate a "click" on the first image
			}).filter(":first").click();
			
			var title = $("div.items img.active").attr("title");
			var desc = $("div.items img.active").attr("alt");
			
			if(desc == "" && title == "") {
				$('div.legend').hide();
			}
			else {
				$('div.legend').show();
			}
			
			$("h4.title").text(title);
			$("p.description").text(desc);
			
			$("div.items img").click(function(){
				title = $(this).attr("title");
				desc = $(this).attr("alt");			
				
				$("h4.title").text(title);
				$("p.description").text(desc);
				
				if(desc == "" && title == "") {
					$('div.legend').hide();
				}
				else {
					$('div.legend').show();
				}
			});

		});
