/*
http://javascriptcompressor.com/

v1.9:
menünün çok yavaş açılmasını engellemek için, AI functionı düzeltildi. Önceden her eleman için NM_01
div içeriği edit ediliyordu, bu işlem, şişkin menülerde çok uzun sürüyor.. Bunun yerinde NM_01'e divHTML değişkeni
atayıp sadece bir kez div içeriği güncelledim.

v1.8:
alt menüye top değer verildiğinde diğer menüler sola kayıyordu, o düzeltildi.

v1.7:
url'si olmayan elemanların üstüne gelince mouse cursor değişmesi engellendi.

v1.6:
menülerin scroll ederek açılması yapıldı. Bunun için 

scroll=3 şeklinde, her 50 milisaniyede kaç pixel ilerleyeceği tutuluyor.
scrollStyle="block" ise tüm alt menüler bir seferde, blok halinde açılıyor.
scrollStyle="order" ise önce birinci alt menü tam açılıyor, daha sonra onun altından ikinci menü, daha sonra üçüncü şeklinde..
scrollStyle="order" için orderd değişkeni kullanılabilir. Normalde bir menünün hareketi tam olarak bitince bir sonraki 
başlayabiliyor. Ama eğer orderd=x verilmişse, menünün hareketinin bitmesine x pixel kala diğeri harekete başlayabilir.

AlwaysVisible iptal edildi; sadece ana menüye, otomatk olarak verilen bir değişken haline getirildi. Artık NMData'da kullanılmasının 
bir anlamı kalmadı.

div html içerik oluşturma yapısı değiştirildi, tüm menüler eklendikten sonra, childlar altta kalacak şekilde tersten html oluşturuldu
(kullanıcıyı ne ilgilendirecekse bu?)

-----------------------------------------------
v1.5:
fadeIn,fadeOut ve opacity işlemlerinde InternetExplorer'daki hatalar düzeltildi.. FadeIn ve FadeOut için ayrı timer yazıldı..
bunu yapmak için tüm div mantığı ve tüm open-close functionları değiştirildi...

ikinci dereceden ve sonrasında alt menü eklemedeki bug düzeltildi.

NMDatanın son satırına NM_Init_Menu(); eklenmesi gerekiyor.

NMData'da AlwaysVisible değişkenleri sub menuler için konulmamalı, artık bu değişken dikkate alınıyor...
 
-----------------------------------------------
v.1.4:
NM.fadeIn,fadeOut özellikleri eklendi. fadeIn=300 yazarsan 300milisaniyede görünüyor, fadeOut=400 ise kapanırken 400 milisaniyede kapanıyor.
NM.opacity özelliği eklendi. 0-1 arasında değer.

------------------------------------------------
v.1.3.1:
submenü açılmalarında 4 yöndeki açılma hatası düzeltildi: 
horizontal-up-left, horizontal-down-left
vertical-right-up, vertical-left-up

mousemove kontrolünde hangi menünün üstte olduğunu algılamak için z-index kontrolü de eklendi. ControlMenu proceduru 
değiştirildi.

güvenlik açısından window.resize ve document.mousemove procedureleri window.load'un içine alındı:

	$(window).load(function()
	{
    Load_NM();

	  $(window).resize(function()
	  {
	  	reAlignMenus();
	  });
	  
	  $(document).mousemove(function(e)
		{
	  	NMmousemove(e);
	  });
    
	});
  
NM.title özelliği eklendi.
NM.fadeIn,NM.fadeOut,NM.opacity özellikleri eklendi

------------------------------------------------
v1.3:
submenülerin açılmasındaki hatalar gideriliyor... tüm işlemler
document.mousemove'a alındı, mouseoutlar iptal oldu.
ana sayfada
  $(document).mousemove(function(e)
	{
  	NMmousemove(e);
  });
şeklinde çağrı yapılmalı.

------------------------------------------------
v1.2 :
SubMenuler eklendi.
NM_Data'da function çağırmalar değişti:
* new NM_Menu("NM_01",null); şeklinde, ikinci parametre parent oldu. Ana menu için null

* AI fonksiyonu iptal oldu bunun yerine her child kendisini .addSelf(); diyerek parentına ekliyor.

* menulere setStye(st) function eklendi, buradaki style'lar daha önceden yaratılabiliyor:
style1=new style()
style1.url
openTo
.orientation
.direction
.left
.top
.width
.height
değişkenleri önceden atanabilir..

------------------------------------------------
*/

var NM_Index=0;
var MenuArr=new Array();

function NM_Init_Menu()
{
	var i1;
  for (i1=0;i1<MenuArr.length;i1++)
  {
  	if (MenuArr[i1].parent == null)
    {
    	MenuArr[i1].timerId=setTimeout("NM_Timer("+i1+")",50);
    }//if (MenuArr[i1].parent == null)
  }//for i1
}

function Control_Item(NM)
{
	var now=new Date();
  var t=now.getTime();
  var i1;
  var op;
  var k1;
  var scrollIt=true;
  if ((NM.currentX != NM.xTo) || (NM.currentY != NM.yTo))
  {
    if (NM.parent.scroll != 0)
    {
     	if (NM.scrollCondition == null) 
       	scrollIt=true;
      else
      {
      	if ((Math.abs(NM.scrollCondition.currentX-NM.scrollCondition.xTo) <= NM.parent.orderd) && (Math.abs(NM.scrollCondition.currentY-NM.scrollCondition.yTo) <= NM.parent.orderd))
        	scrollIt=true;
        else
        	scrollIt=false;  
      }//if (NM.scrollCondition == null)
      if ((scrollIt == true) && (NM.movement == "closing"))
      {  	
     	//daha alt leveldan hareket eden bir alt menü varsa, kapanışta önce onun hareketinin bitmesi beklenir.
      	for (i1=0;i1<NM.parent.arr.length;i1++)
        {
        	if (NM.parent.arr[i1].anyChildMoving() == true)
          {
          	scrollIt=false;
            break;
          }//if (NM.parent.arr[i1].anyChildMoving() == true)
        }//for i1
      }//if (scrollIt == true)
    }//if (NM.parent.scroll != 0)
    if (scrollIt == true)
    {
      if (NM.currentX != NM.xTo)
      {
        
    		if (NM.xFrom < NM.xTo)
        {
        	
        	NM.currentX+=NM.parent.scroll;
          if (NM.currentX > NM.xTo)
          	NM.currentX=NM.xTo;
        } else//if (NM.xFrom < NM.xTo)
        {
        	NM.currentX-=NM.parent.scroll;
          if (NM.currentX < NM.xTo)
          	NM.currentX=NM.xTo;
        } //if (NM.xFrom < NM.xTo),else
  //      NM.getClip();
        $("#"+NM.divName).css("left",Math.round(NM.currentX)+"px");
        $("#"+NM.divName+"_on").css("left",Math.round(NM.currentX)+"px");
      }//if (NM.currentX != NM.xTo)
      if (NM.currentY != NM.yTo)
      {
    		if (NM.yFrom < NM.yTo)
        {
        	NM.currentY+=NM.parent.scroll;
          if (NM.currentY > NM.yTo)
          	NM.currentY=NM.yTo;
        } else//if (NM.xFrom < NM.xTo)
        {
        	NM.currentY-=NM.parent.scroll;
          if (NM.currentY < NM.yTo)
          	NM.currentY=NM.yTo;
        } //if (NM.xFrom < NM.xTo),else
  //      NM.getClip();
        $("#"+NM.divName).css("top",Math.round(NM.currentY)-$("#NM_01").offset().top+"px");
        $("#"+NM.divName+"_on").css("top",Math.round(NM.currentY)-$("#NM_01").offset().top+"px");
      }//if (NM.currentX != NM.xTo)
      if ((NM.currentX == NM.xTo) && (NM.currentY == NM.yTo))
      {
  //      NM.getClip();
      	if (NM.parent.opened == false) $("#"+NM.divName).css("display","none");
      }//if ((NM.currentX == NM.xTo) && (NM.currentY == NM.yTo))
    }//if (scrollIt == true)
    NM.getClip();
  }//if ((NM.currentX != NM.xTo) || (NM.currentY != NM.yTo))
	if (NM.currentOpacity_off != NM.opacityTo_off)
  {
  	if (NM.opacityToGoTime2_off <= t)
    	op=NM.opacityTo_off;
    else
    {
    	k1=(t-NM.opacityToGoTime1_off)/(NM.opacityToGoTime2_off-NM.opacityToGoTime1_off);
      op=NM.opacityFrom_off+(NM.opacityTo_off-NM.opacityFrom_off)*k1;
    }
  	$("#"+NM.divName).css("opacity",op);
    NM.currentOpacity_off=op;
	  if (op == 0) 
    	$("#"+NM.divName).css("display","none"); 
   	else 
    	$("#"+NM.divName).css("display","block");  
 }//if (MenuArr[ind].arr[i1].currentOpacity != MenuArr[ind].arr[i1].opacityToGo)
 
	if (NM.currentOpacity_on != NM.opacityTo_on)
  {
  	if (NM.opacityToGoTime2_on <= t)
    	op=NM.opacityTo_on;
    else
    {
    	k1=(t-NM.opacityToGoTime1_on)/(NM.opacityToGoTime2_on-NM.opacityToGoTime1_on);
      op=NM.opacityFrom_on+(NM.opacityTo_on-NM.opacityFrom_on)*k1;
    }
  	$("#"+NM.divName+"_on").css("opacity",op);
    NM.currentOpacity_on=op;
	  if (op == 0) 
    	$("#"+NM.divName+"_on").css("display","none"); 
   	else 
    	$("#"+NM.divName+"_on").css("display","block");  
 }//if (MenuArr[ind].arr[i1].currentOpacity != MenuArr[ind].arr[i1].opacityToGo)
	for (i1=0;i1<NM.arr.length;i1++)
  {  	
  	Control_Item(NM.arr[i1]);    
  }//for i1 
}
//function Control_Item(NM)

function Control_States(NM)
{
	var i1;
	Control_Item(NM);
}

function NM_Timer(ind)
{
	var i1;
	for (i1=0;i1<MenuArr[ind].arr.length;i1++)
	  Control_Item(MenuArr[ind].arr[i1]);
//  $("#debug").html(_s);
  MenuArr[ind].timerId=setTimeout("NM_Timer("+ind+")",50);
}

function NMmousemove(e)
{
	var i1;
// 	$("#debug").html(e.pageX+"."+e.pageY);
 	var _mouseX=e.pageX/*-$("#"+thisNM.divName).offset().left*/;
  var _mouseY=e.pageY/*-$("#"+thisNM.divName).offset().top*/;
  controlMenu(_mouseX,_mouseY);	      
}

function find_NM(divName)
{
	var i1;
  var NM;
	for (i1=0;i1<MenuArr.length;i1++)
  {
  	if ((MenuArr[i1].divName == divName) || (MenuArr[i1].divName+"_on" == divName))
    {
    	NM=MenuArr[i1];
      break;
    }
  }//for i1
  return(NM);
}


function reAlignMenus()
{
	var i1;
	for (i1=0;i1<MenuArr.length;i1++)
  {
  	if (MenuArr[i1].parent == null)
	  	MenuArr[i1].prepare();    
  }//for i1
}

function style()
{
	this.url=null;
  this.openTo=null;
  this.orientation=null;
  this.direction=null;
  this.left=null;
  this.top=null;
  this.width=null;
  this.height=null;
  this.title=null;
  this.fadeIn=0;
  this.fadeOut=0;
  this.opacity=1;
  this.scroll=0;
  this.scrollStyle=null;
  this.orderd=0;
}

function controlMenu(_mouseX,_mouseY)
{
	var i1;
  var menuToOpen=null;
  var maxZIndex=0;
  var mainParent=mainParentt=null;
  for (i1=0;i1<MenuArr.length;i1++)
  {
  	if (MenuArr[i1].parent != null)
    {
    	if (MenuArr[i1].parent.opened == true)
      {
      	if ((_mouseX >= MenuArr[i1].currentX) && (_mouseX <= MenuArr[i1].currentX+MenuArr[i1].width)
           && (_mouseY >= MenuArr[i1].currentY) && (_mouseY <= MenuArr[i1].currentY+MenuArr[i1].height)
           && (_mouseX >= MenuArr[i1].offsetLeft) && (_mouseX <= MenuArr[i1].offsetLeft+MenuArr[i1].width)
           && (_mouseY >= MenuArr[i1].offsetTop) && (_mouseY <= MenuArr[i1].offsetTop+MenuArr[i1].height)
           )
        {
        	if (menuToOpen == null)
          {
          	menuToOpen=MenuArr[i1];
            maxZIndex=MenuArr[i1].zindex;
            mainParent=mainParentt;
          } else//if (menuToOpen == null)
          {
          	if (MenuArr[i1].zindex >= maxZIndex)
            {
            	menuToOpen=MenuArr[i1];
              maxZIndex=MenuArr[i1].zindex;
              mainParent=mainParentt;
            }//if (MenuArr[i1].zindex >= maxZIndex)
          }//if (menuToOpen == null),else
        }//((_mouseX >= NM.arr[i1].offsetLeft) && (_mouseX <= NM.arr[i1].offsetLeft+NM.arr[i1].width)..
      }//if (MenuArr[i1].parent.opened == true)
    }//if (MenuArr[i1].parent != null)
    else
    	mainParentt=MenuArr[i1];
  }//for i1
  if (menuToOpen == null)
  {  
  	for (i1=0;i1<MenuArr.length;i1++)
    {
    	if ((MenuArr[i1].opened == true) && (MenuArr[i1].parent != null)) MenuArr[i1].close(false,0);
    }
  } else//if (menuToOpen == null)
 	{
  	for (i1=0;i1<MenuArr.length;i1++)
    {
    	if ((MenuArr[i1].parent == null) && (MenuArr[i1] != mainParent)) MenuArr[i1].close(false,0);
    }
//  	$("#debug").html(menuToOpen.divName+"."+menuToOpen.arr.length);
  	menuToOpen.open();
    for (i1=0;i1<menuToOpen.arr.length;i1++)
    	menuToOpen.arr[i1].close(false,0);
  } //if (menuToOpen == null),els
}

function NM_Menu(divName,parent)
{
  this.parent=parent;
  this.arr=new(Array);
  this.fadeIn=0;
  this.fadeOut=0;
  this.opacity=1;
	this.url="";
  this.openTo="right";
  this.orientation="horizontal";
  this.direction="right";
  this.scroll=0;
  this.scrollStyle="block";
  this.orderd=0;
  this.left=0;
  this.top=0;
  this.width=0;
  this.height=0;
  this.allwaysVisible=false;
  this.onHtml="";
  this.offHtml="";
  this.onImg="";
  this.offImg="";
  this.title="";
	if (parent != null) 
  {
  	this.divName="NM_div"+NM_Index;
    NM_Index+=1;
    this.zindex=parent.zindex+1;
  }//if (parent != null)
  else
  {
  	this.divName=divName;
	  this.zindex=1;
  }//if (parent != null),else

  this.offsetLeft=0;
  this.offsetTop;
  this.xTo=0;
  this.yTo=0;
  this.movement="";
  this.scrollCondition=null;
  this.currentX=0;
  this.currentY=0;
  this.closedX=0;
  this.closedY=0;
  this.clipLeft=0;
  this.clipTop=0;
  this.clipRight=0;
  this.clipBottom=0;
  this.timerId=null;
  this.opened=false;
  this.divHTML="";
  this.divAdded=false;
  MenuArr[MenuArr.length]=this;
	
  this.addSelf = function()
  {
  	if (this.onImg == "") this.onImg=this.offImg;
  	if (this.onHtml == "") this.onHtml=this.offHtml;
    if (this.parent.parent == null)
    	this.alwaysVisible=true;
    else
    	this.alwaysVisible=false;
    this.parent.arr[this.parent.arr.length]=this;
  	//this.parent.AI(this);
  };
  
  this.setStyle = function(st)
  {
		if (st.url != null) this.url=st.url;
  	if (st.openTo != null) this.openTo=st.openTo;
	  if (st.orientation != null) this.orientation=st.orientation;
  	if (st.direction != null) this.direction=st.direction;
	  if (st.left != null) this.left=st.left;
	  if (st.top != null) this.top=st.top;
	  if (st.width != null) this.width=st.width;
	  if (st.height != null) this.height=st.height;
	  if (st.fadeIn != 0) this.fadeIn=st.fadeIn;
  	if (st.fadeOut != 0) this.fadeOut=st.fadeOut;
	  if (st.opacity != 1) this.opacity=st.opacity;
    if (st.title != null) this.title=st.title;
    if (st.scroll != 0) this.scroll=st.scroll;
    if (st.scrollStyle != null) this.scrollStyle=st.scrollStyle;
    if (st.orderd != 0) this.orderd=st.orderd;
  };    
  
  this.AI = function(NM)
  {
  	var i1;
    var html0,html;
    if (NM != this)
    {
//    	html0=$("#"+NM.divName).html();
			html0=NM.divHTML;
      html="";
      html+="<div id='"+this.divName+"' style='display:none;position:absolute;left:0px;top:0px;width:"+this.width+"px;height:"+this.height+"px;z-index:"+this.zindex+"'>";		
      if (this.offHtml != "") html+=this.offHtml;
  		if (this.offImg != "") html+="<img src='"+this.offImg+"'>";
      html+="</div>";
      html+="<div ";
      html+="title='" + this.title +"' ";
      html+="id='"+this.divName+"_on' style='display:none;position:absolute;left:0px;top:0px;width:"+this.width+"px;height:"+this.height+"px;z-index:"+this.zindex+"'>";
      if (this.onHtml != "") html+=this.onHtml;
  		if (this.onImg != "") html+="<img src='"+this.onImg+"'>";
      html+="</div>";
//      $("#"+NM.divName).html(html0+html);
			NM.divHTML=html0+html;
    }//if (NM != this)   	
    for (i1=0;i1<this.arr.length;i1++)
    {
      this.arr[i1].AI(NM);
    }//for i1
    this.divAdded=true;
    $("#debug").text($("#"+NM.divName).html());    
  };//this.AI.
  
  this.arrangeChilds = function()
  {
    var OpenStr;
    
    function onlyY(t)
    {
    	var i1;
    	for (i1=0;i1<t.arr.length;i1++)
	    	t.arr[i1].currentY=t.offsetTop;
    };//function onlyY.
    
    function yOrderBlock(t)
    {
			var i1;
      var dy;
      dy=t.offsetTop-t.arr[t.arr.length-1].currentY;
      for (i1=0;i1<t.arr.length;i1++)
      	t.arr[i1].currentY+=dy;    	
    };//function yOrder.
    
    function yOrderOrder(t)
    {
			var i1;
      var dy;
      if (t.offsetTop-t.arr[0].currentY > 0)
      	dy=t.orderd;
      else
      	dy=-t.orderd;      
      t.arr[0].currentY=t.offsetTop;
      for (i1=1;i1<t.arr.length;i1++)
      {
      	t.arr[i1].currentY=t.arr[i1-1].offsetTop+dy;
      }//for i1    	
    };//function yOrderOrder.
    
    function xOrderBlock(t)
    {
			var i1;
      var dx;
      dx=t.offsetLeft+t.width-(t.arr[t.arr.length-1].currentX+t.arr[t.arr.length-1].width);
      for (i1=0;i1<t.arr.length;i1++)
      	t.arr[i1].currentX+=dx;    	
    };//function xOrderBlock.
    
    function xOrderRight(t)
    {
			var i1;
      var dx;
      if (t.offsetLeft+t.width-(t.arr[0].currentX+t.arr[0].width) > 0)
      	dx=t.orderd;
      else
      	dx=-t.orderd;      
      t.arr[0].currentX=t.offsetLeft+t.width-t.arr[0].width;
      for (i1=1;i1<t.arr.length;i1++)
      {
      	t.arr[i1].currentX=t.arr[i1-1].offsetLeft+dx+t.arr[i1-1].width-t.arr[i1].width-1;
      }//for i1    	
    };//function xOrderOrder.
    
    function xOrderLeft(t)
    {
			var i1;
      var dx;
      if (t.offsetLeft+t.width-(t.arr[0].currentX+t.arr[0].width) > 0)
      	dx=t.orderd;
      else
      	dx=-t.orderd;      
    	t.arr[0].currentX=t.offsetLeft;
      for (i1=1;i1<t.arr.length;i1++)
      {
      	t.arr[i1].currentX=t.arr[i1-1].offsetLeft+dx;
      }//for i1
    };//function xOrderLeft.
    
    function xAlignRight(t)
    {
    	var i1;
      for (i1=0;i1<t.arr.length;i1++)
      {
      	t.arr[i1].currentX=t.offsetLeft+t.width-t.arr[i1].width-1;
      }
    };//function xAlign.
    
    function xAlignLeft(t)
    {
    	var i1;
      for (i1=0;i1<t.arr.length;i1++)
      {
      	t.arr[i1].currentX=t.offsetLeft;
      }
   	};//function xAlignLeft.
    
	 	if (this.scroll != 0)
    {
    	for (i1=0;i1<this.arr.length;i1++)
      {
	    	if (this.scroll != 0)
  	    {
        	if (this.scrollStyle == "block")
          {
	    	  	this.arr[i1].clipLeft=this.clipLeft;
  	    	  this.arr[i1].clipTop=this.clipTop;
	  	      this.arr[i1].clipRight=this.clipRight;
  	  	    this.arr[i1].clipBottom=this.clipBottom;
          }
        	if (this.scrollStyle == "order")
          {
	    	  	this.arr[i1].clipLeft=this.arr[i1].offsetLeft;
  	    	  this.arr[i1].clipTop=this.arr[i1].offsetTop;
	  	      this.arr[i1].clipRight=this.arr[i1].offsetLeft+this.arr[i1].width;
  	  	    this.arr[i1].clipBottom=this.arr[i1].offsetTop+this.arr[i1].height;
          }
    	  }//if (this.scroll != 0)        
      }//for i1
OpenStr=".T."+this.openTo.charAt(0)+".D."+this.direction.charAt(0)+".O."+this.orientation.charAt(0)+".S."+this.scrollStyle.charAt(0)+".";
			switch (String(OpenStr))
      {
       	case ".T.u.D.r.O.h.S.b.": onlyY(this);break;
        case ".T.u.D.r.O.h.S.o.": onlyY(this);break;
       	case ".T.u.D.l.O.h.S.b.": onlyY(this);break;
        case ".T.u.D.l.O.h.S.o.": onlyY(this);break;
        case ".T.u.D.u.O.v.S.b.": yOrderBlock(this);break;
        case ".T.u.D.u.O.v.S.o.": yOrderOrder(this);break;
        case ".T.u.D.d.O.v.S.b.": yOrderBlock(this);break;
        case ".T.u.D.d.O.v.S.o.": yOrderOrder(this);break;
        
       	case ".T.d.D.r.O.h.S.b.": onlyY(this);break;
        case ".T.d.D.r.O.h.S.o.": onlyY(this);break;
       	case ".T.d.D.l.O.h.S.b.": onlyY(this);break;
        case ".T.d.D.l.O.h.S.o.": onlyY(this);break;
        case ".T.d.D.u.O.v.S.b.": yOrderBlock(this);break;
        case ".T.d.D.u.O.v.S.o.": yOrderOrder(this);break;
        case ".T.d.D.d.O.v.S.b.": yOrderBlock(this);break;
        case ".T.d.D.d.O.v.S.o.": yOrderOrder(this);break;

       	case ".T.r.D.r.O.h.S.b.": xOrderBlock(this);break;
        case ".T.r.D.r.O.h.S.o.": xOrderRight(this);break;
       	case ".T.r.D.l.O.h.S.b.": xOrderBlock(this);break;
        case ".T.r.D.l.O.h.S.o.": xOrderLeft(this);break;
        case ".T.r.D.u.O.v.S.b.": xAlignRight(this);break;
        case ".T.r.D.u.O.v.S.o.": xAlignRight(this);break;
        case ".T.r.D.d.O.v.S.b.": xAlignRight(this);break;
        case ".T.r.D.d.O.v.S.o.": xAlignRight(this);break;
        
       	case ".T.l.D.r.O.h.S.b.": xOrderBlock(this);break;
        case ".T.l.D.r.O.h.S.o.": xOrderRight(this);break;
       	case ".T.l.D.l.O.h.S.b.": xOrderBlock(this);break;
        case ".T.l.D.l.O.h.S.o.": xOrderLeft(this);break;
        case ".T.l.D.u.O.v.S.b.": xAlignLeft(this);break;
        case ".T.l.D.u.O.v.S.o.": xAlignLeft(this);break;
        case ".T.l.D.d.O.v.S.b.": xAlignLeft(this);break;
        case ".T.l.D.d.O.v.S.o.": xAlignLeft(this);break;
        
      }//switch (OpenStr)
    }//if (this.scroll != 0)
    for (i1=0;i1<this.arr.length;i1++)
    {
	   	this.arr[i1].closedX=this.arr[i1].currentX;
  	  this.arr[i1].closedY=this.arr[i1].currentY;
      this.arr[i1].xTo=this.arr[i1].currentX;
      this.arr[i1].yTo=this.arr[i1].currentY;
    	$("#"+this.arr[i1].divName).css("left",this.arr[i1].currentX+"px");
     	$("#"+this.arr[i1].divName).css("top",(this.arr[i1].currentY-$("#NM_01").offset().top)+"px");
     	$("#"+this.arr[i1].divName+"_on").css("left",this.arr[i1].currentX+"px");
 	   	$("#"+this.arr[i1].divName+"_on").css("top",(this.arr[i1].currentY-$("#NM_01").offset().top)+"px");
    }//for i1
  };//this.arrangeChilds
  
	this.prepare = function()
  {
  	var i1,x,y;
    var offsetLeft,offsetTop;
    var NM;
    var thisNM;
//   	this.offsetLeft=x;
//    this.offsetTop=y;
    if (this.parent == null)	
    {
    	if (this.divAdded == false) 
      {
      	this.AI(this);
	      $("#"+this.divName).html(this.divHTML);
        
      }
	  	x=$("#"+this.divName).offset().left;
			y=$("#"+this.divName).offset().top;
      this.opened=true;
    }//if (this.parent == null)
        
    if (this.parent != null)
    {
	  	x=this.offsetLeft;
			y=this.offsetTop;
    	if (this.openTo == "right") x+=this.width;
      if (this.openTo == "down") y+=this.height;
    }//if (this.parent != null)
   	for (i1=0;i1<this.arr.length;i1++)
    {
    	if ((this.openTo == "left") && (this.direction != "left")) x=this.offsetLeft-this.arr[i1].width+this.arr[i1].left;
      if ((i1 == 0) && (this.openTo == "up") && (this.direction != "up")) y-=this.arr[i1].height+this.arr[i1].top;
    	if ((this.orientation == "horizontal") && ((i1 != 0) || ((this.openTo != "up") && (this.openTo != "down"))) && (this.direction == "left")) x-=this.arr[i1].width+this.arr[i1].left;
      if ((this.orientation == "vertical") && ((i1 != 0) || ((this.openTo != "right") && (this.openTo != "left"))) && (this.direction == "up")) y-=this.arr[i1].height+this.arr[i1].top;
      offsetLeft=x+this.arr[i1].left;
      offsetTop=y+this.arr[i1].top;
      if (this.arr[i1].alwaysVisible == true) 
      {
      	if (this.arr[i1].opacity != 0)
        	$("#"+this.arr[i1].divName).css("opacity",this.arr[i1].opacity);
      		$("#"+this.arr[i1].divName).css("display","block");
        this.arr[i1].currentOpacity_off=this.arr[i1].opacity;
      }
      else
      	this.arr[i1].currentOpacity_off=0;
			$("#"+this.arr[i1].divName+"_on").css("display","none");
      this.arr[i1].currentOpacity_on=0;
      
		  this.arr[i1].opacityFrom_off=this.arr[i1].currentOpacity_off;
		  this.arr[i1].opacityTo_off=this.arr[i1].currentOpacity_off;
		  this.arr[i1].opacityFrom_on=this.arr[i1].currentOpacity_on;
		  this.arr[i1].opacityTo_on=this.arr[i1].currentOpacity_on;
      
      
      this.arr[i1].offsetLeft=offsetLeft;
 	    this.arr[i1].offsetTop=offsetTop;
      
			this.arr[i1].currentX=offsetLeft;
	    this.arr[i1].currentY=offsetTop;
      //bu pozisyonlar scroll = 0 ise doğru, yerleştirme işlemlerini zaten arrangeChilds içinde yapacağım...
      if (this.scroll != 0)
      {
      	if (i1 == 0)
        {
        	this.clipLeft=this.arr[0].offsetLeft;
          this.clipTop=this.arr[0].offsetTop;
          this.clipRight=this.arr[0].offsetLeft+this.arr[i1].width;
          this.clipBottom=this.arr[0].offsetTop+this.arr[i1].height;          
        }//if (i1 == 0) 
        else
        {
        	if (this.arr[i1].offsetLeft < this.clipLeft) this.clipLeft=this.arr[i1].offsetLeft;
          if (this.arr[i1].offsetTop < this.clipTop) this.clipTop=this.arr[i1].offsetTop;
          if (this.arr[i1].offsetLeft+this.arr[i1].width > this.clipRight) this.clipRight=this.arr[i1].offsetLeft+this.arr[i1].width;
          if (this.arr[i1].offsetTop+this.arr[i1].height > this.clipBottom) this.clipBottom=this.arr[i1].offsetTop+this.arr[i1].height;
        }//if (i1 == 0),else
      }//if (this.scroll != 0)
      
      if ((this.orientation == "horizontal") && (this.direction == "right")) x+=this.arr[i1].width;
      if ((this.direction == "left") || (this.direction == "right")) x+=this.arr[i1].left;
      if ((this.orientation == "vertical") && (this.direction == "down")) y+=this.arr[i1].height;      
      if ((this.direction == "up") || (this.direction == "down")) y+=this.arr[i1].top;
                     	
      this.arr[i1].prepare();
    }//for i1
    this.arrangeChilds();
   	for (i1=0;i1<this.arr.length;i1++)
    {
    	this.arr[i1].getClip();
    }//for i1
	  $("#"+this.divName+"_on").click(function()
  	{
    	var NM=find_NM(this.id);
      NM.click();
	  });
    if (this.parent == null)
    {
	    thisNM=this;
      maxy=1000;
    }//if (this.parent == null)
  };//this.prepare = function().
  
  this.getClip = function()
  {
  	if (this.parent.scroll != 0)
    {
			var s="rect("+(this.clipTop-this.currentY)+"px,"+(this.clipRight-this.currentX)+"px,"+(this.clipBottom-this.currentY)+"px,"+(this.clipLeft-this.currentX)+"px)";
			$("#"+this.divName).css("clip",s);
      $("#"+this.divName+"_on").css("clip",s);
    }//if (this.parent.scroll != 0)
  };//this.getClip.
  
  this.Make_On_FadeOut = function(fadeOutValue)
  {
   	var now=new Date();
   	this.opacityFrom_on=this.currentOpacity_on;
    this.opacityTo_on=0;
    this.opacityToGoTime1_on=now.getTime();
    this.opacityToGoTime2_on=this.opacityToGoTime1_on+fadeOutValue;
  };//this.Make_On_FadeOut.
  
  this.Make_Off_FadeOut = function(fadeOutValue)
  {
   	var now=new Date();
   	this.opacityFrom_off=this.currentOpacity_off;
    this.opacityTo_off=0;
    this.opacityToGoTime1_off=now.getTime();
    this.opacityToGoTime2_off=this.opacityToGoTime1_off+fadeOutValue;
  };//this.Make_Off_FadeOut.
  
  this.Make_On_Close = function()
  {
		$("#"+this.divName+"_on").css("display","none");
    this.currentOpacity_on=0;
    this.opacityTo_on=0;
  };//this.Make_On_Close.
  
  this.Make_Off_Show = function()
  {
		$("#"+this.divName).css("opacity",this.opacity);
  	$("#"+this.divName).css("display","block");         
    this.currentOpacity_off=this.opacity;
    this.opacityTo_off=this.opacity;
  };//this.Make_Off_Show.
  
  this.Make_Off_Close = function()
  {
		$("#"+this.divName).css("display","none");
    this.currentOpacity_off=0;
    this.opacityTo_off=0;
  };//function Make_Off_Close.
  
  this.Make_Scroll_Close = function()
  {
  	var i1;
//  	if (this.fadeIn == 0) this.Show_Selected();
		this.xFrom=this.currentX;
    this.yFrom=this.currentY;
    this.xTo=this.closedX;
    this.yTo=this.closedY;
    this.movement="closing";          	
//	  	$("#debug").html("scroll "+this.arr[i1].currentY+" > "+this.arr[i1].yTo);
//      if (this.fadeIn == 0) this.arr[i1].Show_Normal();
  };//this.Make_Scroll_Close 
  
  this.close = function(CloseSelf,fadeOutValue)
  {  
  	var i1;
  	if ((this.opened == true) || (this.parent == null) || (CloseSelf == true))
    {
			this.sendToBack();
      if (CloseSelf == false) fadeOutValue=this.fadeOut;
      if (fadeOutValue != 0)
      {
      	this.Make_On_FadeOut(fadeOutValue);
      }//if (this.fadeOut != 0)
      else
      {
      	this.Make_On_Close();
        if ((CloseSelf == true) && (this.parent.scroll!= 0))
        	this.Make_Off_Show();
      }//if (this.fadeOut != 0),else
      if (CloseSelf == false)
      {
      	this.Make_Off_Show();
      }//if (CloseSelf == false)
      else
      {
        if (fadeOutValue != 0)
        {
        	this.Make_Off_FadeOut(fadeOutValue);
          if (this.parent.scroll != 0) this.Make_Scroll_Close();
        }//if (this.fadeOut != 0)
        else
        {
        	if (this.parent.scroll == 0)
	        	this.Make_Off_Close();
          else
            this.Make_Scroll_Close();        
        }//if (this.fadeOut != 0),else
      }//if (CloseSelf == false),else
   		$("#"+this.divName).css("cursor","default");
      if (this.opened == true)
      {
		    for (i1=0;i1<this.arr.length;i1++)
  	    {      	
		    	this.arr[i1].close(true,fadeOutValue);
          if (this.scroll != 0)
          {
          	if (this.scrollStyle == "block") this.arr[i1].scrollCondition=null;
            if (this.scrollStyle == "order") 
            {
            	if (i1 < this.arr.length-1)
	            	this.arr[i1].scrollCondition=this.arr[i1+1];
              else
              	this.arr[i1].scrollCondition=null;
            }//if (this.scrollStyle == "order")
          }//if (this.scroll != 0)          
	      }//for i1
      }//if (this.opened == true)
      if (this.parent != null) this.opened=false;
    }//if (this.opened == true)
  };//this.close.
  
	this.Make_FadeIn= function()
  {
//  	$("#debug").html("fadein "+this.divName);
  	var i1;
  	var now=new Date();
  	this.opacityFrom_on=this.currentOpacity_on;
    this.opacityTo_on=this.opacity;
    this.opacityToGoTime1_on=now.getTime();
    this.opacityToGoTime2_on=this.opacityToGoTime1_on+this.fadeIn;
    for (i1=0;i1<this.arr.length;i1++)
    {
    	this.arr[i1].opacityFrom_off=this.arr[i1].currentOpacity_off;
      this.arr[i1].opacityTo_off=this.arr[i1].opacity;
      this.arr[i1].opacityToGoTime1_off=this.opacityToGoTime1_on;
      this.arr[i1].opacityToGoTime2_off=this.opacityToGoTime2_on;
//          $("#debug").html(this.arr[i1].divName+" "+this.arr[i1].opacityTo);
    }//for i1
  };//this.Make_FadeIn.
  
  this.Show_Selected = function()
  {
  	$("#"+this.divName+"_on").css("opacity",this.opacity);
  	$("#"+this.divName+"_on").css("display","block");
		this.currentOpacity_on=this.opacity;
    this.opacityTo_on=this.opacity;        
  	$("#"+this.divName).css("display","none");
		this.currentOpacity_off=0;
    this.opacityTo_off=0;        
  };//this.Show_Selected.
  
  this.Show_Normal = function()
  {
    	$("#"+this.divName).css("opacity",this.opacity);
	   	$("#"+this.divName).css("display","block");
			this.currentOpacity_off=this.opacity;
      this.opacityTo_off=this.opacity;        
	   	$("#"+this.divName+"_on").css("display","none");
			this.currentOpacity_on=0;
      this.opacityTo_on=0;        
  };//this.Show_Normal.
  
  this.Make_Open = function()
  {
//  	$("#debug").html("open "+this.divName);
  	var i1;
    this.Show_Selected();
    for (i1=0;i1<this.arr.length;i1++)
    {
      this.arr[i1].Show_Normal();        
    }//for i1
  };
  //this.Make_Open.
  
  this.Make_Scroll_Open = function()
  {
  	var i1;
  	if (this.fadeIn == 0) this.Show_Selected();
    for (i1=0;i1<this.arr.length;i1++)
    {
			this.arr[i1].xFrom=this.arr[i1].currentX;
      this.arr[i1].yFrom=this.arr[i1].currentY;
      this.arr[i1].xTo=this.arr[i1].offsetLeft;
      this.arr[i1].yTo=this.arr[i1].offsetTop;
      this.arr[i1].movement="opening";
      if (this.scrollStyle == "block") this.arr[i1].scrollCondition=null;
      if (this.scrollStyle == "order")
      {
      	if (i1 == 0)
        	this.arr[i1].scrollCondition=null;
        else
        	this.arr[i1].scrollCondition=this.arr[i1-1];
      }//if (this.scrollStyle == "order")          	
      if (this.fadeIn == 0) this.arr[i1].Show_Normal();
    }//for i1
  };
  //this.Make_Scroll.
    
  this.open = function()
  {
  	var i1;       
    if ((this.opened == false) || (this.parent == null))
    {    	
	  	for (i1=0;i1<MenuArr.length;i1++)
	    {
	    	if ((MenuArr[i1].opened == true) && (MenuArr[i1].parent == this.parent) && (MenuArr[i1] != this))
	      	MenuArr[i1].close(false);      	
	    }//for i1
      this.bringToFront();
//      $("#debug").html("open: "+this.divName+" "+this.opacity);
      if (this.fadeIn != 0)
      {
      	this.Make_FadeIn();
        if (this.scroll != 0) this.Make_Scroll_Open(); 
      }//if (this.fadeIn != 0)
      else
      {
      	if (this.scroll != 0) 
        	this.Make_Scroll_Open();
        else
	      	this.Make_Open();
      }//if (this.fadeIn != 0),else
      if (this.url != "")
		    $("#"+this.divName+"_on").css("cursor","pointer");
	    this.opened=true;
    }//if (this.opened == false)
  };
  //this.open.
  
  this.anyChildMoving = function()
  {
  	var i1;
    var b=false;
    for (i1=0;i1<this.arr.length;i1++)
    {
    	if ((this.arr[i1].xTo != this.arr[i1].currentX) || (this.arr[i1].yTo != this.arr[i1].currentY))
     	{
      	b=true;
        break;
      }
    	if (this.arr[i1].anyChildMoving() == true)
      {
      	b=true;
        break;
      }//if (this.arr[i1].anyChildMoving() == true)
    }//for i1
    return(b);
  };//this.anyChildMoving.
  
  this.bringToFront = function()
  {
			$("#"+this.divName).css("z-index",this.zindex+1);
			$("#"+this.divName+"_on").css("z-index",this.zindex+1);
      if (this.parent != null) 
      	this.parent.bringToFront();
  };
  //this.bringToFront.
  
  this.sendToBack = function()
  {
			$("#"+this.divName).css("z-index",this.zindex);
			$("#"+this.divName+"_on").css("z-index",this.zindex);
  };
   
  this.click=function()
  {
  	if (this.url != "") window.location.href=this.url;
  };  
}//function NM_Menu(divName)




