var expandingModule = 'right1', expandSpeed = 20, timerSpeed = 3, bottomPadding = 10;
var xx = new Array();
var imageOnSuffix = '-selected', imageOffSuffix = '', imageTopOffSuffix = '-top';
function loadMe(args) {
	modulelinkidsarray = args.split(",");
	for (x=0;x<modulelinkidsarray.length;x++) {
		eleid = modulelinkidsarray[x];
		thisele = document.getElementById(eleid);
		if (x==0 && modulelinkidsarray.length > 1) {
			thisele.style.height = getElementHeight(eleid) + bottomPadding + 'px';	
			thisele.originalHeight = getElementHeight(eleid);
		} else {
			thisele.style.display = 'block'; // show, in order to get height
			thisele.style.height = getElementHeight(eleid) + 'px'; // get height
			thisele.originalHeight = getElementHeight(eleid) + bottomPadding;
			thisele.style.display = 'none'; // hide again
		}
	}
}
function getElementHeight(eleid) {
	thisele = document.getElementById(eleid);
	return thisele.offsetHeight;
}

function expandModule(moduleprefix, thisindex, maxindex, cancelifactive, changeImage) {
	moduleid = moduleprefix + thisindex;
	thismodule = document.getElementById(moduleid);
	modulelinkidsarray = new Array();
	n = 0;
	for (x=1;x<=maxindex;x++) {
		if (x != thisindex) {
			modulelinkidsarray[n] = moduleprefix + x;
			n++;
		}
	}
	if (expandingModule == moduleid && cancelifactive == 1) { // you've clicked on the current expanded module		
	} else { // expand this module
		if (changeImage == true) {// change image based on moduleid and modulelinkids
			thismoduleimage = document.getElementById(moduleid + '-image');
			imageSrc = thismoduleimage.src;
			imageSrcNoExt = imageSrc.substr(0, imageSrc.length - 4);
			imageSrcExt = imageSrc.substr(imageSrc.length - 4, 4);
			re = new RegExp(imageOffSuffix, 'gi');
			imageSrcNoExt = imageSrcNoExt.replace(re, '');
			re = new RegExp(imageTopOffSuffix, 'gi');
			imageSrcNoExt = imageSrcNoExt.replace(re, '');
			imageSrcNew = imageSrcNoExt + imageOnSuffix + imageSrcExt;
			thismoduleimage.src = imageSrcNew;
			for (x=0;x<modulelinkidsarray.length;x++) {
				thismoduleimage = document.getElementById(modulelinkidsarray[x] + '-image');
				imageSrc = thismoduleimage.src;
				imageSrcNoExt = imageSrc.substr(0, imageSrc.length - 4);
				imageSrcExt = imageSrc.substr(imageSrc.length - 4, 4);
				
				re = new RegExp(imageOnSuffix, 'gi');
				imageSrcNoExt = imageSrcNoExt.replace(re, '');
				re = new RegExp(imageTopOffSuffix, 'gi');
				imageSrcNoExt = imageSrcNoExt.replace(re, '');
				thiscurrentindex = modulelinkidsarray[x].substr(5, modulelinkidsarray[x].length - 5);
				if (thiscurrentindex < thisindex) {
					imageSrcNew = imageSrcNoExt + imageTopOffSuffix + imageSrcExt;
				} else {
					imageSrcNew = imageSrcNoExt + imageOffSuffix + imageSrcExt;
				}
				thismoduleimage.src = imageSrcNew;
			}
		}
		if (thismodule.style.display != 'block') {
			thismodule.style.height = '0px';
			thismodule.style.display = 'block';
		}
		expandingModule = moduleid;
		startTimer(moduleid,'plus');
		
		if (modulelinkidsarray.length > 0) {
			for (x=0;x<modulelinkidsarray.length;x++) {
				startTimer(modulelinkidsarray[x],'minus');
			}
		}
	}	
}
function startTimer(eleid, direction) {
	xx[xx.length] = setTimeout("expandContract('"+eleid+"', '"+direction+"')", timerSpeed);
}
function expandContract(eleid, direction) {
	thisele = document.getElementById(eleid);
	if (direction == 0) { // simple expand/contract, no animation
		if (thisele.style.display == 'block') {
			thisele.style.display = 'none';
		} else {
			thisele.style.display = 'block';
		}
	} else { // animated movement
		restartTimer = 1;		thiseleheight = thisele.style.height;
		thiseleheight = thiseleheight.substring(0,(thiseleheight.length-2))*1;
		var useragent = navigator.userAgent;
		var isIE6 = (useragent.indexOf('MSIE 6.0') > -1) ? true : false;
		if (direction == 'plus') {
			if (thiseleheight + expandSpeed > thisele.originalHeight || isIE6 == true) {
				thisele.style.height = thisele.originalHeight + 'px';
				restartTimer = 0;
			} else {
				thisele.style.height = thiseleheight + expandSpeed + 'px';
			}
			//document.getElementById('debug').value = expandingModule;
		} else {
			if (thiseleheight - expandSpeed < 0 || isIE6 == true) {
				thisele.style.height = 0 + 'px';
				restartTimer = 0;
				thisele.style.display = 'none';
			} else {
				thisele.style.height = thiseleheight - expandSpeed + 'px';
			}
		}
		if (restartTimer == 1) {
			xx[xx.length] = setTimeout("expandContract('"+eleid+"', '"+direction+"')", timerSpeed);
		}
	}
}