// blogtools.js
// Phil Windley (www.windley.com)
// Use with scriptaculous.js and related code

var folded = new Object();

function toggle_blind(id, init) {

    var elem = document.getElementById(id);

    if(folded[id] == null) { /* set initial state */
	folded[id] = init;
    }

    if(folded[id] == 1) {
	Effect.BlindUp(elem);
	folded[id] = 0;
    } else {
	Effect.BlindDown(elem);
	folded[id] = 1;
    }
}

function mfclose(id) {            
   Effect.Shrink(document.getElementById(id));
   folded[id] = 0;
}

function toggle_shrink(id)  {            
    var elem=document.getElementById(id);
    if(folded[id] == 1) {
	Effect.Shrink(elem);
	folded[id] = 0;
    } else	{
	Effect.Grow(elem);
	folded[id] = 1;
    }
}

function toggle_slideright(id)  {            
    var elem=document.getElementById(id)            
    if(folded[id] == 1) {
	Effect.Puff(elem);
	folded[id] = 0;
    } else	{
	Effect.BlindDown(elem);
	folded[id] = 1;
    }
}

// Embedded Popups
function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function showpopbox(sName,offsetX,offsetY) {
	if (document.getElementById('link_'+sName) != null) {
		// get the position of the associated link
		var xPos = findPosX(document.getElementById('link_'+sName));
		var yPos = findPosY(document.getElementById('link_'+sName));
		// pad the position so the link will not be covered
		xPos = xPos + 5;
		yPos = yPos + 13;
	} else {
		// if there's no link to attach to, put the popup under the nav
		var xPos = 100;
		var yPos = 150;
	}
	if (!isNaN(offsetX) && !isNaN(offsetY)) {
		// move elements if needed
		xPos = xPos + offsetX;
		yPos = yPos + offsetY;
	}
	// opens the embedded popups
	document.getElementById(sName).style.display = 'block';
	document.getElementById(sName).style.left = xPos + "px";
	document.getElementById(sName).style.top = yPos + "px";
}
function showinlinepopbox(sName) {
	// opens the embedded popups
	document.getElementById(sName).style.display = 'block';
}
function hidepopbox(sName) {
	// Closes the embedded popups
	document.getElementById(sName).style.display = 'none';
}