//===================================================
// Image Manipulation Routines
// v1.1: 2002-04-19
// Author: Michael van Ouwerkerk - speedingrhino.com
//===================================================

if ( !Array.prototype.push ){
	Array.prototype.push = function(){
		for ( var i = 0; i < arguments.length; i ++ ) this[ this.length ] = arguments[ i ];
		return this.length;
	}
}

if ( !Array.prototype.pop ){
	Array.prototype.pop = function(){
		var lastitem = this.length > 0 ? this[ this.length - 1 ] : undefined;
		if ( this.length > 0 ) this.length--;
		return lastitem;
	}
}

var Img = {
	preloader : new Array(),
	stack : new Array(),
	
	//=======================================================================================================================
	// The Img.swap arguments are triplets of id + frame + src strings.
	// There can be as many triplets in a call as you want.
	// Example: Img.swap('imgMinimalsm', 'frameMain', 'images/minimalsm_on.gif')
	// If no frames are used, just give null or an empty string for the frame argument.
	// Example: Img.swap('imgMinimalsm', null, 'images/minimalsm_on.gif', 'imgSuprematism', '', 'images/suprematism_on.gif')
	//=======================================================================================================================
	swap : function() {
		var img = null;
		for (var i=0; i<arguments.length; i+=3) {
			img = this.find(arguments[i], arguments[i+1]);
			if (!img || !arguments[i+2]) continue;
			this.stack.push(img.src);
			this.stack.push(img);
			img.src = arguments[i+2];
		}
	},
	
	//================================================================
	// Img.restore sets all the images back to their original source.
	// The Img.stack array is emptied at the same time.
	// Example: Img.restore()
	//================================================================
	restore : function() {
		while (this.stack.length) this.stack.pop().src = this.stack.pop();
	},
	
	//==============================================================================
	// Img.preload - preloads images.
	// Arguments are as many source strings as you want.
	// Example: Img.preload('images/minimalsm_on.gif', 'images/suprematism_on.gif')
	//==============================================================================
	preload : function() {
		for (var i=0; i<arguments.length; i++) {
			this.preloader.push(new Image());
			this.preloader[this.preloader.length-1].src = arguments[i];
		}
		
	},
	
	//=======================================================================================================
	// Img.find takes an id string as argument and returns a js reference to the image.
	// This method is used primarily for Netscape 4, to automatically find images that are nested in layers.
	// It can now also find an image in a frame, if the frame's name is given in the function call.
	// Example: Img.find('imgMinimalsm', 'mainFrame')
	//=======================================================================================================
	find : function(id, frame, d) {
		var img = null;
		if (!d) {
			if (frame && top[frame]) d = top[frame].document;
			else d = document;
			if (!d) return null;
		}
		if (d.images) img = d.images[id];
		else if (d.getElementById) img = d.getElementById(id);
		for (var i=0; !img && d.layers && i<d.layers.length; i++){
			img = this.find(id, null, d.layers[i].document);
		}
		return img;
	}
}
// end