/**
 * @package parcours
 * @subpackage benchmark
 * @filesource
 */

/**
 * objet js de gestion d'une fiche produit.
 *
 *
 * @author Damien BENOIT <benoit@benchmark.fr>
 * @package creations
 * @subpackage html_include
 * @version 1.00
 * @since 24/06/2009 Damien BENOIT <benoit@benchmark.fr> création
 */

if(typeof(benchmark) == "undefined") { var benchmark = new Object(); }
if(typeof(benchmark.application) == "undefined") { benchmark.application = new Object(); }
if(typeof(benchmark.application.ecommerce) == "undefined") { benchmark.application.ecommerce = new Object(); }

/**
 * constructeur :
 * @return void
 */
benchmark.application.ecommerce.ObjEcommerceFicheProduit = function(mode)
{
	/**
	* initialisation
	* @author Damien BENOIT <benoit@benchmark.fr>
	* @return void
	*/
	this.initialise = function()
	{
		this.initialiseZoomImages();
	};

	/**
	* initialisation
	* @author Damien BENOIT <benoit@benchmark.fr>
	* @return void
	*/
	this.initialiseZoomImages = function()
	{
		//comportement sur les miniatures :
		$('.image_zoom')
			.bind(
				'mouseenter',
				function()
				{
					// si l'image change seulement :
					if($(this).attr('src_350') != $('#image_principale img').attr('src') )
					{
						// @todo à enlever, mis temporairement pour gerer pb de cache IE
						if($.browser.msie)
						{
							var aleatoire = Math.random();
							//var aleatoire = 1;
						}else{
							var aleatoire = 1;
						}

						benchmark.framework.ihm.effet.ObjEffet.changeImage(
								'#image_principale img',
								$(this).attr('src_350')+'?'+aleatoire,
								250,
								// on rajoute le comportement sur l'image principale changée :
								function(e)
								{
									// obligé par ie de passer de e.currentTarget à e.target et finallement à un champs en dur (la loose):
									$('#image_principale img')
										.bind('click',
												function(e)
												{
													var popup = new benchmark.framework.ihm.ObjPopup();
													popup.ouvreImage($(this).attr('src_full'));
												}
											);
								},
								// on conserve l'url de l'image full pour ouverture popup:
								{
									'src_full'	: $(this).attr('src_full')
								},
								$('#image_principale')
								);
					}
				}
				)
			.bind(
				'click',
				function()
				{
					var popup = new benchmark.framework.ihm.ObjPopup();
					popup.ouvreImage($(this).attr('src_full'));
				}
				)
			;
		// factorisation du centrage :
		var centreImage = function() {benchmark.framework.ihm.effet.ObjEffet.centre('#image_principale img','#image_principale',false,false);}
		// comportement image principale à l'origine :
		$('#image_principale img')
			.css('display','none')
			.bind(
					'click',
					function(e)
					{
						var popup = new benchmark.framework.ihm.ObjPopup();
						popup.ouvreImage($(this).attr('src_full'));
					}
				)
			.bind(
					'load',
					function(e)
					{
						centreImage();
						$(this).fadeIn();
					}
					)
			;
		// premier centrage automatique :
		// non webkit tout va bien :
		if($.browser.msie || $.browser.mozilla)
		{
			centreImage();
		}
		// webkit à du mal à centrer dès le début on attends un peu :
		else
		{
			setTimeout(function(){centreImage();},100);
		}
		// on bind le redimensionnement de la fenêtre pour suivre le déplacement malgré le positionnement absolut
		$(window).bind('resize',centreImage);

	};
};
/*
$(document).ready(
		function(){
			objTrace = new benchmark.framework.util.debug.ObjTrace();
			objTrace.traceActive = true; // pour activer les traces
			objTrace.trace('moteur de trace initialisé',objTrace.TRACE_TYPE_INTERNAL,true);
		}
	);
*/