jQuery.fn.extend({
   findPos : function() {
       obj = $(this).get(0);
       var curleft = obj.offsetLeft || 0;
       var curtop = obj.offsetTop || 0;
       while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
       }
       return {x:curleft,y:curtop};
   }
});

function close_zoom(icone,pos_x,pos_y,icone_width){
	if(jQuery.browser.mozilla	==	true || jQuery.browser.safari	==	true){
		pos_y		=		pos_y-500;
	}
	
	if(jQuery.browser.msie	==	true && jQuery.browser.version	==	8.0){
		pos_y		=		pos_y-500;
	}
	
	$('.zoom_picture').animate({'width':icone_width,'left':pos_x,'top':pos_y},250,function(){$('.zoom_picture').remove()});
	
}
		
$(document).ready(function(){
	$('.zoomBox').click(function(){
		pos 						= 		$(this).findPos();
		icone_width					=		$(this).children('img').width();
		icone_height				=		$(this).children('img').height();
		explodeParam				=		$(this).attr('href').split('?');
		if(explodeParam.length	>	1){
			explodeWidth			=		explodeParam[1].split('=');
			newWidth				=		explodeWidth[1];
		}else{
			newWidth				=		500;
		}
		newHeight					=		Math.floor(icone_height*(newWidth/icone_width));
		leftPos						=		pos.x-(newWidth/2)+(icone_width/2);
		topPos						=		pos.y-(newHeight/2)+(icone_height/2);
		icone						=		$(this).parent().attr('class')
		$(this).parent().append("<div class=\"zoom_picture\"><a onclick=\"javascript:close_zoom(icone,pos.x,pos.y,icone_width)\"><img src=\""+$(this).attr('href')+"\" border=\"0\"></a></div>");
		$('.zoom_picture').css({'top':pos.y,'left':pos.x});
		
		if(jQuery.browser.mozilla	==	true || jQuery.browser.safari	==	true){
			$('.zoom_picture').css({'top':pos.y-500});
			topPos		=		topPos-500;
		}
		
		if(jQuery.browser.msie	==	true && jQuery.browser.version	==	8.0){
			$('.zoom_picture').css({'top':pos.y-500});
			topPos		=		topPos-500;
		}
		
		$('.zoom_picture').animate({'width':newWidth,'left':leftPos,'top':topPos},250);
		return false
	});
});
