jQuery('img').live('mouseover', function() {
	// Grab a jQuery copy of the image.
	var img = jQuery(this);

	// Check if we've already processed it.
	if (img.hasClass('thumbnail')) {
		return;
	}

	// Get the source of the image.
	var src = img.attr('src');

	// If it's not from the upload site's thumbs directory, don't do anything.
	if (src.indexOf('upload.drarok.com/uploads/thumbs/') == -1) {
		return;
	}

	// Add the thumbnail class, which changes the cursor and is checked in the onclick.
	img.addClass('thumbnail');
});

jQuery('img').live('click', function() {
	// Grab a jQuery copy of the image.
	var img = jQuery(this);

	// If it's not our thumbnail class, ignore it.
	if (! img.hasClass('thumbnail')) {
		return;
	}

	// Remove the thumbnail class to get rid of the pointer cursor.
	img.removeClass('thumbnail');

	// Start fading the image out.
	img.fadeTo('slow', 0.3);

	// Wrap in a css-styles span element.
	img.wrap('<span class="thumbnail_wrapper" />');
	img.after('<img class="thumbnail_loader" src="./styles/subsilver2/theme/images/ajax-loader.gif" width="220" height="19" />');

	// Bind to the onload event.
	img.bind('load', function() {
		// Get the image for the event.
		var img = jQuery(this);

		// Remove the ajax loader image.
		img.siblings('.thumbnail_loader').remove();

		// Unwrap it from its container.
		img.unwrap();

		// Fade the image back to opaque.
		img.fadeTo('fast', 1.0);
	});

	// Get the source of the image and swap in the full-size image.
	var src = img.attr('src');
	img.attr('src', src.replace('/uploads/thumbs/', '/uploads/'));
});

