function setObjStyle(objID) {
    //this function sets method/style for the current object

    if(document.getElementById && document.getElementById(objID)) {
		// W3C
		return document.getElementById(objID).style;
    } 
	else if (document.all && document.all(objID)) {
		// IE4
		return document.all(objID).style;
    } 
	else if (document.layers && document.layers[objID]) {
		// NS4
		return document.layers[objID];
    }
	else {
		return false;
    }
}

function changeObjVis(objID, newVis) {
    styleObj = setObjStyle(objID);
    if(styleObj) {
		styleObj.visibility = newVis;
		return true;
    } 
	else {
		return false;
    }
}

function selectCat(mcObj, scID, y) {
	if(y == undefined)
		y = 0; //set y offset to 0 if y is not passed as an argument
	
	setObjBG(mcObj.id, '#d0e5f8'); //highlight the selected main category
	changeObjVis(scID, 'visible'); //make the sub category box visible
	setPosition(mcObj, scID, y); //align the sub category box
	
	//for testing only and maybe phase 2
	//styleObj.borderTop = '1px solid #3c7fb9';
	//styleObj.borderBottom = '1px solid #3c7fb9';
}	

function unSelectCat(mcObj, scID) {
	changeObjVis(scID, 'hidden'); //hide the selected sub category box
	setObjBG(mcObj.id, '#ffffff'); //reset the backgorund color of the selected main category

	//for testing only and maybe phase 2
	//styleObj.borderTop = '0px';
	//styleObj.borderBottom = '0px';
}

function selectSubCat(scObj) {
	setObjBG(scObj.parentNode.id, '#ffffff');
}

function unSelectSubCat(scObj) {
	setObjBG(scObj.parentNode.id, '#d0e5f8');
}

function setObjBG(objID, color) {
	styleObj = setObjStyle(objID);
	styleObj.backgroundColor = color;
}

function setPosition(mcObj, scID, y) {
	xPos = getPosition(mcObj, 'left');
	yPos = getPosition(mcObj, 'top');
	
	styleObj = setObjStyle(scID);
	
	styleObj.left = xPos + 139;
	styleObj.top = yPos + y;
}

function getPosition(mcObj, pos) {
	if(pos == "left")
		position = mcObj.offsetLeft;
    else if (pos == "top")
		position = mcObj.offsetTop;
	
	tempID = mcObj.offsetParent;
	
	while(tempID != null) {
		if(pos == "left")
			position += tempID.offsetLeft;
	    else if (pos == "top")
			position += tempID.offsetTop;
		
        tempID = tempID.offsetParent;
	}

	return position;
}