/*
Date:		$Date: 2010-07-25 16:22:32 +0200 (So, 25 Jul 2010) $
Author:		$Author: Sri $
Version:	$Id: dd_zoom.js 19 2010-07-25 14:22:32Z Sri $
*/

var fast_clicked = false;

function loadZoomCnt( sUrl)
{
	if( sUrl != '')
	{
		sUrl = sUrl.replace( /&amp;/g, '&');
		if( oBody = $( 'body'))
		{
			oBody.append( '<div id="zoomtpl"></div>');
			if( oZoomtpl = $( '#zoomtpl'))
			{
				//load the zoom-content into the zoomtpl-container
				$.get( sUrl, function(data)
					{
						$( oZoomtpl).append( data);
						
						//preloading images
						aImgs = $( 'img', oZoomtpl);
						for ( var i = 0; i < aImgs.length; i++)
						{
							var img = new Image();
							$(img).attr('src', aImgs[ i]);
						}
						
						/*
						$( '#zoom_tip').hover( function( e) 
						{
							if( $( '#zoomtpl').length)
							{
								imgTop = $( '#product_img').position().top;
								imgLeft = $( '#product_img').position().left;
								imgW = $( '#product_img').width();
								imgH = $( '#product_img').height();
								centerX = imgLeft + (imgW/2) - ( $( '#zoom_tip a').width()/2) ;
								centerY = imgTop + (imgH/2) - ( $( '#zoom_tip a').height()/2) ;
								
								
								$( '#zoom_tip a').css( 'top', parseInt( centerY)+'px');
								$( '#zoom_tip a').css( 'left', parseInt( centerX)+'px');
								
								if ( $( '#zoom_tip a').css( 'display') ==  'none' )
								{
									$( '#zoom_tip a').show( 'slow');
								}
							}
						},
						function()
						{
							if( $( '#zoomtpl').length)
							{
								$( '#zoom_tip a').hide( 'slow');
							}
						}
						);
						*/
						//adding click-event to exturls-link
						$( '#zoom_tip').click( function( e) 
						{
							//$( 'a', this).unbind( 'click');
							//finding real width and heigth of the container
							$( '#zoomtpl').css( 'display', 'block');
							iPadding = $( '#zoom').css( 'padding-left');
							iPadding = iPadding != '' ? parseInt( iPadding) : 0;
							iBorder = $( '#zoom').css( 'border-left-width');
							iBorder = iBorder != '' ? parseInt( iBorder) : 0;
							iExtra = 10;
							iHeight = $( '#zoom').height() + ( iPadding * 2) + ( iBorder * 2);
							iWidth = $( '#zoom').width() + ( iPadding * 2) + ( iBorder * 2) + iExtra;
							iHeightHalf = parseInt( iHeight / 2);
							iHeight = iHeight + 'px';
							iWidth = iWidth + 'px';
							$( '#zoomtpl').css( 'display', 'none');
							
							//setting height and width of the zoom-container to 0
							$( '#zoomtpl').css( 'width', '0px');
							$( '#zoomtpl').css( 'height', '0px');
						
							$( this).css( 'visibility', 'hidden');
							iTop = e.pageY + 'px';
							iTopEnd = ( e.pageY - iHeightHalf) + 'px';
							iLeft = ( e.pageX - 80 ) + 'px';
							$( '#zoomtpl').css( 'top', iTop);
							$( '#zoomtpl').css( 'left', iLeft);
							$( '#zoomtpl').css( 'display', 'block');
							$( '#zoomtpl').hide();
							$( '#zoomtpl').animate(
								{
									height: iHeight,
									width: iWidth,
									top: iTopEnd,
									opacity: "show"
								}, 'slow', function() 
								{
									$( '#zoomtpl').css( 'width', 'auto');
									$( '#zoomtpl').css( 'height', 'auto');
								}
							);
							
							$( '#zoom_tip a').hide();
							return false;
						});
						
						//adding close-Function
						$( '#zoom .close').click( function() 
						{
							$( '#zoom_tip').css( 'visibility', 'visible');
							$( '#zoomtpl').css( 'display', 'none');

							//setting height and width of the zoom-container to 0
							$( '#zoomtpl').css( 'width', 'auto');
							$( '#zoomtpl').css( 'height', 'auto');
							
							return false;
						});
						
						$( '#zoom_tip .loading').remove();
						setZoomify();
						//$( '#zoom_tip a').show();
						
//						if( fast_clicked)
//						{
//							$( '#zoom_tip').trigger('click');
//						}
					}
				);
			}
		}
	} 
}
