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){
	delay			=		250;
	if(jQuery.browser.mozilla	==	true){
		pos_y		=		pos_y-80;
		delay		=		750;
		$("object").css({'visibility':'visible'})
	}
	
	if(jQuery.browser.msie	==	true && jQuery.browser.version	==	8.0){
		pos_y		=		pos_y-80;
	}
	
	$('.zoom_picture').animate({'width':icone_width,'left':pos_x,'top':pos_y},delay,function(){$('.zoom_picture').remove()});
}
		
$(document).ready(function(){
	$('.zoomBox').click(function(){
		
		
		
		if($('.zoom_picture').length	>	0){
			$('.zoom_picture').remove();
		}
		
		delay						=		450;
		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				=		400;
		}
		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')+"\" width=\""+newWidth+"\"></a></div>");
		
		$('.zoom_picture').css({'top':pos.y,'left':pos.x});
		if(jQuery.browser.mozilla	==	true){
			$("object").css({'visibility':'hidden'})
			$('.zoom_picture').css({'top':pos.y-80});
			topPos		=		topPos-80;
			delay		=		750;
		}
		
		if(jQuery.browser.msie	==	true && jQuery.browser.version	==	8.0){
			$('.zoom_picture').css({'top':pos.y-500});
			topPos		=		topPos-80;
		}
		
		$('.zoom_picture').animate({'width':newWidth,'left':leftPos,'top':topPos},delay);
		return false
	});
});