//TOOLS AND FUNCTIONS FOR ACCORDIAN COMPONENT

// IMAGE MANIPULATION AND LOADING FUNCTIONS

// changes an image within a document base to a new url
function swap(name, source){
	try{
		document.images[name].src = source;
	}
	catch(e){
		if(debugMode == true){
			alert("Error: "+e+"\n Name: "+name+"\n Function: swap \n Location: tools.js");
		}
	}
}

// preloads images for rollovers etc
// required variables
// Name: must be an array of the images to be loaded
//
// optional variables
// width, height: may either be single numbers or an array that matches the needs for the images in Name.  
// root: path to the images directory, defaults to ""
function loadImage(name, width, height, root){
	imagesToLoad = new Array(name.length);
	var w;
	var h;
	var r = "";
	if (typeof root != "undefined"){
		r = root;
	}
	
	for (var i = 0; i < imagesToLoad.length ; i++){
		if (typeof width != "undefined"){
			if (typeof width =="object"){
				w = width[i];
			}
			else{ w = width;}
		}
		else {w = "n";}
		if (typeof height != "undefined"){
			if (typeof height == "object"){
				h = height[i];
			}
			else {h = height};
		}
		else {h = "n"}
		if ((w != "n") && (h != "n")){
			imagesToLoad[i] = new Image(w,h);
		}
		else {imagesToLoad[i] = new Image();}
		imagesToLoad[i].src = r + name[i];
	}
}


//  General DHTML functions.  All require setobj()
//

// sets the object string to be used
function setobj(obj){
	var theobject; 
	if (typeof obj == "string"){
		if (obj == "document"){
			theobject = document;
		}
		else{
			theobject = document.getElementById(obj);
		}
	}
	else{
		theobject = obj;
	}
	return theobject;
}

//sets the cursor for an object
function setCursor(name, cstyle){
	var obj = setobj(name);
	try{
		obj.style.cursor = cstyle;
	}
	catch(e){
		if(debugMode == true){
			alert("Error: "+e+"\n Name: "+name+"\n Function: setCursor \n Location: tools.js");
		}
	}
}

// GENERAL STYLE ELEMENTS

// sets the stylesheet text
// equivelent to style="stylesheet:declarations;" in a tag
// styleText: stylesheet:declarations; stylesheet:declarations;
function setStyleText(name, styleText){
	var obj = setobj(name);
	try{
		obj.style.cssText = styleText;
	}
	catch(e){
		if(debugMode == true){
			alert("Error: "+e+"\n Name: "+name+"\n Function: setStyleText \n Location: tools.js");
		}
	}
}

function getStyleText(name){
	var obj = setobj(name);
	var csTxt;
	try{
		csTxt = obj.style.cssText;
	}
	catch(e){
		if(debugMode == true){
			alert("Error: "+e+"\n Name: "+name+"\n Function: getStyleText \n Location: tools.js");
		}
	}
	return csTxt;
}

// sets the current Stylesheet class
function setClass(name,clsName){
	var obj = setobj(name);
	try{
		obj.className = clsName;
	}
	catch(e){
		if(debugMode == true){
			alert("Error: "+e+"\n Name: "+name+"\n Function: setClass \n Location: tools.js");
		}
	}
}



// sets the display type for an item (none = hidden)
function setDisplay(name,dtype){
	var obj = setobj(name);	
	try{
		obj.style.display = dtype;	
	}
	catch(e){
		if(debugMode == true){
			alert("Error: "+e+"\n Name: "+name+"\n Function: setDisplay \n Location: tools.js");
		}
	}
}


