(function($) 
{
	$('#dm_page div.dm_widget.content_image_scroller').live('dmWidgetLaunch', function()
	{
		var rootScroller = $('.image_scroller_root');
		rootScroller.find('.items img').click(function() {
			// see if same thumb is being clicked
			if ($(this).hasClass('active')) { return; }

			//alert($(this).attr('class'));
			// calclulate large image's URL based on the thumbnail URL (flickr specific)
			var url = $(this).attr('src'); //.replace('_k.jpg', '.jpg');
		
			// get handle to element that wraps the image and make it semi-transparent
			var wrap = rootScroller.find('.scroller_bigpic img:first');
			wrap.fadeTo('fast', 0);
		
			// the large image from www.flickr.com
			var img = new Image();
		
			// call this function after it's loaded
			img.onload = function() 
			{
				// change the image
				wrap.attr('src', url);
				
				// make wrapper fully visible
				wrap.fadeTo('fast', 1);
			};
		
			// begin loading the image from www.flickr.com
			img.src = url;
		
			// activate item
			$('.items img').removeClass('active');
			$(this).addClass('active');
		
		// when page loads simulate a 'click' on the first image
		});

	});
})(jQuery);
