/*
Copyright (c) 2007 Trinair
Author: Robin van der Rijst
*/

var js_buttonImages = {
	
	styleids: null, 
	preloaded: null,
	imageroot: "../images/layout/menu/",
	imageext: "_on.png",
	onclass: "on",
	 	
	/* public functions */
	
	init: function() {
		//document.getElementById should be supported
		if(!document.getElementById) return;
		//Button style names are dynamically generated in 
		//  header.php
		this.styleids = js_buttonStyleNames();
		//preload images
		this.preload();
				
		this.available = true;
	},
	
	on: function(name) {
		var element = document.getElementById(name);
		if(!element) {
			this.last = null;
			return;
		}
		//set classname 'on' to activate different style
		element.className = this.onclass;
		this.last = element;
	},
	
	off: function(){
		if(this.last){
			//undo setting 'on' classname
			this.last.className = null;
		}
	},
	
	/* private functions */	
	preload: function(){
		var size = this.styleids.length;
		this.preloaded = new Array();
		var index;
		for(index = 0; index < size; index++) {
			this.preloaded[index] = new Image();
			var source = this.imageroot+this.styleids[index]+this.imageext;
			this.preloaded[index].src = source;
		}
	}
};
