
/******************************/
/* CFX V5.0 - Button Rollover */
/* cfx_button.js - V5.0       */
/* Copyright 1999             */
/* Carl-Eric Menzel           */
/* Bitforce Media             */
/* RPF Online                 */
/* cfx@bitforce.com           */
/* Nur mit Genehmigung zu     */
/* benutzen!                  */
/******************************/

cfxprivate_preinit('cfx.button = "5.0";');

function cfx_button(name, inact, act) {
	eval(name + " = new cfxprivate_button_obj('" + name + "','" + inact + "','" + act+ "');");
} //endfunction

function cfxprivate_button_obj(name, inact, act) {
	cfx_makeobjindex(this);
	this.name = name;
	this.targ = "cfx_" + name;
	this.state = false;
	this.timeoutid = false;
	this.flashcounter = 0;
	if (cfx.test.imageenabled) {
		this.act = cfxprivate_button_act;
		this.deact = cfxprivate_button_deact;
		if (act.substring(0,5) == "anim:") {
			this.on = eval(act.substring(5,act.length));
			this.doact = cfxprivate_button_doact_anim;
			this.flash = cfx_void;
			this.onanim = new cfxprivate_anim_animdata;
			this.onanim.targ = this.targ;
		} else {
			this.on = new Image();
			this.on.src = act;
			this.doact = cfxprivate_button_doact_simple;
			this.flash = cfxprivate_button_flash;
			this.onanim = false;
		} //endif
		if (inact.substring(0,5) == "anim:") {
			this.off = eval(inact.substring(5,inact.length));
			this.dodeact = cfxprivate_button_dodeact_anim;
			this.flash = cfx_void;
			this.offanim = new cfxprivate_anim_animdata;
			this.offanim.targ = this.targ;
		} else {
			this.off = new Image();
			this.off.src = inact;
			this.dodeact = cfxprivate_button_dodeact_simple;
		} //endif
		this.invert = cfxprivate_button_invert;
	} else {
		this.on = false;
		this.off = false;
		this.act = cfx_void;
		this.deact = cfx_void;
		this.flash = cfx_void;
		this.invert = cfx_void;
	} //endif
} //endfunction

function cfxprivate_button_act() {
	if (cfx.debug) alert(this.targ);
	var args = cfxprivate_button_act.arguments;
	if (args.length) {
		if (cfx.test.timeoutenabled) {			
			this.timeoutid = window.setTimeout(this.name + ".act()",args[0]);
		} else {
			this.act();
		} //endif
	} else {
		if (this.timeoutid) {
			window.clearTimeout(this.timeoutid);
			this.timeoutid = false;
		} //endif
		this.state = true;
		if (this.offanim) {
			this.off.stop(this.offanim);
		} //endif
		this.doact();
	} //endif
} //endfunction

function cfxprivate_button_doact_simple() {
	document.images[this.targ].src = this.on.src;
} //endif

function cfxprivate_button_doact_anim() {
	this.on.play(this.onanim);
} //endif

function cfxprivate_button_deact() {
	var args = cfxprivate_button_deact.arguments;
	if (args.length) {
		if (cfx.test.timeoutenabled) {			
			this.timeoutid = window.setTimeout(this.name + ".deact()",args[0]);
		} else {
			this.deact();
		} //endif
	} else {
		if (this.timeoutid) {
			window.clearTimeout(this.timeoutid);
			this.timeoutid = false;
		} //endif
		this.state = false;
		if (this.onanim) {
			this.on.stop(this.onanim);
		} //endif
		this.dodeact();
	} //endif		
} //endfunction

function cfxprivate_button_dodeact_simple() {
	document.images[this.targ].src = this.off.src;
} //endfunction

function cfxprivate_button_dodeact_anim() {
	this.off.play(this.offanim);
} //endif

function cfxprivate_button_flash(num,delay) {
	if (this.flashcounter < num) {
		this.invert();
		this.flashcounter++
		window.setTimeout(this.name + ".flash(" + num + "," + delay + ");",delay);
	} else {
		this.flashcounter = 0;
	} //endif
} //endfunction

function cfxprivate_button_invert() {
	if (this.state) {
		this.deact();
	} else {
		this.act();
	} //endif
} //endfunction