//===============================================================
// Skriptlib supporting the AmberMenu script, 2004-01-16
// Copyright 2004 Michael van Ouwerkerk (http://13thparallel.org)
//===============================================================
var Skriptlib = {
	getElement : function( id ){
		var elm = null;
		if( document.getElementById ) elm = document.getElementById( id );
		else if( document.all ) elm = document.all[ id ];
		else if( document.layers ) elm = this.getElementAux( id );
		return elm;
	},

	getElementAux : function( id, doc ){
		if( !doc ) doc = document;
		var layer = doc.layers[ id ];
		for( var i = 0; !layer && i < doc.layers.length; i++ ) {
			layer = this.getElementAux( id, doc.layers[ i ].document );
		}
		return layer;
	},
	
	getStyleObj : function( id ){
		var style = null;
		var elm = this.getElement( id );
		if( elm ) style = elm.style ? elm.style : elm;
		return style;
	}
};

var Img = {
	preloader : new Array(),
	stack : new Array(),
	
	// Example: Img.swap('imgMinimalsm', 'frameMain', 'images/minimalsm_on.gif')
	// 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];
		}
	},
	
	// Example: Img.restore()
	restore : function() {
		while (this.stack.length) this.stack.pop().src = this.stack.pop();
	},
	
	// 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];
		}
	},
	
	// 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
