var bResizing = false;
var nResizeWidth = 15;
var resizeType = "";
var bCollapsed = false;
var lastSize = "";
var lastClass = "close";
var mozilla = false;			// ADDED BY SMU

window.onload = function()
{
	resizeType = window.location.href.charAt(window.location.href.lastIndexOf("/") + 1);
	
	document.onmousemove = getResizeMouse;
	
	var currElement = document.getElementById(resizeType + 'resize');
	currElement.onmousedown = function(){startResize()};
	currElement.onmouseup		= function(){endResize()};
	currElement.onmouseout	= function(){cancelResize()};
	
	var currElement = document.getElementById('toggle');
	currElement.onmouseover	= function(){changeImage(true, this)};
	currElement.onmouseout	= function(){changeImage(false, this)};
	currElement.onmouseover	= function(){changeImage(true, this);doQuickTip()};
  currElement.onmouseout	= function(){changeImage(false, this);parent.header.quickTip('')};	
	currElement.onclick	= function(){toggleResize()};		
}

function doQuickTip()
{
	if (resizeType == "v")
	{
		if (bCollapsed)
		{
			tip = top.strTipMaximizeTree;
		}
		else
		{
			tip = top.strTipMinimizeTree;
		}
	}
	else
	{
		if (bCollapsed)
		{
			tip = top.strTipMaximizeOverview;
		}
		else
		{
			tip = top.strTipMinimizeOverview;
		}	
	}
	parent.header.quickTip(tip);
}

function changeImage(activate, elem)
{
	if (activate)
	{
		elem.className = lastClass + "Active";
	}
	else
	{
		elem.className = lastClass;
	}
}

function getResizeMouse(Event)
{
  if (Event)
  {
    oEvent = Event;
    mozilla = true;
  }
  else
  {
    oEvent = event;
    mozilla = false;
  }
  
  if (!oEvent)
  {
    return;
  }
  else
  {
    if (!parent.document.getElementById(resizeType + 'Resize'))
    {
      window.setTimeout("getResizeMouse(Event);", 100);  
    }
    else
    {
      newX = oEvent.clientX;
      newY = oEvent.clientY;
      if (bResizing)
      {
        resizeElem = parent.document.getElementById(resizeType + 'Resize');    
        
 				if (resizeType == "v")
				{         
					sCols = resizeElem.cols;
					aCols = sCols.split(",");

					nCols = eval(aCols[0]) + newX - (nResizeWidth/2);
					if (nCols > nResizeWidth)
					{
						sCols = nCols + ",*";
						resizeElem.cols = sCols;
					}
        }
        // ADDED BY SMU
        else
        {
					sRows = resizeElem.rows;
					aRows = sRows.split(",");

					nRows = eval(aRows[2]) - newY + (nResizeWidth/2);
					if (nRows > nResizeWidth)
					{
						sRows = "*,15," + nRows;
						resizeElem.rows = sRows;
					}
				}					
      }      
    }
  }
}

function toggleResize()
{
  resizeElem = parent.document.getElementById(resizeType + 'Resize'); 
  if (!resizeElem || !document.getElementById('toggle'))
  {
    window.setTimeout("toggleResize();", 100);          
  }
  else 
  {
    sCols = resizeElem.cols;
    sRows = resizeElem.rows;
    if (!bCollapsed)
    {
      if (resizeType == "v")
      {
      	lastSize = sCols;
      	resizeElem.cols = "15,*";
      }
      else
      {
      	lastSize = sRows;
      	resizeElem.rows = "*,15,0"
      }
      document.getElementById('toggle').className = "open";
      lastClass = "open";
      bCollapsed = true;
    }
    else
    {
    	if (resizeType == "v")
    	{
      	resizeElem.cols = lastSize;
      }
      else
      {
      	resizeElem.rows = lastSize;
      }
      lastSize = "";
      document.getElementById('toggle').className = "close"; 
      lastClass = "close";
      bCollapsed = false;
      // ADDED BY SMU
			if (!parent.overview)
			{
				parent.model.actualizeAS();
			}
			else
			{
				parent.overview.resizeAS();
			}
    }
  }
}

function startResize()
{
	bResizing = true;
}

function endResize()
{
	if (!parent.model)
	{
		window.setTimeout("endResize();", 100);
	}
	else
	{
		if (bResizing)
		{
			// ADDED BY SMU
			if (!parent.overview)
			{
				parent.model.actualizeAS();
			}
			else
			{
				parent.overview.resizeAS();
			}
		}
		bResizing = false;
	}
}

function cancelResize()
{
	if (mozilla)
	{
		endResize();
	}
}