/** 
	rollower helpers
	
	Usage:
	
	- mark all <img> elements to be rolled over with some id attributes
	if multiply similar images are present on the page, suffix them with "__${somenumber}" like 
	id="imageA__1" 
	
	- create a rollowerManager object no a page
	var roll = new rollowerManager();
	
	- register rollover images in the object
	roll.registerImage('imageA', 'images/a.gif', 'images/a_over.gif');
	
	- surround image elements with <a> and add the onmouse handlers:
	<a onmouseover="roll.on('imageA'); return true;" onmouseout="roll.off('imageA'); return true;"><img id="imageA__23452" ...></a>
*/

function rolloverManager() {
	this.images = [];
	
	this.registerImage = function(idStr, hrefOff, hrefOn) {
		var offImage = new Image();
		offImage.src = hrefOff;
		
		var onImage = new Image();
		onImage.src = hrefOn;
		
		this.images[this.stripIdSuffix(idStr) + '_off'] = offImage;
		this.images[this.stripIdSuffix(idStr) + '_on'] = onImage;
	}
	
	this.assignCachedSrc = function(idStr, suffix) {
		var imgElem = document.getElementById(idStr);
		var imgCached = this.images[this.stripIdSuffix(idStr) + suffix];
		
		if ( imgElem != undefined && imgCached != undefined ) {
			imgElem.src = imgCached.src;
		}
	}

	this.on = function(idStr) {
		this.assignCachedSrc(idStr, '_on');
	}
	
	this.off = function(idStr) {
		this.assignCachedSrc(idStr, '_off');
	}
	
	this.stripIdSuffix = function(idStr) {
		var idx = idStr.lastIndexOf('__');
		if ( idx != -1 ) {
			return idStr.substr(0, idx);
		} else {
			return idStr;
		}
	}
}