function initGlass() {
	var hasGlass = $$('.hasglass').shift();
	if( hasGlass && $('showimage') ){
		var modelId = null;
		var colorId = null;
        var rapportformat = null;
        var zoomImageUrl = null;
        var glassSize = { x: 197, y: 192 }
        var orgSize = { x: 132, y: 193 }

		if(matches = (document.getElementById('currentModel').src).match(/reference_([0-9]+)_([0-9]+).jpeg$/)){
			var modelId = matches[1];
			var colorId = matches[2];
			var zoomImageUrl = 'content/references/reference_full_' + modelId + '_' + colorId + '.jpeg';
		}

		ratiox = 3;
		ratioy = 3;
		new Json.Remote('js/ratio.js.php?modelid=' + modelId + '&colorid=' + colorId, {
			encoding: 'iso-8859-1',
			onComplete: function(refratio){
				ratio = refratio;
			}
		}).send();


        $('showimage').setStyles({overflow: 'hidden'});
		if ($('glass')) $('glass').remove();
		var glass = new Element('div', {
           'id': 'glass',
           'styles': {
				'display': 'none',
				'width': glassSize.x,
				'height': glassSize.y,
				'background-image': 'url(' + zoomImageUrl + ')',
				'background-repeat': 'no-repeat',
				'z-index': 50
			}
		}).injectInside($('showimage'));
		var changeGlass = function(e){
			var event = new Event(e);
			var posx = event.page.x  - glassSize.x;
			var posy = event.page.y  - glassSize.y;
			var ratiox=ratio['ratiox'];
			var ratioy=ratio['ratioy'];
			//calcul position de l'image zoomé
			var cm = $('currentModel');
			var main = $('main_container');

			//document.getElementById('chemindefer').innerHTML='<div>s o c : '+document.body.scrollHeight+' - '+ main.offsetHeight+'<div>';

			var dx = 0;
			var dy = 0;
			var tt = parseInt(120 +dy+ (document.body.scrollHeight - main.offsetHeight)/2,10);
			var ll = parseInt(240 +dx+ (document.body.scrollWidth - main.offsetWidth)/2,10);

			if(true){
				var x = parseInt(event.page.x, 10) - ll;
				var y = parseInt(event.page.y, 10) - tt;
			}else{
				var x = parseInt(event.page.x, 10) - parseInt(cm.clientLeft, 10);
				var y = parseInt(event.page.y, 10) - parseInt(cm.clientTop, 10);
			}
			if (ratio['largeurini']<orgSize['x']) {
				x-=parseInt(0.5*(orgSize['x']-ratio['largeurini']),10);
			}
			if (ratio['hauteurini']<orgSize['y']) {
				y-=parseInt(0.5*(orgSize['y']-ratio['hauteurini']),10);
			}
			if (window.ie6) y+=0.5*glassSize.y;
			var decalBackx=parseInt( ratiox*x-glassSize.x/2 , 10);
			var decalBacky=parseInt( ratioy*y-glassSize.y/2 , 10);
			// toujours avoir l'image entièrement sur le fond

			if (decalBackx<0) decalBackx=0;
			else {
				if (decalBackx>ratio['largeurzoom']-glassSize.x) decalBackx=parseInt(ratio['largeurzoom']-glassSize.x,10);
				decalBackx=-1*decalBackx;
			}
			if (decalBacky<0) decalBacky=0;
			else {
				if (decalBacky>(ratio['hauteurzoom']-glassSize.y)) decalBacky=parseInt(ratio['hauteurzoom']-glassSize.y,10);
				decalBacky=-1*decalBacky;
			}
			var fx=x;
			var fy=y;
			var fv='sfre';
			//document.getElementById('chemindefer').innerHTML='<div>'+posx+'/'+posy+' -> '+x+'/'+y+' ('+ratio['hauteurini']+') '+ratiox+'x'+ratioy+' | '+fv+':'+fx+','+fy+'<div>';
			//document.getElementById('chemindefer').innerHTML='<div>'++'<div>';

			//positionnement
			glass.setStyles({
				'display': '',
                'left': (posx) + 'px',
                'top': (posy) + 'px',
                'background-position':  decalBackx+'px ' + decalBacky + 'px'
			});
		}
		$('currentModel').addEvents({'mousemove': changeGlass.bindWithEvent($('showimage')), 'mouseleave': function(){ glass.setStyle('display', 'none'); }});
	}
}
window.addEvent('load', function(){ initGlass.delay(100); });