if(!JUS101) var JUS101 = {};

JUS101.BackgroundPan = Class.create();
JUS101.BackgroundPan.prototype = {
	initialize: function(element, options) {
		this.element = $(element);
		this.offsetX = this.element.offsetLeft;
		this.offsetY = this.element.offsetTop;
		this.dimensions = this.element.getDimensions();
		this.element.observe('mousemove', this.element_onMouseMove.bindAsEventListener(this));
		this.element.observe('mouseout', this.element_onMouseOut.bindAsEventListener(this));
		this.width = this.element.getWidth();
		this.height = this.element.getHeight();
	},
	
	element_onMouseMove: function(event) {
		clearTimeout(this.timeout);
		var x = ((event.pageX - this.offsetX) / this.width) * 100;
		var y = ((event.pageY - this.offsetY) / this.height) * 100;
		this.element.setStyle({backgroundPosition: x + "% " + y + "%"});
	},
	
	element_onMouseOut: function(event) {
		this.timeout = setTimeout(this.reset.bind(this), 1500);
	},
	
	reset: function() {
		this.element.morph("background-position: 50% 50%")
	}
}

$$('.flickr a.lead').each(function(a){
	new JUS101.BackgroundPan(a);
});
