// Author: Nicholas Livaditis
// Monday, June 12, 2000
// Javascript 1.1 compliant
// Can work with JS 1.0 if this code is
// inlined script tags (Netscape 3.0 browsers, not worth it)
var infixOff = '_off';  // Unique string in off image
var infixOn = '_on';  // Unique string in on image
document.objLastImg = null;
document.LastImgsrc = null;

// Performs a basic Find and Replace operation on a string
function Replace(Expression, Find, Replace) {
	var pos = 0
	while ( (pos = Expression.indexOf(Find,pos)) >= 0 )
		Expression = Expression.substring(0, pos) + Replace + Expression.substring(pos+Find.length)
	return Expression
}

// This will Roll on the image object specified,
// while rolling off the last image specified.
// Eliminates the need to roll off the image
// in the onMouseOut event
function RollOverOn(objImg) {
	if ( objImg && document.images && objImg != document.objLastImg ) {
		if ( document.objLastImg )
			document.objLastImg.src = Replace(document.objLastImg.src,infixOn,infixOff)
		objImg.src = Replace(objImg.src, infixOff, infixOn)
		document.objLastImg = objImg
	}
}

// Roll over function between infixOff
// and infixOn unique strings
function RollOver(objImg) {
	if ( objImg && document.images ) {
		var imgsrc = objImg.src
		var Img1, Img2;
		if ( imgsrc.indexOf(infixOff) >= 0 ) {
			Img1 = infixOff; Img2 = infixOn
		}
		else {
			Img1 = infixOn;	Img2 = infixOff
		}
		objImg.src = Replace(imgsrc, Img1, Img2)
	}
}

function RollOver2(objImg1, objImg2) {
	if ( objImg1 && objImg2 && document.images ) {
		for (var i = 1; i <= 2; i++) {
			var objImg = eval('objImg' + i)
			var imgsrc = objImg.src
			var Img1, Img2
			if ( imgsrc.indexOf(infixOff) >= 0 ) {
				Img1 = infixOff; Img2 = infixOn
			} else {
				Img1 = infixOn; Img2 = infixOff
			}
			objImg.src = Replace(imgsrc, Img1, Img2)
		}
	}
}

// Rolls to any image specified and saves the current (used with RollBack)
function RollTo(objImg, sImgTo) {
	if ( objImg && sImgTo && document.images ) {         
		document.LastImgsrc = objImg.src                
		objImg.src = sImgTo
	}
}
// Rollback will restore the image saved by RollTo
function RollBack(objImg) {
	if ( objImg && document.images ) 
		objImg.src = document.LastImgsrc
}

// Basic Roll-on and roll-off functions
function RollOn(objImg) {
	if ( objImg && document.images && objImg.src.indexOf(infixOff) >= 0 )
		objImg.src = Replace(objImg.src, infixOff, infixOn)
}

function RollOff(objImg) {
	if ( objImg && document.images && objImg.src.indexOf(infixOn) >= 0 )
		objImg.src = Replace(objImg.src,infixOn,infixOff)
}

// Preloads and argument array of images
function preloadImages() {
	if ( document.images ) {
		var Max = preloadImages.arguments.length
		for(var i = 0; i < Max; ++i )
			(new Image()).src = preloadImages.arguments[i]
	}
}