var Zooms = Class.create()
    
Zooms.prototype = { 
	capaZoom : null,

	initialize : function() {
    	$$("img.zoom").each(function(item){
			Event.observe(item, "click", this.zoom.bindAsEventListener(this));		
		}.bind(this));
	},
	
	zoom : function(evt){
		elemento = Event.element(evt);
		
		if(!$('modal_window')){
			this.capaZoom = new CapaDescrip({
				ancho :300,
				alto : 300,
				mostrar : "mostrarImg.aspx?rutaImagen=" + elemento.getAttribute('imgZoom'),
				onComplete : this.ajustarVentana.bindAsEventListener(this)
			});
			this.capaZoom.mostrar();
		}
	},
	
	ajustarVentana : function(){
		setTimeout(function(){
			this.reajustarVentana();
			setTimeout(this.reajustarVentana.bind(this), 1000);			
		}.bind(this),200);
	},
	
	reajustarVentana : function(){
		anchoVentana = $('imagenCapaZoom').width + 20;
		altoVentana = $('imagenCapaZoom').height + 40;
		this.capaZoom.win.setSize(anchoVentana, altoVentana);
		anchoNavegador = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
		altoNavegador = window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
		posScroll = getScrollXY();
		this.capaZoom.win.setLocation(((altoNavegador - altoVentana) / 2) + posScroll[1], (anchoNavegador - anchoVentana) / 2) + posScroll[0];	
	}
}
		
Event.observe(window,"load", function(){ new Zooms(); });

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}