//--------------функции бегунка на драг энд дроп----------
//------------определяет позицию курсора относительно елемента, который посылает событие ev
function mouseLayerXY(ev)
{
  if (!ev) {ev = window.event; ev.target = ev.srcElement}
  var x = 0;
  var y = 0;

  if (ev.layerX)//Gecko
  {
    x = ev.layerX; 
    y = ev.layerY;
  }
  else if (ev.offsetX)//IE, Opera
  {
    x = ev.offsetX;
    y = ev.offsetY;
  }
  return {"x":x, "y":y};
}


//---------------------устанавливает разрешение на беготню
function navMouseDown(obj){
obj.setAttribute("move", "1");
}

//*****---------------------двигает бегунок по полосочке---------------------------------
function divMouseMove(ev){
var p=mouseLayerXY(ev).y+4;
var r=parseInt(e('begun').style.top);
var razn=r-p;
if(e('begun').getAttribute("move")!=0&p>5&razn<10){
e('begun').style.top=p+'px';
}
};

////--------------------говорит что делать когда бегунок остановился--------------------------
function divMouseUp(ev){
e('begun').setAttribute("move", "0");
var p=Math.round(parseInt(mouseLayerXY(ev).y+4)/9); 
	navigation.level=p;
	navigation.setBegunok(p)
    var v=navigation.countM-p;   
    map.setZoom(v);
}
//--------------закончились функции бегунка на драг энд дроп----------

function  VNav(container){
this.container=container;
this.countM=18;//количество уровней карты
this.level=this.countM-map.getZoom();//текущий уровень карты
//действия по кликам-------------------------------------
this.TopClick=function(){map.up(); };
this.LeftClick=function(){map.left(); };
this.RightClick=function(){map.right(); };
this.BottomClick=function(){map.down(); };
this.CenterClick=function(){
 if(e('navbeg').style.display=='none')
  {
   e('navbeg').style.display='';
   e('topImg').style.display='';
   e('leftImg').style.display='';
   e('rightImg').style.display='';
   e('bottomImg').style.display='';   
   e('plusImg').style.display='';
   e('minusImg').style.display='';
   e('centerImg').style.margin='1px';
  }
 else
  {
   e('navbeg').style.display='none';
   e('topImg').style.display='none';
   e('leftImg').style.display='none';
   e('rightImg').style.display='none';
   e('bottomImg').style.display='none';   
   e('plusImg').style.display='none';
   e('minusImg').style.display='none';
   e('centerImg').style.marginTop='30px';
   if(navigator.appVersion.indexOf('MSIE 6.0')==-1)
	{
     e('centerImg').style.marginLeft='34px';
     e('centerImg').style.marginRight='39px'; 
	}else
	{
	 e('centerImg').style.marginLeft='17px';
    }
    if(navigator.appVersion.indexOf('MSIE 7.0')!=-1) { e('centerImg').style.marginLeft='28px';}
  } 
};
this.PlusClick=function()
{	
    if(navigation.level>1)
    {
    navigation.level=Number(navigation.level)-1;
	
	var v=navigation.countM-navigation.level;
    //alert(v);
    map.setZoom(v);
    //alert(map.getZoom());
	navigation.setBegunok(navigation.level);    
    }
};

this.MinusClick=function()
{
if(navigation.level<navigation.countM-1)
    {
    navigation.level=navigation.level+1;
    var v=navigation.countM-navigation.level;     
    map.setZoom(v);
	navigation.setBegunok(navigation.level);

    }
};
//--------------------------------------------------------------действия по кликам--------------------


//--------------------поставить бегунок на нужный уровень-------------------
this.setBegunok=function(p){ 
navigation.level=p;
var height=(Number(p)-1)*9;
if(height>=0){
e('begun').style.top=height+'px';
}
}

//---------------------------------отлов событий :)))------------------
this.onEvent=function(ev)
{
if (ev=='mapZoom') 
 {
	if(navigation.level!=navigation.countM-map.getZoom())
	{
		navigation.level=navigation.countM-map.getZoom();
		navigation.setBegunok(navigation.level);
	}
 }
}
//----------------------------------------------------------


this.createNav = function (container) {	
if(navigator.appVersion.indexOf('MSIE 6.0')!=-1) {var pix='17px';}else{var pix='33px';} //поправка на пиксели для шестого ie
if(navigator.appVersion.indexOf('MSIE 7.0')!=-1) {var pix='34px';}
this.mainDiv = document.createElement("div");
this.mainDiv.style.width='110px';

///-----------------------------пошли кнопочки--------------------------
this.ButtonTop=new buttonOK(this.mainDiv);
this.ButtonTop.Name='<img src="/img/button/top.gif" style="margin-top: 5px;" />';
this.ButtonTop.onclick=this.TopClick;
this.ButtonTop.attributeSet('style.float', 'none');
this.ButtonTop.attributeSet('style.marginLeft', pix);
this.ButtonTop.attributeSet('style.marginRight', pix);
this.ButtonTop.attributeSet('id', 'topImg');
this.ButtonTop.CreateButton();

this.ButtonLeft=new buttonOK(this.mainDiv);
this.ButtonLeft.Name='<img src="/img/button/left.gif" style="margin-top: 5px;" />';
this.ButtonLeft.onclick=this.LeftClick;
this.ButtonLeft.attributeSet('style.margin', '1px');
this.ButtonLeft.attributeSet('id', 'leftImg');
this.ButtonLeft.CreateButton();

this.ButtonCenter=new buttonOK(this.mainDiv);
this.ButtonCenter.Name='<img src="/img/button/bcenter.gif" style="margin-top: 6px;" />';
this.ButtonCenter.onclick=this.CenterClick;
this.ButtonCenter.attributeSet('style.margin', '1px');
	this.ButtonLeft.attributeSet('id', 'centerImg');
this.ButtonCenter.CreateButton();

this.ButtonRight=new buttonOK(this.mainDiv);
this.ButtonRight.Name='<img src="/img/button/right.gif" style="margin-top: 5px;" />';
this.ButtonRight.onclick=this.RightClick;
this.ButtonRight.attributeSet('style.margin', '1px');
this.ButtonRight.attributeSet('id', 'rightImg');
this.ButtonRight.CreateButton();

this.ButtonBottom=new buttonOK(this.mainDiv);
this.ButtonBottom.Name='<img src="/img/button/bottom.gif" style="margin-top: 5px;" />';
this.ButtonBottom.onclick=this.BottomClick;
this.ButtonBottom.attributeSet('style.marginLeft', pix);
this.ButtonBottom.attributeSet('style.marginRight', pix);
this.ButtonBottom.attributeSet('style.marginTop', '1px');
this.ButtonBottom.attributeSet('style.marginbottom', '1px');
this.ButtonBottom.attributeSet('id', 'bottomImg');
this.ButtonBottom.CreateButton();

this.ButtonPlus=new buttonOK(this.mainDiv);
this.ButtonPlus.Name='+';
this.ButtonPlus.onclick=this.PlusClick;
this.ButtonPlus.attributeSet('style.marginTop', '1px');
this.ButtonPlus.attributeSet('style.marginbottom', '16px');
this.ButtonPlus.attributeSet('style.marginLeft', pix);
this.ButtonPlus.attributeSet('style.marginRight', pix);
this.ButtonPlus.attributeSet('id', 'plusImg');
this.ButtonPlus.CreateButton();

//------------------------------------вклинилась дорожка с бегунком-----------------------
this.bt = document.createElement("a");
this.bt.className='navbeg';
this.bt.id='navbeg';
var height=(this.countM-1)*9;
this.bt.style.height=height+'px';
this.bt.setAttribute("onmousemove", 'divMouseMove(event)');
this.bt.setAttribute("onmouseup",'divMouseUp(event)');

if(navigator.appVersion.indexOf('MSIE')!=-1){this.bt.setAttribute("onmouseup", new Function('divMouseUp(event)'));
this.bt.setAttribute("onmousemove", new Function('divMouseMove(event)'));}
this.bt.innerHTML='<span move="0" class="begunNav" onMouseDown="navMouseDown(this)" id="begun" style="top: 0px;" onMouseUp="divMouseUp()"></span>';
this.mainDiv.appendChild(this.bt);
//------------------------закончилась дорожка с бегунком------------------------------
this.ButtonMinus=new buttonOK(this.mainDiv);
this.ButtonMinus.Name='-';
this.ButtonMinus.onclick=this.MinusClick;
this.ButtonMinus.attributeSet('style.marginLeft', pix);
this.ButtonMinus.attributeSet('style.marginRight', pix);
this.ButtonMinus.attributeSet('style.marginTop', '10px');
this.ButtonMinus.attributeSet('id', 'minusImg');
this.ButtonMinus.CreateButton();
this.container.appendChild(this.mainDiv);
//---------------------------------------закончились кнопки-------------------------

navigation.setBegunok(navigation.level); //бегунок, МЕСТО!

}
}	

