//PlanetaMoldova Engine. Scris de Ghenadii Sergheievici Trosnet.
//Unde-i pointerul cand ai nevoie de el :)

var NULL 	      	= null;
var CurrentMouseX 	= 0; 
var CurrentMouseY 	= 0; 
var MaxMenuX 	  	= 300; 
var MinMenuY 	  	= 160; 
var MaxMenuY		= 500;
var ns4				= document.all?false:true;
//var Netscape 	  	= (navigator.appName=="Netscape");
var Netscape		= (navigator.appName=="Netscape");

if (Netscape)
	if (document.getElementById)
		ns4 = false;
	else 
		ns4 = true;
		
var iMaxLength 	  	= 50;
var srcText 	 	= NULL; 
var destCtrl 		= NULL; 
var strCurrent 		= NULL; 
var iCurrentPos 	= 0; 
var T_Array; 
var nCount 			= 0, OrgCount = 0; 
var CurText 		= NULL;
var CurIndex 		= 0;
var strTAGopen 		= "=xn=", strTAGclose = "=/xn=";
var LeftPos 		= 0; 

//---------------------------------------------------------------------------------------
//News Ticker
//---------------------------------------------------------------------------------------
function InnerText(Control)
{
	if (Netscape && !ns4)
		return Control.innerHTML.replace(/<[^>]+>/g,"");
	return Control.innerText; 
}
//---------------------------------------------------------------------------------------

function OnTimeScroll()
{
	if (iCurrentPos>=0  && iCurrentPos < CurText.length)
	{
		var StrTmp = CurText.slice(iCurrentPos, iCurrentPos + iMaxLength); 
		if (ns4)
			destCtrl.innerText = strTmp; 
		else
			destCtrl.innerHTML = StrTmp; 
		iCurrentPos++; 
	} else
	{
		aIndex = Rand(0, nCount-1);
		CurIndex = T_Array[aIndex];
		Move(aIndex); 
		iCurrentPos = 0;
		CurText = srcText.substring(CurIndex, srcText.length);
		CurText = InsertSpace(CurText.substring(0, CurText.indexOf(strTAGclose)), iMaxLength-1);
	}
}
//---------------------------------------------------------------------------------------

function InsertSpace(Text, iCount)
{
	for (k = 0; k<iCount;k++)
		Text = " "+Text; 
	return Text; 		
}
//---------------------------------------------------------------------------------------

function CountNews(srcText)
{
	var iCount= 0; 
	var iLastIndex = 0; 
	for (;;)
	{
		var Index = srcText.indexOf(strTAGopen, iLastIndex);
		if (-1!=Index)
		     iLastIndex = Index+1; 
		else
			break; 
		++iCount; 
	}
	return iCount; 
}
//---------------------------------------------------------------------------------------

function BuildSortArray(srcText)
{
	nCount = CountNews(srcText); 
	OrgCount = nCount; 
	if (nCount>0)
	{
		T_Array = new Array(nCount); 
		var iLastIndex = 0; 
		var i = 0; 
		for (;;)
		{
			var Index = srcText.indexOf(strTAGopen, iLastIndex); 
			
			if (-1!=Index)
			{
				T_Array[i++] = Index+strTAGopen.length;
				iLastIndex = Index+1;
			}
			else 
				break; 
		}
	}
}
//---------------------------------------------------------------------------------------

function ScrollText(TextControl, Control)
{
	srcText = TextControl.innerText;  
	destCtrl = Control;
	BuildSortArray(srcText); 
	iCurrentPos = -1;
	window.setInterval("OnTimeScroll()", 100); 	
}
//---------------------------------------------------------------------------------------

function Rand(Left, Right)
{
 	return Math.ceil(Left+Math.random()*(Right-Left));
}
//---------------------------------------------------------------------------------------

function Move(from)
{
 var tmp = T_Array[from];
  for (i=from; i<nCount-1;i++)
  {
    T_Array[i] = T_Array[i+1];
  }
  T_Array[nCount-1] = tmp;
  if (--nCount == 0)
   nCount = OrgCount; 
}
//---------------------------------------------------------------------------------------

function GetElement(strElement)
{
	return document.getElementById(strElement);
//	else
	//	return document.tags[strElement];
}
function ScrollInit()
{
	TextControl = GetElement("textdiv");//document.getElementById("textdiv"); 
	Control = GetElement("marquee");//document.getElementById("marquee"); 
	srcText = InnerText(TextControl);//.innerText;  
	destCtrl = Control;
	BuildSortArray(srcText); 
	iCurrentPos = -1;
	
	window.setInterval("OnTimeScroll()", 150); 	
}

//---------------------------------------------------------------------------------------
//Menu 
//---------------------------------------------------------------------------------------

var dwHoverColors = new Array(6); 
dwHoverColors[0] 	= "#B1B4BB"; 
dwHoverColors[1] 	= "#B3B6BD";
dwHoverColors[2] 	= "#B6B9C0";
dwHoverColors[3] 	= "#B9BCC3"; 
dwHoverColors[4] 	= "#BBBEC5";
dwHoverColors[5] 	= "#BEC1C8";

var iTimeoutID 		= -1; 
var dwClrHover 		= "#A4AABA"; 
var dwClrNormal 	= "#B1B4BB"; 
var dwClrSHover 	= "#BEC1C8";
var dwClrSNormal	= "#555862";
var dwAnimationID 	= 0; 
var dwAnimationCycle= -1; 
var objActiveItem 	= 0; //referinta catre obiectul peste care se afla guzganul
var iMaxMenuWidth 	= 135;
var iGrowTimeoutID 	= 0; 
var iCurrentWidth 	= 0; 
var objActiveSubMenu = NULL; 
var LastOpenWindow	= NULL;

function HoverAnimation()
{
  	//assert(NULL != objActiveItem); 
	  SetBg(objActiveItem, dwHoverColors[dwAnimationID]);
	  objActiveItem.left++;
	  if (dwAnimationID >= 5 || dwAnimationID <= 0)
	       dwAnimationCycle = -dwAnimationCycle; 
	  dwAnimationID+=dwAnimationCycle; 
}
//----------------------------------------------------------------------

function SetBg(Control, Color)
{
  	Control.style.backgroundColor = Color; 
}
//---------------------------------------------------------------------------------------

function OnHover(Control)
{
   HideLastSubMenu();
	objActiveItem = Control; 
	dwAnimationCycle = -1; 
	if (iTimeoutID==-1)
		iTimeoutID = window.setInterval("HoverAnimation()", 100); 
}
//---------------------------------------------------------------------------------------

function StopHover(Control, event)
{
   SetBg(Control, dwClrNormal); 
   window.clearInterval(iTimeoutID); 
   dwAnimationID = 0; 
   iTimeoutID = -1; 
   if (!ns4 && !Netscape)
   {
	   if (window.event.x > MaxMenuX || window.event.y > MaxMenuY)
   			HideLastSubMenu();
	} else
	{
		if (event.pageX > MaxMenuX)
		{
			HideLastSubMenu();
		}
	}
	

}
//----------------------------------------------------------------------

function Grow()
{
	if (NULL != objActiveSubMenu)
	{
		iCurrentWidth+=50; 
		objActiveSubMenu.style.width=iCurrentWidth.toString(); 
		if (iCurrentWidth>iMaxMenuWidth)
		{
			window.clearInterval(iGrowTimeoutID); 
		}
	}
}
//----------------------------------------------------------------------

function Popup(MenuItem, strSubMenu, menuWidth, menuHeight)
{

	var	SubMenu = document.getElementById(strSubMenu); 
	OnHover(MenuItem); 
	if (objActiveSubMenu == SubMenu)
		return ; 
	HideLastSubMenu(); 
	SubMenu.style.top  		 = 0 + 'px'; 
	SubMenu.style.left 		 = iMaxMenuWidth-5 +'px' ; 
	SubMenu.style.visibility = "visible"; 
	SubMenu.style.width 	 = menuWidth +"px";
	SubMenu.style.height 	 = menuHeight+"px";
	MaxMenuX 				 = menuWidth + iMaxMenuWidth;
	MaxMenuY 				 = menuHeight ;
	objActiveSubMenu 		 = SubMenu; 

//decomenteaza pentru a anima desfacerea meniurilor. 
//	iCurrentWidth = 0; 
//window.clearInterval(iGrowTimeoutID); 
//	iGrowTimeoutID  = window.setInterval("Grow()", 50); 
}
//----------------------------------------------------------------------

function HideLastSubMenu()
{
	 if (objActiveSubMenu != NULL)
	  objActiveSubMenu.style.visibility="hidden";
	  objActiveSubMenu = NULL;

}
//----------------------------------------------------------------------

function SubMenuHover(Control)
{
	Control.style.backgroundColor = dwClrSHover; 
}
//----------------------------------------------------------------------

function SubMenuOut(Control)
{
	Control.style.backgroundColor = dwClrSNormal; 
}
//----------------------------------------------------------------------
function OpenMP3(strMp3)
{
	var bLowBandwidth = false; 
	HideLastSubMenu();
	if (!bLowBandwidth)
		LastOpenWindow = window.open("listen.html?"+strMp3, "mp3er", "height=150,width=250,status=yes,toolbar=no,menubar=no,location=no",true);
	else
	 	LastOpenWindow = window.open("lowbandwidth.html", "mp3er", "height=150,width=250,status=yes,toolbar=no,menubar=no,location=no",true);
}
function AddMenuItem(strCaption, strAudioUrl, bIsNew, strContentUrl, strFullUrl)
{
	if (strFullUrl==null)
	{
		if (strAudioUrl != null)
		{
			document.write("<tr onMouseOver='SubMenuHover(this);' onMouseOut='SubMenuOut(this);' onClick='OpenMP3(\""+strAudioUrl+"\")');>");
			document.write("<td class=submenutext><nobr>");
			if (bIsNew)
				document.write(strCaption+" - <font color=white>nou!</font>");
			else
				document.write(strCaption);
			document.write("</nobr></td>\n</tr>\n"); 
		} else
		{
			//Only content
			document.write("<tr onMouseOver='SubMenuHover(this);' onMouseOut='SubMenuOut(this);>'"); 
			document.write("<td class=submenutext><nobr><a href=plam.php?ContentFile="+strContentUrl+">"+strCaption+"</a></nobr></td></tr>\n"); 
		}

	}
	else
		document.write("<tr class=submenutext onMouseOver='SubMenuHover(this);' onMouseOut='SubMenuOut(this);'><td><a href='"+strFullUrl+"' target=newWindow>"+strCaption+"</a></td>\n</tr>\n");
}

//----------------------------------------------------------------------

function PrintM(strName, strHost, strText)
{
  document.write("<a href=ma");
  document.write("ilto" + ":");
  document.write(strName + "@" + strHost+">");
  document.write(strText + "</a>");
}

//------------------------

function OpenVideo(StrVideoName)
{
	window.open(StrVideoName, 'PlayAnim','height=432,width=520,status=yes,toolbar=no,menubar=no,location=no',true);
	return false;
}

