

/**
 * Box dimension helper
 */
var approxHeightHolder = new Array();
var approxWidthHolder = new Array();

function ApproxHeight(elem, deep)
{	
	//return $(elem).height();
	var h = elem.offsetHeight;
	
	//Early cut. If no overflow, the exact height should be offsetHeight
	// and also cut search deeper than x level
	if (($(elem).css('overflow') != 'visible') || (++deep > 15))
		return h;
	
	if (approxHeightHolder[elem])
		return approxHeightHolder[elem];
	
	for (var i = 0; i < elem.childNodes.length;i++)
	{
		var el = elem.childNodes[i];
	  
	  	//Cut anything not an element node
		if (el.nodeType != 1)
			continue;
	
		if((el.offsetTop + el.offsetHeight) > h)
			h = el.offsetTop + el.offsetHeight;
		
		var apH = ApproxHeight(el, deep) + el.offsetTop;
		if(apH > h)
			h = apH;
	}
	
	//approxHeightHolder[elem] = h;
	return h;
}

function ApproxWidth(elem, deep)
{
	//return $(elem).width();
	var h = elem.offsetWidth;
	
	//Early cut. if no overflow, the exact width should be offsetWidth
	// and also cut search deeper than x level
	if (($(elem).css('overflow') != 'visible') || (++deep > 15))
		return h;
	
	if (approxWidthHolder[elem])
		return approxWidthHolder[elem];
	
	for (var i = 0; i < elem.childNodes.length;i++)
	{
		var el = elem.childNodes[i];
	  
	  	//Cut anything not an element node
		if (el.nodeType != 1)
			continue;
	
		if((el.offsetLeft + el.offsetWidth) > h)
			h = el.offsetLeft + el.offsetWidth;
		
		var apH = ApproxWidth(el, deep) + el.offsetLeft;
		if(apH > h)
			h = apH;
	}
	//approxWidthHolder[elem] = h;
	return h;
	
}

/**
 * Object helper
 */

var extendedObjects = new Array();
function GetObject(oName)
{
	return $('#'+oName) ? $('#'+oName)[0] : null;
	/*if (!extendedObjects[oName])
		extendedObjects[oName] = $('#'+oName);
	return extendedObjects[oName];//MM_findObj(oName, false);*/
}

/**
 * Rollover and menu helpers
 */
var hideTimers = new Array();
var hideShowDefs = new Array();

function DoHide(el)
{
	var elO = GetObject(el);
	//elO.style.visibility = "hidden";
	$(elO).hide();
	if ((hideShowDefs[elO] != false) && (hideShowDefs[elO] != null))
	{
		//hideShowDefs[elO].style.visibility = "visible";
		$(hideShowDefs[elO]).show();
	}
}

function ResetHideDelay(el)
{
	if((hideTimers[el] != null) && (hideTimers[el] != false))
	{
		clearTimeout(hideTimers[el]);
		hideTimers[el] = null;
	}
}

function StartHideDelay(el)
{
	//alert("starthide");
	if((hideTimers[el] != null) && (hideTimers[el] != false))
	{
		return;
	}
	hideTimers[el] = setTimeout("DoHide('" + el.id + "');", 500);
}

function SetMouseOutHideDelayed(toHideElement, toShowElement)
{
	 
	hideShowDefs[toHideElement] = toShowElement;
	
	/*toHideElement = $(toHideElement);
	toShowElement = $(toShowElement);
	*/
	$(toHideElement).mouseout(function(){ StartHideDelay(toHideElement);});
	$(toHideElement).mouseover(function(){ ResetHideDelay(toHideElement);});
	
	$('#' + $(toHideElement).id + ' > *').mouseout(function(){ StartHideDelay(toHideElement); });
	$('#' + $(toHideElement).id + ' > *').mouseover(function(){ ResetHideDelay(toHideElement); });
}


function SetRollOver(roElement)
{
	var el = $(GetObject(roElement));
	el.initImage = el.attr('src');
	el.rollOverImage = el.attr('alt');
	el.attr('alt', "");
	var imPath = el.attr('src').substr(0, el.attr('src').lastIndexOf("/"));
	
	el.mouseover(function(){el.attr('src', imPath + "/" + el.rollOverImage);});
	el.mouseout (function(){el.attr('src',  el.initImage);});
}









