/*---- TopRecherche.js ----*/

var _zoomedEndProportionWidth = 1.35;
var _zoomedEndProportionHeight = 1.35;
var _zoomedEndDuration = 500;
var _a_RechercheIndex = 0;
var _hideGoogleZoomAction = 0;
var _googleZoomCloneId = "googleZoomCloneId";
var _showGoogleZoomInProgress = false;

function AnimateResizeObj(obj, resizeWidthPercent, resizeHeigthPercent, duration) {
	var offset = obj.offset();
	var top = offset.top;
	var left = offset.left;
	var width = parseFloat(obj.css('width'));
	var height = parseFloat(obj.css('height'));

	var resizedWidth = width * resizeWidthPercent;
	var resizedHeight = height * resizeHeigthPercent;
	var resizedTop = top + height / 2 - resizedHeight / 2
	var resizedLeft = left + width / 2 - resizedWidth / 2

	obj.animate({
		width: resizedWidth,
		height: resizedHeight,
		top: resizedTop,
		left: resizedLeft
	}, duration
				);
}

function ShowGoogleZoom(id) {
	ClearHideGoogleZoomAction();
		
	var obj = $('#' + id);
	var offset = obj.offset();
	var zoomedItemContainer = $('#zoomedItemContainer');
	var clone = obj.clone();

	clone.attr("id", _googleZoomCloneId);
	clone.mouseout(HideGoogleZoomDelayed);
	clone.mouseover(ClearHideGoogleZoomAction);
	clone.css({ top: offset.top, left: offset.left });
	clone.addClass('zoomedItem');
	clone.find('.label_modeleOver').css({ "display": "block" });
	zoomedItemContainer.html(clone);

	AnimateResizeObj(clone, _zoomedEndProportionWidth, _zoomedEndProportionHeight, _zoomedEndDuration);
}

function HideGoogleZoomDelayed() {
	WriteDebugText("HideGoogleZoomDelayed");
	_hideGoogleZoomAction = window.setTimeout('HideGoogleZoom();', 50);
}

function HideGoogleZoom() {
	WriteDebugText("HideGoogleZoom");
	var obj = $('#' + _googleZoomCloneId);
	obj.hide(50);
}

function ClearHideGoogleZoomAction() {
	WriteDebugText("ClearHideGoogleZoomAction");
	window.clearTimeout(_hideGoogleZoomAction);
}

$(document).ready(function() {
	$(".a_Recherche").attr("id",
					   function() {
					   	_a_RechercheIndex++;
					   	return "a_Recherche" + _a_RechercheIndex;
					   }
	);

	$(".a_Recherche").mouseover(
		function() {
			ShowGoogleZoom(this.id);
		}
	)
});


