var MouseoverLoader = Class.create();

MouseoverLoader.prototype = {
	initialize: function()
	{
		debug("Mouseover->init()");
		this.mouseoverFunction = this.mouseover.bindAsEventListener(this);
		this.mouseoutFunction = this.mouseout.bindAsEventListener(this);
		this.page = "mouseover";
		this.thumbnailList = new ThumbnailList();
	},
	registerSingle: function(single)
	{
		single.mouseout_src = single.src;
		single.mouseover_src = single.src.replace(/(.*_)(on|off|grey)(\..{3,5})/i, "$1over$3");
		var state = single.src.replace(/.*_(on|off|grey)\..{3,5}/i, "$1");
		if (state=="grey" || state=="on") return;
		(new Image()).src = single.mouseover_src;
		Event.observe(single, "mouseover", this.mouseoverFunction);
		Event.observe(single, "mouseout", this.mouseoutFunction);
	},
	register: function()
	{
                var links = Element.getElementsBySelector(document.body, "."+this.page);
                var i = 0;
                while (i<links.length)
                {
			this.registerSingle(links[i]);
                        i++;
                }
	},
	unregisterSingle: function(single)
	{
		Event.stopObserving(single, "mouseover", this.mouseoverFunction);
		Event.stopObserving(single, "mouseout", this.mouseoutFunction);
	},
	unregister: function()
	{
                var links = Element.getElementsBySelector(document.body, "."+this.page);
                var i = 0;
                while (i<links.length)
                {
			this.unregisterSingle(links[i]);
                        i++;
                }
	},
	mouseout: function(e)
	{
		var element = Event.element(e);
		element.src = element.mouseout_src;
	},
	mouseover: function(e)
	{
		var element = Event.element(e);
		element.src = element.mouseover_src;
	}
};


