function initGlass() {
	var hasGlass = $$('.hasglass').shift();	
	if( hasGlass && $('lbImage') ){
		var artId = null;
		var glassSize = { x: 200, y: 200 }
		
		if(matches = (document.getElementById('showimg').src).match(/content\/([A-Za-z0-9]+)\/([A-Za-z0-9]+)_([A-Za-z0-9]+)_([0-9]+)_([0-9]+).jpeg$/)){
				var level = matches[2];
				var idreferences = matches[4];
				var idimage = matches[5];
				var bgimgurl = root+'content/'+level+'s/'+level+'_fulldef_' + idreferences + '_'+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 jsonRequest = new Json.Remote(root+'js/artratio.js.php?level=' + level + '&idreferences='+idreferences+'&idimage='+idimage, {
			encoding: 'iso-8859-1',
			onComplete: function(artratio){
				ratio = artratio;
			}
		}).send();
		
		$('lbImage').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($('lbImage'));
	
		var changeGlass = function(e){
			var event = new Event(e);
			var x = event.page.x - $('lbImage').getLeft() - glassSize.x;
			var y = event.page.y - $('lbImage').getTop() - glassSize.y;
			
			glass.setStyles({
				'display': '',
				'left': (x) + 'px',
				'top': (y) + 'px',
				'background-position': parseInt(-ratio*(x+12), 10) +'px ' + parseInt(-ratio*(y+12), 10) + 'px'
			});
		}
		
		$('lbImage').addEvent('mousemove', changeGlass.bindWithEvent($('lbImage')));
		$('lbImage').addEvent('mouseleave', function(){ glass.setStyle('display', 'none'); });
	}
}
window.addEvent('load', function(){ initGlass.delay(100); });


function imageSwap(dir,level,size,id,withflash) {
	var list = $$('.thumblist');
	var imgurl = dir+"/"+level+"_"+size+"_"+id+".jpeg";
	document.getElementById('showimg').src=imgurl;
	if(withflash!='' && list[0].src==dir+"/"+level+"_thumbnail_"+id+".jpeg"){
		var imgurl2 = dir;	
		var dirxt = dir.split('/');
		imgurl2='';
		for(i=0;i<(dirxt.length-2);i++)
			imgurl2+=dirxt[i]+'/';
		imgurl2+='catalogue/productzoom-'+withflash+'.html';
		$('ahreflink').setProperties({
			'href':imgurl2
		});
		document.getElementById('ahreflink').rel='';
		Lightbox.init();
	}else{
		var imgurl2 = dir+"/"+level+"_highdef_"+id+".jpeg";
		$('ahreflink').addClass("hasglass");	
		$('ahreflink').setProperties({
			'href':imgurl2
		});
		document.getElementById('ahreflink').rel='lightbox';
		Lightbox.init();
		initGlass();	
	}
}