
function cntY(e)
{
  if(!e.offsetTop) e = e.offsetParent;
  for(var y=0;e ; e = e.offsetParent) y += e.offsetTop; 
  return y; 
}
function cntX(e)
{  
  if(!e.offsetLeft) e = e.offsetParent;
  for(var x=0;e ; e = e.offsetParent) x += e.offsetLeft; 
  return x; 
}
function getX(e)
{  
  var s = getStyle(e);
//  return parseInt(s.left) || s.pixelLeft || cntX(e) || 0 ;	
  return cntX(e) || parseInt(s.left) || s.pixelLeft || 0 ;	
}
function getY(e)
{  
  var s = getStyle(e);
  //return parseInt(s.top) || s.pixelTop || cntY(e) || 0 ;	
  return cntY(e) || parseInt(s.top) || s.pixelTop || 0 ;	
}
function getW(e)
{
  return e.offsetWidth || getStyle(e).clip.width || getStyle(e).pixelWidth || 0; 
}
function getH(e)
{
  return e.offsetHeight || getStyle(e).clip.height ||  getStyle(e).pixelHeight || 0
}
function moveTo(e,x,y)
{
  getStyle(e).left=x;
  getStyle(e).top=y;
}
function moveBy(x,y)
{
  getStyle(e).left = getX(e) + x;	
  getStyle(e).top = getY(e) + y;	
}
function ActiveObject(c)
{
	this.Contex = c;
	this.src=null;
	this.lcolor=null;
	this.Star = null;
	this.StarSelection = null;
}
function ActiveContextObject(c,a)
{
	this.Contex = c;
	this.ActiveStyle = a;
	//this.OriginalStyle = o;
}


var StarWayDrawTimer = null;
var OpenStarWay = new Array();
var ActiveStar = null;
var CurrentContex = null;
var NewContex=null;

function getStarContext(Star)
{	
	var x = Star.parentNode;
	while( x.getAttribute("id")=="" || x.getAttribute("id")==null )
	{	
		x = x.parentNode;
	}
	return x;	
}
 function GetKid(eSrc,sTagName)
  {
    var cKids=eSrc.childNodes;
    if(cKids==null) cKids=eSrc.children;
    for (var i=0;i<cKids.length;i++)
    {
     if (sTagName==cKids[i].tagName) return cKids[i];
      var cSub=GetKid(cKids[i],sTagName);
	  if(cSub) return cSub; 
    }
    return false;
  }

function getMnuMenber(sObj,tId)
{
     	var cKids=sObj.parentNode.childNodes;
    	if(cKids==null) cKids=sObj.parentNode.children;
	for (var i=0;i<cKids.length;i++)
    	{
     		if (tId==cKids[i].id) return cKids[i];
    	}
return null;
}


function overStar(Star, ConstellationId,ContexId ,AStyleId,Pos,ox,oy)
{


	// FOR IE BROWSER
//if(window.event.srcElement.tagName=="DIV") return;
	clearTimeout(StarWayDrawTimer);
	cc = getStarContext(Star);
	aso = getStyle(document.getElementById(AStyleId));
	CurrentContex = new ActiveContextObject(cc,aso);
	NewContex=null;
	ActiveStar = Star;
	UpdatePath();
	if(ConstellationId)
	{
		ncs = document.getElementById(ConstellationId);
		if(ncs)	
		{	
			switch(Pos)
			{
			case 'b':
				getStyle(ncs).left = getX(Star) + ox;
				getStyle(ncs).top = getY(Star) + getH(Star) + oy;	
				break;
			case 'r':
				getStyle(ncs).left = getX(Star) + getW(Star) + ox;
				getStyle(ncs).top = getY(Star) + oy;	
				break;
			}
			getStyle(ncs).visibility = 'visible';	
			//getStyle(ncs).display = 'block';	
			aso = getStyle(document.getElementById(ConstellationId+"_A"));
			NewContex = new ActiveContextObject(ncs,aso)
			OpenStarWay[OpenStarWay.length] = new ActiveObject(NewContex);
		}
	}
}	

 function SetKidStyle(oParent,cls)
  {
    var cKids = (oParent.children) ?  oParent.children : oParent.childNodes;
    if(cKids==null) return;
    for (var i=0;i<cKids.length;i++)
    {
	  if(cKids[i].getAttribute)
	  {
        if(cKids[i].getAttribute("aclass"))
        {
      		cKids[i].className=cls;
        } 
      SetKidStyle(cKids[i],cls);
      }
    }
   
  }


function ClearStarSelection(o)
{
	if(o) 
	{
		if(o.Star)
		{
			if(o.cn)
			{
				o.Star.className = o.cn;
				//tmp = o.Star.className;
				//o.Star.className= o.Star.aclass;
				//o.Star.aclass = tmp;
				SetKidStyle(o.Star, o.cn);
			}
			if(o.nbgColor) getStyle(o.Star).backgroundColor = o.nbgColor;
			if(o.nBorder) getStyle(o.Star).border = o.nBorder;
			if(o.nColor) getStyle(o.Star).color = o.nColor;
			var td = GetKid(o.Star,"TD");
			if(td)
			{
				if(getStyle(td).backgroundColor && o.lcolor) getStyle(td).backgroundColor = o.lcolor;
			}
		
			var img = GetKid(o.Star,"IMG");
			if(img && img.getAttribute("osrc"))
			{
				img.src = o.src;
			}
		}
/*
		if(o.StarSelection)
		{
			o.Star.onmouseover = o.StarSelection.onmouseover;
			o.Star.onmouseout = o.StarSelection.onmouseout;
			o.StarSelection.removeNode(true);
			o.StarSelection=null;
		}
*/
	}
}
 
function StarSelection(ao)
{
	if(CurrentContex==null) return;
	if(  ao.Contex.ActiveStyle.backgroundColor )
	{
		ao.nbgColor = getStyle(ao.Star).backgroundColor;
		getStyle(ao.Star).backgroundColor = ao.Contex.ActiveStyle.backgroundColor;
	}
	if(ao.Contex.ActiveStyle.color)
	{
		ao.nColor = getStyle(ao.Star).color;
		getStyle(ao.Star).color = ao.Contex.ActiveStyle.color;
	}
	if(ao.Contex.ActiveStyle.border)
	{
		ao.nBorder = getStyle(ao.Star).border;
		getStyle(ao.Star).border = ao.Contex.ActiveStyle.border;
	}
	if(ao.Star.getAttribute("aclass"))
	{
		ao.cn = ao.Star.className;
		ao.Star.className= ao.Star.getAttribute("aclass");
		SetKidStyle(ao.Star, ao.Star.getAttribute("aclass"));
	}
	var td = GetKid(ao.Star,"TD");
	if(td)
	{
		if(getStyle(td).backgroundColor)
		{	
			if(ao.Contex.ActiveStyle.backgroundColor)
			{
				ao.lcolor = getStyle(td).backgroundColor;
				getStyle(td).backgroundColor = ao.Contex.ActiveStyle.backgroundColor;
			}
		}
	}
	
	var img=GetKid(ao.Star,"IMG");
	if(img && img.getAttribute("osrc"))
	{
		ao.src = img.src;
		img.src = img.getAttribute("osrc");
	}
/*	
	if(ao.StarSelection || CurrentContex==null) return;
	var ss = document.createElement('div');
	getStyle(ss).position = 'absolute';
	getStyle(ss).border = "solid 1px";
	getStyle(ss).left = ao.Star.offsetParent.offsetLeft; //getX(Star);
	getStyle(ss).top =  ao.Star.offsetParent.offsetTop; //getY(Star);
	getStyle(ss).width = getW(ao.Star) ;
	getStyle(ss).height = getH(ao.Star);
	getStyle(ss).zIndex = 1000;//getStyle(Star).zIndex - 1;
	getStyle(ss).backgroundColor = "green";
	getStyle(ss).filter = 'alpha(opacity=40)';
	CurrentContex.insertAdjacentElement('BeforeEnd', ss);
	ss.onmouseover = ao.Star.onmouseover;
	ss.onmouseout = ao.Star.onmouseout;
	ao.Star.onmouseover =null;
	ao.Star.onmouseout = null;
	ao.StarSelection =ss;
*/

}

//function overConstellation(Constellation,isVolatile)
function overConstellation(Constellation,aso)
{
	aso = getStyle(document.getElementById(aso));
	CurrentContex = new ActiveContextObject(Constellation,aso)
}

function getObjIndex(c)
{
	for(i=0; i < OpenStarWay.length;i++)
	{
		if(OpenStarWay[i].Contex.Contex==c) return i; 
	}
	return -1;
}


function UpdatePath()
{
	if(NewContex && (CurrentContex.Contex==OpenStarWay[OpenStarWay.length-2].Contex.Contex))
	{
		coi = OpenStarWay.length-2;
	}
	else
	{
		coi =  OpenStarWay.length-1;
		while(OpenStarWay.length>0)
		{
			if(CurrentContex)
			{
				if(CurrentContex.Contex==OpenStarWay[OpenStarWay.length-1].Contex.Contex) break;
			}
			if(OpenStarWay.length>1)
			{			
				writeLog(OpenStarWay[OpenStarWay.length-1].Contex);
				getStyle(OpenStarWay[OpenStarWay.length-1].Contex.Contex).visibility='hidden';
				//getStyle(OpenStarWay[OpenStarWay.length-1].Contex.Contex).display='none';
			}
			ClearStarSelection(OpenStarWay[OpenStarWay.length-1]);
			OpenStarWay[OpenStarWay.length-1].Contex = null;
			OpenStarWay[OpenStarWay.length-1] = null;
			OpenStarWay.length--;
			coi =  OpenStarWay.length-1;
		}	
	}
	if((OpenStarWay.length==0) && (CurrentContex!=null))
	{
		OpenStarWay[0]= new ActiveObject(CurrentContex);
		coi = 0;
	}		
	if(!ActiveStar || (OpenStarWay[coi].Star != ActiveStar))
	{
		ClearStarSelection(OpenStarWay[coi]);		
	}	
	if(ActiveStar && ActiveStar != OpenStarWay[coi].Star)
	{
		OpenStarWay[coi].Star = ActiveStar;
		StarSelection(OpenStarWay[coi]);
	}
}

function outStar()
{
	ActiveStar = null;
	CurrentContex=null;
	NewContex=null;
	setClose();
}
function outConstellation()
{
	CurrentContex=null;
	setClose();
}
function setClose()
{
	clearTimeout(StarWayDrawTimer);
	StarWayDrawTimer = setTimeout('UpdatePath()', 400); 
}
function getStyle(o)
{
	DOM = document.getElementById ? 1:0;
	return DOM ? o.style : o;
}	
function fnCancelEvent()
{
  window.event.returnValue = false;
  window.event.cancelBubble = true;
  return false;
}

function writeLog(msg)
{
var x = document.getElementById("xxx");
//x.innerHTML += (msg + "&nbsp;");
}	
function writeLogx(msg)
{
var x = document.getElementById("xxx");
//x.innerHTML += (msg + "&nbsp;");
}	
