function initGlass() {
	var hasGlass = $$('.hasglass').shift();	
	if( hasGlass && $('lbImageGlass') ){
		var artId = null;
		var glassSize = { x: 200, y: 180 }
		
		//alert(document.getElementById('showimg').src);
		if(matches = (document.getElementById('showimg').src).match(/content\/([A-Za-z]+)\/([A-Za-z]+)([1-5]+)_([0-9]+).jpeg$/)){
				var level = matches[2];
				var numimage = matches[3];
				var idimage = matches[4];
				var bgimgurl = root+'content/'+level+'s/'+level+numimage+'_loupe_' +idimage+'.jpeg';
				
		} 
		/*
		if(matches = (document.getElementById('showimg').src).match(/content\/([A-Za-z0-9]+)\/([A-Za-z0-9]+)_([A-Za-z0-9]+)_([0-9]+).jpeg$/)){
				var level = matches[2];
				var idreferences = matches[4];	
				var bgimgurl = root+'content/'+level+'s/'+level+'_fulldef_' + idreferences + '.jpeg';	
		}*/
		var ratio = 1;
		var jsonRequest = new Json.Remote(root+'js/artratio.js.php?level=' + level +'&numimage='+numimage+'&idimage='+idimage, {
			encoding: 'iso-8859-1',
			onComplete: function(artratio){
				ratio = artratio;
			}
		}).send();
				
		
		$('lbImageGlass').setStyles({
			overflow: 'hidden'	
		});
		
		var glass = new Element('div',{
			id: 'glass',
		    'styles': {
		        'display': 'none',
				'position': 'absolute',
				'margin-left': -12,
				'margin-top': -12,
				'width': glassSize.x,
				'height': glassSize.y,
				'background-image': 'url('+bgimgurl+')',
				'background-repeat': 'no-repeat',
				'background-repeat': 'no-repeat',
				'z-index': 50,
				'top': -1*glassSize.y,
				'left': -1*glassSize.x
		    }
		}).injectInside($('lbImageGlass'));
	

		var changeGlass = function(e){
			//alert($('lbImageGlass').getLeft() + '-' + glassSize.x + '-' + ratio);

			var event = new Event(e);
			var x = event.page.x - $('lbImageGlass').getLeft() - glassSize.x;
			var y = event.page.y - $('lbImageGlass').getTop() - glassSize.y;			
					
			//alert(x + '-' + y);
			
			
			glass.setStyles({
				'display': '',
				//'left': (x) + 'px',
				//'top': (y) + 'px',
				'left': 116 + 'px',
				'top': 12 + 'px',				
				//'background-position': parseInt(-ratio*(x+12), 10) +'px ' + parseInt(-ratio*(y+12), 10) + 'px'
				'background-position': parseInt(-ratio*(x+225), 10) +'px ' + parseInt(-ratio*(y+295), 10) + 'px'				
			});
		}
		
		function intpictureGlass (){
			
			var x1 = glassSize.x;
			var y1 = glassSize.y;
			
			//alert($('lbImageGlass').getLeft() + '-' + glassSize.x + '-' + ratio);
			//alert($('lbImageGlass').getTop() + '-' + glassSize.y + '-' + ratio);
			
			glass.setStyles({
					'display': '',
					'left': 116 + 'px',
					'top': 12 + 'px',				
					'background-position': parseInt(-ratio*(x1), 10) +'px ' + parseInt(-ratio*(y1+500), 10) + 'px'				
				});
			
		}
		intpictureGlass ();		
		
		
		$('lbImageGlass').addEvent('mousemove', changeGlass.bindWithEvent($('lbImageGlass')));
		$('lbImageGlass').addEvent('mouseleave', function(){ glass.setStyle('display', 'none'); });
	}
}
window.addEvent('domready', function(){ initGlass.delay(100); }  );

/*
function imageSwap(dir,level,size,id) {
	var imgurl = dir+"/"+level+"_"+size+"_"+id+".jpeg";
	document.getElementById('showimg').src=imgurl;
	var imgurl2 = dir+"/"+level+"_highdef_"+id+".jpeg";
	document.getElementById('ahreflink').href=imgurl2;						
}*/
