/**
 * @author Judd
 */

var preloads = Class.create();

preloads.prototype = {
	initialize : function(name, url, up, down, hover, fade){
		if (this.up == null){ this.up = new Array(); }
		if (this.down == null){ this.down = new Array(); }
		if (this.hover == null){ this.hover = new Array(); }
		if (this.state == null){ this.state = new Array(); }
		if (this.url == null){ this.url = new Array(); }
		if (this.fade == null){ this.fade = new Array(); }
		
		this.currdiv = null;
		
		this.up[name] = new Image();
		this.down[name] = new Image();
		this.hover[name] = new Image();
		if (fade == null){
			this.fade[name] = false;
		} else {
			this.fade[name] = true;
		}
		
		if (up != null){ this.up[name].src = up; }
		if (down != null){ this.down[name].src = down; }
		if (hover != null){ this.hover[name].src = hover; }		
		
		/**
		 * this is holds the state of the button,
		 * 0 = up
		 * 1 = hover
		 * 2 = down
		 */
		this.state[name] = 0;
		
		this.url[name] = url;
	},
		
	modifyState : function(name, state) {
		if (this.state[name] != state){
			//alert($(name));
			if (state == 0){
				//alert("UP: " + this.up[name].src);
				$(name).src = this.up[name].src;
			} else if (state == 1){
				//alert("HOVER: " + this.hover[name].src);
				$(name).src = this.hover[name].src;
			} else {
				//alert("DOWN: " + this.down[name].src);
				$(name).src = this.down[name].src;
				if (this.currdiv != name){
					if (this.currdiv != null){
						if (this.fade[name]){
							//new Effect.Fade(this.currdiv + "div", { duration: 1.0, queue: 'front'});
							$(this.currdiv + "div").innerHTML="";
							$(this.currdiv + "div").style.display="none";
						} else {
							new Effect.DropOut(this.currdiv + "div");
						}
						this.currdiv = null;
					}
					if (this.url[name] != null){
						//if (this.currdiv != null){
						//	$(this.currdiv + "div").innerHTML = "";
						//}
						new Ajax.Updater(name + "div", this.url[name]);
						new Effect.Appear(name + "div", { duration: 2.0})
						this.currdiv = name;
					}		
				}						
			}
			this.state[name] = state;
		}
	}
}



