// preload image function
function preload(active_name,image_names,directory,extension) {
	image_names = image_names.split(",");
	if (!directory) directory = "images";
	if (!extension) extension = "gif";
	for (i=0; i < image_names.length; i++) {
		this_name = image_names[i];
		this_image = directory + "/" + this_name;
		eval(this_name + "_off = new Image()");
		if (this_name == active_name) {
			eval(this_name + "_off.src = '" + this_image + "_act." + extension + "'");
		} else {
			eval(this_name + "_off.src = '" + this_image + "_off." + extension + "'");
		}
		eval(this_name + "_on = new Image()");
		eval(this_name + "_on.src = '" + this_image + "_on." + extension + "'");
	}
}

// rollover image function
function change(name, state) {
	eval('document.images.' + name + '.src = ' + name + '_' + state + '.src');
}


// functions to show/hide content by id - used in other functions
function show_content(this_id) {
	if (document.getElementById(this_id) != null)
	document.getElementById(this_id).style.display = "block";
}

function hide_content(this_id) {
	if (document.getElementById(this_id) != null)
	document.getElementById(this_id).style.display = "none";
}

// glossary popup function
function glossary(term) {
    if (term) {
        newwindow = window.open("/CEF/Learn/Glossary.aspx?word=" + term + "#" + term, "Glossary", "width=640,height=480,scrollbars=1,resizable=1,menubar=0,toolbar=0,location=0,status=0,directories=0,copyhistory=0");
    } else {
        newwindow = window.open("/CEF/Learn/Glossary.aspx", "Glossary", "width=640,height=480,scrollbars=1,resizable=1,menubar=0,toolbar=0,location=0,status=0,directories=0,copyhistory=0");  
    }
}

// generic popup function
function popup(name) {
        newwindow = window.open(name + ".aspx", "newwindow", "width=640,height=480,scrollbars=1,resizable=1,menubar=0,toolbar=0,location=0,status=0,directories=0,copyhistory=0");
}

// functions to show/hide features
function toggle_feature(active,total) {

    for (i=1; i<= total; i++) {
        if (i == active) {
            if (document.getElementById("feature" + i).style.display == "block") {
                hide_content("feature" + i);
                document.getElementById("button" + i).style.background ="#afbcba";
            } else {
                show_content("feature" + i);
                document.getElementById("button" + i).style.background ="#df7a1c";
            }
						
        } else {
            hide_content("feature" + i);
            document.getElementById("button" + i).style.background ="#afbcba";
        }
    }
}
			
function show_all_features(total) {
    for (i=1; i<= total; i++) {
        show_content("feature" + i);
        document.getElementById("button" + i).style.background ="#df7a1c";
    }
}
			
function hide_all_features(total) {
    for (i=1; i<= total; i++) {
        hide_content("feature" + i);
        document.getElementById("button" + i).style.background ="#afbcba";
    }
}
			
// Positions page at top of specified element
function ScrollElementIntoView(idOfElementToScrollIntoView)
{
	var elementToScrollIntoView = document.getElementById(idOfElementToScrollIntoView);
	if (elementToScrollIntoView)
	{
		if (elementToScrollIntoView.scrollIntoView)
		{
			elementToScrollIntoView.scrollIntoView();
		}
	}
}
