dojo.require("dojo.html");
dojo.require("dojo.fx.html");

wipeShow2 = function(nodeId, callback) {
	var node = dojo.byId(nodeId);

	// Calculate the expanded height
	var overflow = dojo.html.getStyle(node, "overflow");
	node.style.overflow = "hidden";
	node.style.height = "0px";
	dojo.html.show(node);
	var height = node.scrollHeight;

	sinWipe(nodeId, 0, height, getDx(height), 0, function() { 
													node.style.overflow = overflow;
													node.style.height = "auto";
													if(callback) { callback(node); }
												});
}

wipeHide2 = function(nodeId, callback) {
	var node = dojo.byId(nodeId);
	var height = node.offsetHeight;
	var overflow = dojo.html.getStyle(node, "overflow");
	node.style.overflow = "hidden";
	
	sinWipe(nodeId, height, 0, getDx(height), 0, function() {if(callback) { callback(node); }});
}

getDx = function(height) {
	var steps = Math.round(height / 45); // duration / 5.0;
	steps = (steps > 15 ? 15 : (steps < 7 ? 7 : steps));
	var dx = Math.PI / steps;
	return dx;
}

pi = Math.PI;
sinWipe = function(nodeId, startHeight, endHeight, dx, xVal, cb) {
	var node = dojo.byId(nodeId);
	
	xVal += dx;
	if(xVal > pi) xVal = pi;
	var dh =  (endHeight-startHeight)*(1.0-Math.pow((1.0+Math.cos(xVal))/2.0, 2));
	var newH = startHeight + dh;

	newH = Math.round(newH > endHeight && endHeight > startHeight ? endHeight : (newH < endHeight && endHeight < startHeight ? startHeight : newH));
	newH = (newH > 0 ? newH : 0);
	node.style.height = newH + 'px';
	if(endHeight == 0 && newH == 0)
	{
		node.style.display = 'none';
	}
	
	if(xVal == pi) {
		if(cb) window.setTimeout(cb, 75);
		return;
	}

	window.setTimeout(function() { sinWipe(nodeId, startHeight, endHeight, dx, xVal, cb);}, 75);
}

function hideInlineSpecs(elem, url) {
  // Fix up the open link to do nothing while we close
	var linkElem = dojo.byId(elem + 'link');
	linkElem.onclick = function() { return false;};

	var openArrow = dojo.byId(elem + 'openarrow');
	openArrow.style.display = 'none';
	var closedArrow = dojo.byId(elem + 'closedarrow');
	closedArrow.style.display = 'inline';
	
	wipeHide2(elem,function() {linkElem.onclick = function() {showInlineSpecs(elem, url); return false;};});
}

function showInlineSpecs(elem, url) {
	// Fix up the open link to do nothing while we open
	var linkElem = dojo.byId(elem + 'link');
	linkElem.onclick = function() { return false;};
	
	var openArrow = dojo.byId(elem + 'openarrow');
	openArrow.style.display = 'inline';
	var closedArrow = dojo.byId(elem + 'closedarrow');
	closedArrow.style.display = 'none';
	
	wipeShow2(elem, function() {linkElem.onclick = function() { hideInlineSpecs(elem, url); return false;};});
}