var widgets;

widgets = new Object();
widgets.objs = new Object();
widgets.objcount = 0;
widgets.basepath = "widgets/";

function slider_click(obj,slider,n,hush)
{
	var i;
	if(slider.selected != null) {
		slider.selected.src = slider.off[slider.current]
	}
	for(i=0;i<slider.steps;i++) {
		if(i < n) {
			document["_obj_" + (i + slider.base)].src = slider.on[i];
		} else {
			document["_obj_" + (i + slider.base)].src = slider.off[i];
		}
	}
	obj.src = slider.on[n];
	slider.current = n;
	slider.selected = obj;
	if (!hush) {
		document[slider.action](n);
	}
}

function slider_set(slider, value)
{
	if(value < 0) return;
	if(value >= slider.steps) return;
	slider_click(document["_obj_" + (value + slider.base)], slider, value, 1);
}

function slider_adjust(slider, adj)
{
	var n;
	n = slider.current + adj;
	if(n < 0) return;
	if(n >= slider.steps) return;
	slider_click(document["_obj_" + (n + slider.base)], slider, n, 1);
}

function widgets_slider(name, steps, action)
{
	var s,i,bn;

	s = new Object();
	s.steps = steps;
	s.off = new Array(steps);
	s.on = new Array(steps);
	s.current = 0;
	s.action = action;
	widgets.objs[name] = s;

	bn = widgets.basepath;

	s.base = widgets.objcount;

	s.on[0] = bn + "slider.endcap.left.filled.gif";
	s.off[0] = bn + "slider.endcap.left.gif";
	for(i = 1; i < (steps - 1); i++){
		s.on[i] = bn + "slider.middle.filled.gif";
		s.off[i] = bn + "slider.middle.gif";
	}
	s.on[steps-1] = bn + "slider.endcap.right.filled.gif";
	s.off[steps-1] = bn + "slider.endcap.right.gif";

//	document.write('<IMG onMouseOver=\'this.src="'+bn+'left_active.gif";\' onMouseOut=\'this.src="'+bn+'left.gif";\' onClick="slider_adjust(widgets.objs.'+name+',-1);" SRC="'+bn+'left.gif">');
	for(i = 0; i < steps; i++) {
		document.write('<IMG NAME="_obj_'+widgets.objcount+'" onClick="slider_click(this,widgets.objs.'+name+','+i+')" SRC="'+s.off[i]+'">');
		widgets.objcount++;		
 	}
//	document.write('<IMG onMouseOver=\'this.src="'+bn+'right_active.gif";\' onMouseOut=\'this.src="'+bn+'right.gif";\' onClick="slider_adjust(widgets.objs.'+name+',1);" SRC="'+bn+'right.gif">');
}


function widgets_radio_group(name)
{
	var r,i;
	r = new Object();
	r.base = widgets.objcount;
	widgets.objs[name] = r;

	for(i = 1; arguments[i]; i++) {
		document.write('<IMG ALIGN=CENTER NAME="_obj_'+widgets.objcount+'" SRC="'+widgets.basepath+'radio_inactive.gif">');
		document.write(arguments[i] + "<BR>");
		widgets.objcount++;
	}
}

function checkbox_adjust(obj, enabled)
{
	var img = document["_obj_"+obj.base];
	if(enabled) {
		obj.enabled = true;
		img.src = obj.on;
	} else {
		obj.enabled = false;
		img.src = obj.off;
	}		
	document[obj.action](enabled);
}

function checkbox_toggle(name)
{
	var obj = widgets.objs[name];	
	if(obj.enabled) {
		checkbox_adjust(obj, false);	
	} else {
		checkbox_adjust(obj, true);
	}
}

function widgets_checkbox(name,action)
{
	var c;
	c = new Object();
	c.base = widgets.objcount;
	c.action = action;
	c.off = widgets.basepath + "checkbox.gif";
	c.on = widgets.basepath + "checkbox.checked.gif";
	c.enabled = false;
	widgets.objs[name] = c;
	widgets.objcount++;
	document.write('<IMG ALIGN=CENTER onClick="checkbox_toggle(\''+name+'\');" NAME="_obj_'+c.base+'" SRC="'+c.off+'">');
}
