$(document).ready(function(){

	function initZoom()
	{
		var options = {
		   		zoomWidth: 300,
		    	zoomHeight: 300,
		    	showPreload: true,
	            title: true,
	            lens:true,
	            showEffect:'show',
	            hideEffect:'fadeout'
	        }
		$('#jqZoom').jqzoom(options);
	}
	
	//do an initial cleanup of the image title in case slashes are still there
	var firstTitle = $('#imageSwap').attr('title');
	if(firstTitle) firstTitle = firstTitle.replace(/[\\]/g,"");
	$('#imageSwap').attr('title',firstTitle);
	
	if(jQuery().jqzoom) { initZoom(); }

	$('div.additionalImages').each(function(){
	    $(this).mouseover(function(){
			
	        var imgsrc = $(this).children('a').attr('href');
	        var hasLargeImage = $(this).hasClass('hasLargeImage');
	        var theTitle = $(this).children('a').children('img').attr('title');
	        
	        $('img#imageSwap').attr('src',imgsrc);
	        
	    	$('#jqZoom').unbind(); //unbind all events to the jqzoom div first
	        
	        imgsrc = (hasLargeImage) ? $(this).children('a').attr('data') : imgsrc;
	        
        	//var largeImageSrc =  
        
        	$('#jqZoom').attr({href:imgsrc, title:theTitle.replace(/[\\]/g,"")});
	        
	        if(jQuery().jqzoom) { initZoom(); }
	        
	    })
	});
	
	if(jQuery().lightBox) $('div.additionalImages a').lightBox();
});
