
(function($)
{
	var productZoomSettings =
	{	
		//global settings
		imagePath: '#image_link',
		imageGaleryPath: '.more-views a',
		
		
		//options of jqzoom http://www.mind-projects.it/projects/jqzoom/index.php#documentation
		jqzoomOptions: {
			zoomWidth: 495,
			zoomHeight: 430,
			xOffset: 15,
			title:false,
		  	showEffect:'show',
	    	hideEffect:'hide',
			fadeinSpeed: 'fast',
	    	fadeoutSpeed: 'fast',
			showPreload: false,
			lensReset:true
		}
	};
	
	var productZoom = {
		
		initialized: false,
		
		init: function() {
			//alert('init');
			this._init();
			
			//$(productZoomSettings.imageGaleryPath).bind("click",productZoom.galClick);
			
			//productZoom.bigImageLink.jqzoom(productZoomSettings.jqzoomOptions);
			reload(productZoom.bigImageLink.attr('href'), productZoom.bigImage.attr('src'))
		},
		
		_init: function() {
			
			if(productZoom.initialized != true) {
				
				productZoom.bigImageLink = $(productZoomSettings.imagePath);
				productZoom.bigImage = $('img',productZoom.bigImageLink);
				productZoom.bigImageLinkBackup = productZoom.bigImageLink.clone();
				productZoom.initialized = true;
			} else {
				productZoom.bigImageLinkBackup = productZoom.bigImageLink.clone();
			}
			
		},
		
		galClick: function(ev) {
			ev.preventDefault();								
			var l = $(this);
			
			productZoom.bigImageLink.replaceWith(productZoom.bigImageLinkBackup.clone());
			
			productZoom.bigImageLink = $(productZoomSettings.imagePath);
			
			productZoom.bigImage = $('img',productZoom.bigImageLink);
				
			$('.jqZoomWindow').remove();
			productZoom.bigImageLink.attr('href',l.attr('href'));
			productZoom.bigImage.attr('src',l.attr('rel'));
				
			productZoom.bigImageLink.jqzoom(productZoomSettings.jqzoomOptions);
		},
		
		reload: function(href, rel) {
			this._init();

			if(productZoom.bigImageLink.get(0).parentNode) {
				productZoom.bigImageLink.replaceWith(productZoom.bigImageLinkBackup.clone());
			}

			productZoom.bigImageLink = $(productZoomSettings.imagePath);
			productZoom.bigImage = $('img',productZoom.bigImageLink);
			
			$('.jqZoomWindow').remove();
			productZoom.bigImageLink.attr('href',href);
			productZoom.bigImage.attr('src',rel);
			
			productZoom.bigImageLink.jqzoom(productZoomSettings.jqzoomOptions);
		}
		
	};	
		
	/*$(document).ready(function(){	
			
			productZoom.init();
	});*/
	
	window.productZoom = productZoom;

})(jQuery.noConflict());

//TODO : opons of jqzoom + make gallery work

