/**
 * toggles (folds and unfolds) a bucket drill-down node 
 * @param link - the link object in the div heirarchy which is passed via onclick
 */
 
var imagePlus = new Image();
imagePlus.src = "images/shared/plus.gif";

var imageMinus = new Image();
imageMinus.src = "images/shared/minus.gif";

/**
 * Public function. Toggles bucket items open/close state.
 * @param element the reference to Prototype element or string Id of element to be opened/closed.
 * @param indicator the reference (or element ID) to Image that shows current state.
 */
function bucketSlide(element, indicator) {
    var target = $(element);
    if (target.style.overflow!='hidden') { 
        bucketClose(target); 
        $(indicator).src=imagePlus.src;
    } else {
        bucketOpen(target); 
        $(indicator).src=imageMinus.src;
    }
}

/** 
 * Private function. Referenced by bucketSlide. Reduces the size of items box to 1 and hides it, 
 * saving the original height.
 */
function bucketClose(element) {
    element.setAttribute('origHeight', element.offsetHeight);
    element.style.overflow = 'hidden';
    element.style.display = 'none';
}

/** 
 * Private function. Referenced by bucketSlide. Shows the items box and than restores it's original 
 * size using Rico's Size effect.
 */
function bucketOpen(element) {
    element.style.display = '';
    $(element).style.overflow='visible';
}

/**
 * Public function.
 * Call this function for each bucken if the buckets should all be closed when the page loads.
 */
function bucketHide(element) {
    var target = $(element);
    target.setAttribute('origHeight', target.offsetHeight);
    target.style.overflow = 'hidden';
    target.style.display = 'none';
}

function toggleNodes(action, nodeClass, moreLinkId, lessLinkId) {	
	var toggleRules = new Array();
	toggleRules[0] = 'bucketDrillDownShowHideNode';
	toggleRules[1] = 'dyansShowHideNode';
	toggleRules[2] = 'alfShowHideNode';
	toggleRules[3] = 'iFoundShowHideNode';
	//set based on what's in moreLessLinks.css
	
	var hiddenItems = document.getElementsByClassName(nodeClass);	
	var newRules = new Array();	
	if (document.styleSheets[0].cssRules)
		newRules = document.styleSheets[0].cssRules
	else if (document.styleSheets[0].rules)
		newRules = document.styleSheets[0].rules
	else return;	
	if(action == 'show') {			
		for (t=0; t < toggleRules.length; t++) {
			if (toggleRules[t] == nodeClass) {
				newRules[t].style.display = 'list-item';				
			}	
		}
		if(moreLinkId){
			document.getElementById(moreLinkId).style.display = 'none';
		}
		if(lessLinkId){
			document.getElementById(lessLinkId).style.display = 'block';
		}	
	}
	if(action == 'hide') {	
		for (t=0; t < toggleRules.length; t++) {
			if (toggleRules[t] == nodeClass) {
				newRules[t].style.display = 'none';
			}
		}			
		if(moreLinkId){
			document.getElementById(moreLinkId).style.display = 'block';
		}
		if(lessLinkId){
			document.getElementById(lessLinkId).style.display = 'none';									
		}		
	}	
}