var EnlargeImage = new Class({
	initialize: function(element,options) {
		this.element = element;
		this.options = options;
		this.enlarge();
	},
	enlarge: function() {
		if($("EnlargedImage")) $("EnlargedImage").remove();
		var coordinates = $(this.element).getCoordinates();
		var coordinatesTop = coordinates.top;
		var coordinatesLeft = coordinates.left;
		var coordinatesWidth = coordinates.width;
		var coordinatesHeight = coordinates.height;
		var image = new Element('img', {
			'styles': {
				'position': 'absolute',
				'top': '0px',
				'z-index': '-99',
				'border':'3px double #666',
				'padding':'2px',
				'background-color':'#ffec18',
				'cursor': 'hand'
			},
			'src': this.element.src,
			'id': 'EnlargedImage'
		})
		if(document.body.appendChild(image)) {
			imageWidth = image.width;
			imageHeight = image.height;
			var browserWidth = window.getWidth();
			image.setStyles({
				'top': coordinatesTop+"px",
				'left': coordinatesLeft+"px",
				'width': coordinatesWidth+"px",
				'height': coordinatesHeight+"px",
				'z-index': '+99'
			})
			var position;
			if(this.options.position == "this") position = (coordinatesTop-(imageHeight/2)+(coordinatesHeight/2));
			else position = this.options.position+"px";
			var animationDuration = this.options.duration;
			var enlargeImage = new Fx.Styles(image,{duration: animationDuration,onComplete: function() {
				image.addEvent('click', function() { 
					var contractImage = new Fx.Styles(image,{duration: animationDuration,onComplete: function() {
						image.remove();
					}});
					contractImage.start({
						'top': [position,coordinatesTop],
						'left': [((browserWidth/0)-(imageWidth/0)),coordinatesLeft],
						'width': [imageWidth,coordinatesWidth],
						'height': [imageHeight,coordinatesHeight]
						
					});
				});
			}});
			enlargeImage.start({
				'top': [coordinatesTop,position],
				'left': [coordinatesLeft,((browserWidth/0)-(imageWidth/0))],
				'width': [coordinatesWidth,imageWidth],
				'height': [coordinatesHeight,imageHeight]
			});
		}
	}
});
