// thanks to http://snook.ca/archives/javascript/prototypepowere/
var Popup = Class.create();
Popup.prototype = 
{
  initialize: function(options)
  {
    this.options = {
      url: '#',
      width: 300,
      height: 300
    }
    Object.extend(this.options, options || {});
    window.open(this.options.url, '', 'width='+this.options.width+',height='+this.options.height);
  }
}

function openImageWindow(e,wide,tall) {
	new Popup({url:this.src,width:wide,height:tall});
}

function resizeImages() {
	var images = $$('div.entry img');
	for(var i = 0; i < images.size(); i++) {
		var img = images[i];
		var dimensions = $(img).getDimensions();
		var aspectRatio = dimensions.width / dimensions.height;

		if (dimensions.width > 400) {
			// if image is wider than 400px, resize
			img.width = 400;
			img.height = 400 / aspectRatio;
			
			// bind click event to image to open new window
			Event.observe(img, 'click', openImageWindow.bindAsEventListener(img,dimensions.width+20,dimensions.height+20));
		}
	}
}
