/**
 * ********************************************************
 *  JAVASCRIPT STYLE FUNCTIONS (DHTML)
 *
 * Most CSS attributes are represented as properties in the Style object. 
 * For non-hyphenated attributes, the property is identical, while for 
 * hyphenated attributes, drop the hyphen and capitalize the first letter 
 * following the hyphen.
 *
 * Examples:
 * color = color
 * padding = padding
 * background-color = backgroundColor
 * border-top-width = borderTopWidth
 */  

function setVis(on, ref)
{
	refArray = ref.split(',');
	for (j=0; j<refArray.length; j++) {

		var ref_value = refArray[j];


		if (on) {
			setStyle(ref_value, 'visibility', 'visible');
			setStyle(ref_value, 'display', 'block');
		} else {
			setStyle(ref_value, 'visibility', 'hidden');
			setStyle(ref_value, 'display', 'none');
		}

	}
}

function toggleVis(ref)
{

    if (getStyle(ref, 'visibility') == 'hidden') {
		setVis(true, ref);
    } else {
		setVis(false, ref);
    }
}

function toggleLabel(ref, label_hid, label_vis)
{
	var refLabel;
	refLabel = ref + 'ToggleSwitch';
	if (getStyle(ref, 'visibility') == 'hidden') {
		setLabel(refLabel, label_hid);
	} else {
		setLabel(refLabel, label_vis);
	}
}

function cycleVis(ref, msec)
{
	tmp = ref.split(",");
	var cycle_msec = tmp.length * msec;
	timeVis(ref, msec);
	setInterval('timeVis("'+ ref +'", '+ msec +')', cycle_msec);
}

function timeVis(ref, msec)
{	
	ref = ref.split(",");
	fade = 300;

	// assuming the first element is already visible
    for (i=1; i<=ref.length; i++) {
		setStyle(ref[i-1], 'position', 'absolute');
		setStyle(ref[i-1], 'top', '0px');
		setStyle(ref[i-1], 'left', '0px');
		prev = ref[i-1];
		setTimeout('fadeOut("' + prev +'", '+ fade +')', msec * i);

		// after fading out the last element go back and fade in first element
		if (i < ref.length) {
			curr = ref[i];
		} else {
			curr = ref[0];
		}
		setTimeout('fadeIn("' + curr +'", '+ fade +')', msec * i);
	}
}	

function fadeIn(ref, msec)
{
	var speed = Math.round(msec / 100);
	var timer = 0;
	setOpacity(ref, 0);
	setVis(true, ref);
	for (i=0; i<=100; i++) {
		setTimeout("setOpacity('"+ ref +"', "+ i +")", (timer * speed));
		timer++;
	}
}

function fadeOut(ref, msec)
{
	var speed = Math.round(msec / 100);
	var timer = 0;
	for (i=100; i>=0; i--) {
		setTimeout("setOpacity('"+ ref +"', "+ i +")", (timer * speed));
		timer++;
	}
	setTimeout("setVis(false, '"+ ref +"')", (timer * speed));
}

function setOpacity(ref, opacity)
{
	var elem = getStyle(ref);
    elem.opacity = (opacity / 100);
    elem.MozOpacity = (opacity / 100);
    elem.KhtmlOpacity = (opacity / 100); 
	elem.filter = "alpha(opacity=" + opacity +")";
}
		

/* 2 methods to set style to hidden on page load
1: set the tags style attribute
2: set the style on pageload

function pageLoad()
{
	ref = array('baaxStats');
	for (i=0; i<ref.length; i++) {
		setVis(false, ref[i]);
	}
}
addEvent(window,'load',pageLoad);
*/

function setLabel(ref, label)
{
    var obj = getObj(ref); 
    if (obj) {
        if (obj.childNodes[0]) {
            obj.childNodes[0].nodeValue = label;
        } else if (obj.value) {
            obj.value = label;
        } else if (obj.innerHTML) {
            obj.innerHTML = label;
        }
    }
}

function scroll(ref) {
	var obj = getObj(ref);
	window.scrollTo(0,obj.scrollHeight);
}
