// JavaScript Document
/////////////////////////////////////////
//
//
//FOR DROP DOWN MENU + -
//<div imageid>(imageId)

//<div outside>(parentDivid) this div should have "outside" in the id of the div
//		<div inside> (contentDivid)

//////////////////////////////////////
function Box_DropDownAction(parentDivId, contentDivId, imageId,menuWidth,myid,myct)
{

	var thisBox			= document.getElementById( parentDivId );
	var thisInnerBox	= document.getElementById( contentDivId );
	var thisInnerTop	= parseInt( thisInnerBox.style.top );
	var thisBoxHeight 	= parseInt(thisBox.style.height);
	
	
	
	var parentsToResize = "";
	var p = thisBox.parentNode;
	while (p)
	{
		if (p.id && p.id.indexOf("outside") != -1)
		{
			if (parentsToResize == "")
			{
				parentsToResize = p.id;
			}
			else
			{
				parentsToResize = parentsToResize + "," + p.id;
			}
		}
		
		p = p.parentNode;
	}


	if( thisBoxHeight <= 0 || thisInnerTop < 0)
	{
		thisBox.style.display = "block";
		thisInnerBox.style.display = "block";
		
		thisBox.style.height	= "0px";
		thisBox.style.width		= menuWidth+"px";
		thisInnerBox.style.top  = "0px";
		
		Box_DropDown_Action('open', parentDivId, contentDivId, parentsToResize, imageId,myid,myct);
	}
	else
	{
		Box_DropDown_Action('close', parentDivId, contentDivId, parentsToResize, imageId,myid,myct);
	}
}

function Box_DropDown_Action( thisAction, parentDivId, contentDivId, parentsToResize, imageId,myid,myct)
{
	
	
	
	var thisBox			= document.getElementById( parentDivId );
	var thisInnerBox	= document.getElementById( contentDivId );
	var thisBoxHeight 	= parseInt(thisBox.style.height);
	
	if (parentsToResize)
	{
		var parents = parentsToResize.split(",");
	}
	
	var pixelsPerSecond = parseInt(thisInnerBox.offsetHeight) / 10;
		
	if( thisAction == 'open' )
	{
		if( thisBoxHeight < thisInnerBox.offsetHeight)
		{	
			var pixelsToAdd = pixelsPerSecond;
			
			if (thisBoxHeight + pixelsPerSecond > thisInnerBox.offsetHeight)
			{
				pixelsToAdd = thisInnerBox.offsetHeight - thisBoxHeight;
			}
			
			thisBox.style.height    = thisBox.offsetHeight + pixelsToAdd + "px";
			
			if (parents)
			{
				for (var i = 0; i < parents.length; i++)
				{
					var pBox = document.getElementById(parents[i]);
					pBox.style.height = pBox.offsetHeight + pixelsToAdd + "px";
				}
			}
			
			var myFunction =  "Box_DropDown_Action('open', '" 
						+ thisBox.id + "', '" + thisInnerBox.id + "', '" + parentsToResize + "', '" +imageId +  "','"+ myid +"','"+ myct +"')";
			setTimeout(myFunction, 1 );
			
		}
		else
		{
			Box_DropDown_Arrow( "minus",imageId,myid,myct );
		}
	}
	else if( thisAction == 'close' )
	{
		
		if( thisBoxHeight > 0)
		{
			var pixelsToRemove = pixelsPerSecond;
			
			if (thisBoxHeight - pixelsPerSecond < 0)
			{
				pixelsToRemove = thisBoxHeight;
			}
			
			thisBox.style.height    = thisBoxHeight - pixelsToRemove + "px";
			if (parents)
			{
				for (var i = 0; i < parents.length; i++)
				{
					var pBox = document.getElementById(parents[i]);
					var pBoxHeight 	= parseInt(pBox.style.height);
					pBox.style.height = pBoxHeight - pixelsToRemove + "px";
				}
			}
			
			var myFunction =  "Box_DropDown_Action('close', '" 
						+ thisBox.id + "', '" + thisInnerBox.id  + "', '" + parentsToResize + "', '" +imageId + "', '" + myid +"','"+ myct +"')";
			setTimeout( myFunction, 1 );
		}
		else
		{
			thisBox.style.display = "none";
			thisInnerBox.style.display = "none";
			Box_DropDown_Arrow( "plus",imageId,myid,myct );
		}
	}
}

function Box_DropDown_Arrow( arrowType,imageId,myid,myct )
{
	var arrow="arrow" + myid;
	
	if(arrowType=="minus"){
	document.getElementById( imageId ).className ="treeON2";
	//document.getElementById(myid ).style.visibility = "hidden";
	document.getElementById(arrow).innerHTML = '<img  src="/images/masthead/business/solution/orange-arrow-down.gif"/>';
	}
	if(arrowType=="plus"){
	document.getElementById( imageId ).className ="treeOff2";
	document.getElementById(arrow).innerHTML  = '<img src="/images/masthead/business/solution/orange-arrow.gif"/>';
	/*if(myid!= myct)
	{
		document.getElementById(myid ).style.visibility= "visible";
		
	}*/
	}
	
	
}
