var currentDiv;

function openPreviewProduct(event, url)
{
	if(event != null)
	{
		if(event.preventDefault){ 
			event.preventDefault(); 
		}else{
			event.returnValue = false;
		}
	}
	
	currentDiv = new Element('div');
	currentDiv.setStyle({'display':'block','position':'absolute'});
	currentDiv.addClassName('product_preview');
	currentDiv.observe('click', splash_hide);
	
	var loading = 
			'<p style="text-align:right">'+
				'<img id="close_over" alt="Fermer" src="'+ GFX +'graphic/shared/bt_close_splash.png" style="cursor:pointer">'+
			'</p>'+
			'<div align="center">Chargement ...<br/><br/><img src="'+ GFX +'graphic/shared/loading.gif" alt="Chargement en cours ..."/><br/><br/><br/></div>';
	
	currentDiv.update(loading);
	currentDiv.wrap();

	
	$(over).update();
	$(over).insert({'bottom':currentDiv});
	$(over).setStyle({'display':'block'});
		
	body.insert({'bottom':$(over)});
	
	resizeUserPopup(null);
	
	Event.observe(window, 'scroll', resizeUserPopup);
	Event.observe(window, 'resize', resizeUserPopup);
	Event.observe(window, 'click', splash_hide);
	
	new Ajax.Request(url, {
		onSuccess: function(response){
			currentDiv.innerHTML = response.responseText;
			
			resizeUserPopup();
			
			if(!MSIE6 && !MSIE7){
				Cufon.replace('.product_preview .ficheProduit h1');
				Cufon.replace('.product_preview .ficheProduit h2');
				Cufon.replace('.troisFoisSansFrais span.bleuAchat');
				Cufon.replace('.instructionGotham');
			}
			//Initialise l'écouteur pour l'ajout de produit sans avoir selectionné de taille
			cc_init();
			//Initialise l'écouteur pour la gallery
			glissGalleryInit();
			//Initialise le zoom d'image
			zoom_init();
			//Fonction permettant d'initialiser le zoom
			myInitZoom();

			resizeUserPopup();
		}
	})
}

function myInitZoom()
{
	if($('visuelPrincipal') != null){
		MagicZoom.stop($('visuelPrincipal'));
		MagicZoom.start($('visuelPrincipal'));
	}

	if($('visuelPrincipal_1') != null){
		MagicZoom.stop($('visuelPrincipal_1'));
		MagicZoom.start($('visuelPrincipal_1'));
	}

	if($('visuelPrincipal_2') != null){
		MagicZoom.stop($('visuelPrincipal_2'));
		MagicZoom.start($('visuelPrincipal_2'));
	}
}

function resizeUserPopup(event){
	$(currentDiv).setStyle({'top':parseInt((document.viewport.getHeight() - $(currentDiv).getHeight()) / 2 + document.viewport.getScrollOffsets().top) + 'px', 'left':parseInt((document.viewport.getWidth() - $(currentDiv).getWidth()) / 2 + document.viewport.getScrollOffsets().left) + 'px'});
}