

var Rollover = Class.create();
Rollover.prototype = {
	
	element:null,
	img:null,
	defaultSrc:null,
	rollSrc:null,
	overListener:null,
	outListener:null,
	
	initialize: function (el) {
		this.element = el; 
		if(this.element.down('img')) {
			if(!this.element.hasClassName("selected")) {
				this.img = this.element.down('img');
				this.defaultSrc = this.img.src;
				this.rollSrc = (this.img.src.indexOf("over")>-1) ? this.img.src.replace("_over","") : this.img.src.replace(".gif","_over.gif");
				var preload = new Image();
				preload.src = this.rollSrc;
				this.overListener = this.over.bind(this);
				this.outListener = this.out.bind(this);
				this.out();
			} else {
				this.img = this.element.down('img');
				this.rollSrc = (this.img.src.indexOf("over")>-1) ? this.img.src.replace("_over","") : this.img.src.replace(".gif","_over.gif");
				var preload = new Image();
				preload.src = this.rollSrc;
				this.over();
			}
		}
	},
	
	over: function (e) {
		Event.stopObserving(this.element, "mouseover", this.overListener);
		this.img.src = this.rollSrc;
		Event.observe(this.element, "mouseout", this.outListener);
	},
	
	out: function (e) {
		Event.stopObserving(this.element, "mouseout", this.outListener);
		this.img.src = this.defaultSrc;
		Event.observe(this.element, "mouseover", this.overListener);
	}
	
}
