// Tools for the download page
// sharehub.com
// jwm

window.onload=function() {

	//Configuration Options
	var max_width = 525;			// Sets the max width, in pixels, for every image
	var selector = 'img.userImage';		//Sets the syntax for finding the images.  Defaults to all images.
	var orig_contentWidth = $("div#content").width();
	
	$(selector).each(function() {
		var orig_width = $(this).width();
		var orig_height = $(this).height();
		if (orig_width > max_width) {
			//Set variables	for manipulation
			var ratio = (orig_height / orig_width );
			var new_width = max_width;
			var new_height = (new_width * ratio);
			
			//Shrink the image and add link to full-sized image
			$(this).height(new_height).width(new_width);
			
			$(this).attr("title", "This image has been resized to fit the page. Click to view the full size.");
			$(this).css("cursor", "pointer");

			$(this).bind("click", function(e) {
				if ( $(this).width() > max_width )
				{
					$(this).height(new_height).width(new_width);
					$("#imageBox").height(new_height).width(new_width);
					$("div#content").width(orig_contentWidth);
					$(this).attr("title", "This image has been scaled to fit the page. Click to view the full size.");
				}
				else
				{
					$("div#content").width($("div#content").width() + (orig_width - new_width));
					$("#imageBox").height(orig_height).width(orig_width);
					$(this).height(orig_height).width(orig_width);
					$(this).attr("title", "Viewing full size. Click to return to scaled version.");
				}
			});

		} //if
		$(this).css("visibility","visible");
	} //each
	);

}; //onload


