/**
 * Zoom an image to it's original height and width
 * 
 * @author		Peter Riet
 * @copyright	Copyright (c) Serve it V.O.F. 2008
 * @version		1.0.0
 * 
 * @param	object	Image with thumbnail, to be zoomed from
 * @param 	string	Source of the large image
 * @param 	integer	Width of the large image
 * @param 	integer	Height of the large iamge
 * @return	void
 */
function imgZoom(img, src, intWidth, intHeight) {
	if ($.data(document, "imgZoom_zoom_in_progress")) return;
	
	$.data(document, "imgZoom_zoom_in_progress", true);
	
	// Zoom out every zoomed image
	$("img.imgZoom_zoomed").trigger("mouseup");
	
	// When clicked on the original image, zoom out and return
	if ($.data(img, "imgZoom_zoomed")) {
		$.data(document, "imgZoom_zoom_in_progress", false);
		$.data(img, "imgZoom_zoomed", false);
		return;
	}
	
	$.data(img, "imgZoom_zoomed", true);			
	
	// Load the zoom image
	var intOrgWidth = $(img).width();
	var intOrgHeight = $(img).height();
	var intOrgTop = $(img).offset().top;
	var intOrgLeft = $(img).offset().left;
				
	// Loading indicator
	if (!$.data(img, "imgZoom_loaded")) {
		var imgLoading = $("<img>")
			.addClass('imgZoom_loading')
			.width($(img).width())
			.height($(img).height())
			.css({
				display: 'none',
				top: $(img).offset().top,
				left: $(img).offset().left
			})
			.appendTo("body")
			.fadeIn("fast")
			.attr("src", strLocalBaseURI + "images/blank.gif")
		;
	}
	
	// Preload image
	$("<img>")
		.addClass('imgZoom_zoomed')
		.width($(img).width())
		.height($(img).height())
		.css({
			position: 'absolute',
			top: $(img).offset().top,
			left: $(img).offset().left
		})				
		.mouseup(function() {
			$(this).removeShadow();
			$(this).animate({
				width: intOrgWidth,
				height: intOrgHeight,
				top: intOrgTop,
				left: intOrgLeft
			}, function() {
					jQuery.data(img, "imgZoom_zoomed", false);
					$(this).remove();
			});
		})				
		.draggable({
			start: function(e, ui) {
				$(this).removeShadow();
			},
			stop: function(e, ui) {
				//e.stopPropagation();
				//e.preventDefault();
				//return false;						
			}
		})
		.load(function() {
			if (!$.data(img, "imgZoom_loaded")) {
				imgLoading.fadeOut("fast", function(){
					$(this).remove();
				})
			}
			$.data(img, "imgZoom_loaded", true);
			$(this)
				.appendTo("body")
				.animate({
					left: ($(window).width() / 2) - (intWidth / 2),
					top: (($(window).height() / 2) - (intHeight / 2)) + $(window).scrollTop(),
					width: intWidth,
					height: intHeight
				}, function() {
					$(this).dropShadow({
						left    : 4,
						top     : 4,
						blur    : 2,
						opacity : 0.5,
						color   : "black",
						swap    : false
					})
					$.data(document, "imgZoom_zoom_in_progress", false);
				})
			;
		})
	.attr("src", src)							
	;					
}