function removeselobj()
{

 var remobj;
 var lev=new Array();
  for(j=1;j<5;j++)
  {
    lev[j]=document.getElementById('level'+j);
    for(i=0;i<IDob[obID].length;i++)
    {
     if(remobj=document.getElementById(j+"obj"+IDob[obID][i]))
   	 lev[j].removeChild(remobj);
    }
  } 
   objshow[obID]=false;
}

function addhintinfo(datas)
{

	if(!(objinfo[datas[0][0]]))
	{
     objinfo[datas[0][0]]= new Array();
	 for(i=1; i<datas[0].length; i++)
	 {
	 	objinfo[datas[0][0]][i-1]=datas[0][i];
	 }
	}
				
	
	//alert('addhintinfo2' + datas[0][2]);
	document.getElementById('hoteltitle').innerHTML=datas[0][1];

	document.getElementById('hotelabout').innerHTML=datas[0][2];
	document.getElementById('hotelprice').innerHTML=datas[0][4];

	var tempstar="";
	
	for(i=1;i<=datas[0][3];i++)
	{
		tempstar+='<img src="img/star_a.gif">';
	}

	document.getElementById('hotelstars').innerHTML=tempstar;
	document.getElementById('hotellink').href=datas[0][5]+"/";
	document.getElementById('hotelimg').src="photoinmap/"+datas[0][0]+".jpg";
		
 
   showmovehint();
} 

 var tempt,templ;
 
 var tipznacka;
function showobjhint(objID,obyekt) //part1
{
	 //alert("showobjhint" +objID);
	
	 tempt=obyekt.style.top;
	 templ=obyekt.style.left;
	 	if(objinfo[obID])
	{
		addhintinfo(objinfo[obID])
				//showmovehint();
	}
	 else
	{
		loadXMLDoc('gethotelinfo.php?hotelID='+objID,'addhintinfo',6);
	}
	 

}

var deltaheight=-7;
function showmovehint() //part2
{
	
	
	var lev=document.getElementById('level'+level);
	var doh=document.getElementById('divhint');
	pngheight=doh.offsetHeight+deltaheight;
	var pngwid=doh.offsetWidth;
    
	pngwidth=-10;
	
	
	
	var levtop=parseInt(lev.style.top);
	var	tt=parseInt(tempt)-pngheight+levtop;
	var delt=0;
	
	var levleft=parseInt(lev.style.left);
	var	ll=parseInt(templ)+levleft;
	var deltl=0;
	
	
	if(tt<0)
	{
 		
		if(levtop>tt)delt=-levtop;
		else delt=-tt;
	}  

//alert(ll+pngwid+"    "+maindivW);




	delt=-tt;
	deltl=-ll;

	if((ll+pngwid)>(maindivW-15))//-15 kakoy to delta
	{
	 	deltl=(ll+pngwid+15)-maindivW;
	}

	doh.style.top=(tt)+'px';//26-visota tag-a
	doh.style.left=(parseInt(templ)-pngwidth+parseInt(lev.style.left))+'px';
	
	doh.style.visibility='visible';
	showhint=true;
	
	

	if(delt>0 || deltl>0)
		{
			if(deltl<0)deltl=0;//proverot i dlya delt bez l
			if(delt<0)delt=0;
			
			moveslowLT('vverx',delt,'napravo',deltl);
			
		}


}


function hideobjhint()
{
	var doh=document.getElementById('divobjhint');
	doh.style.visibility='hidden';
	showhint=false;
	return false;
}

function vobjhint()
{
	var doh=document.getElementById('divobjhint');
	//doh.style.left=-200;   esli nepravilno budet rabotat otkrit komentarii
	//doh.style.top=-200;
	doh.style.visibility='visible';
 // alert(this.id);
 // alert(this.style.left);
  //alert(this.style.top);
}


function createicon(iconimg,width,height,iconx,icony,shad)
{
	this.iconimg=iconimg;
	this.shad=shad;
	this.width=width;
	this.height=height;
	this.iconx=iconx;
	this.icony=icony;
}


function addobjtomap(objid,x,y,icon)
{
	//alert(objid);
	//tmp=new String(objid);
    //objid=tmp.substr(5,objid.length);
	//alert(objid);
	this.objid=objid;
	this.x=x;
	this.y=y;
	
	var levarray=new Array(0,document.getElementById('level1'),document.getElementById('level2'),document.getElementById('level3'),document.getElementById('level4'));

	var ind;
	var backg,shadbackg;
  for(j=1;j<=4;j++)
  {	
  
  	
     if(navigator.appName.indexOf("Explorer")!=-1)//esli explorer to backgroung....
	 {
		backg="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+icon.iconimg+"', sizingMethod='scale')";
		shadbackg="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+icon.shad+"', sizingMethod='scale')";
	 }
	  else
	 {
		backg="background: no-repeat url('"+icon.iconimg+"')";
		shadbackg="background: no-repeat url('"+icon.shad+"')";
	 }
	  	tempid=objid+'-'+j;
   		div=create( "div", { id: tempid,style: "position:absolute; width:"+icon.width+"px; height:"+icon.height+"px; z-index:5; cursor:pointer; "+backg+"; top:"+(Math.round(y/Math.pow(k,(4-j)))-icon.icony)+"px;left:"+(Math.round(x/Math.pow(k,(4-j)))-icon.iconx)+'px' });
   		divshad=create( "div", { id: "shad"+tempid,style: "position:absolute; width:"+icon.width+"px; height:"+icon.height+"px; z-index:5; cursor:pointer;  "+shadbackg+"; top:"+(Math.round(y/Math.pow(k,(4-j)))-icon.icony)+"px;left:"+(Math.round(x/Math.pow(k,(4-j)))-icon.iconx)+'px' });

		//div.setAttribute("onclick","showobjhint()");
		div.onclick = function (){showobjhint(objid,this);   };
		
		levarray[j].appendChild(divshad);
	    levarray[j].appendChild(div);
  }
	 
	 
}




/*
function addobjtomap()//all object(is bad)
{
var levarray=new Array(0,document.getElementById('level1'),document.getElementById('level2'),document.getElementById('level3'),document.getElementById('level4'));



var ind;
  for(j=1;j<5;j++)
  {
   for(i=0;i<Xob[obID].length;i++)
	 {
	  ind=j+'-'+obID+'-'+i;


   div=create( "div", { id: j+"obj"+IDob[obID][i],style: "position:absolute; width:16px; height:16px; z-index:5; cursor:pointer; background: no-repeat url(files/"+ objtip[obID] +".gif); top:"+(Math.round(Yob[obID][i]/Math.pow(k,(4-j)))-8)+"px;left:"+(Math.round(Xob[obID][i]/Math.pow(k,(4-j)))-8)+'px' });

	div.setAttribute("onclick","showobjhint()");
	div.onclick = showobjhint;




	   levarray[j].appendChild(div);
	 } 
	}
	 
	 
   }
*/


function showobj(objID)
{
  obID=objID;// index obyekta
  if(!objshow[obID])
   {
   
       if(!objload[obID])//esli koordinati obektov ne zagrujeni
	 {
	

  		requestdata('obekti.php?ob='+objtip[objID],'loadobj');
  	 }
	  else
	 {
	  addobjtomap();
	 }
	 //addobjtomap();
	 
	 
	 objshow[obID]=true;
	  //potom nado pokazat obyekti (proisxoditv ajax)
   }
    else
  {
    removeselobj();
  }
  if(objID==9)
   {
  	t1ID = window.setTimeout("showobj(8)", 500);
	t2ID = window.setTimeout("showobj(10)", 1000);
   }
}

var chatwindow=0;
function closehint()
{
   chatwindow=0;
   var divhint=document.getElementById('divhint');
   divhint.style.top=10000+'px';
   divhint.style.visibility='hidden';
   showhint=false;
  return false;
}


function showstreet(streetID)
{
 if(streetID!=-1)
 {
//osnovnaya karta
   var lx,ly;
   var lev=document.getElementById('level'+level);
   lx=-strx[streetID]* Math.pow(2,(level-1))+Math.round(maindivW/2);
   ly=-stry[streetID]* Math.pow(2,(level-1))+Math.round(maindivH/2);

	if(lx>0)lx=0; //proverka granic
 	if(ly>0)ly=0;
	if(ly<(-(divh[level]-maindivH))&& (ly<0) )ly=-(divh[level]-maindivH);
	if(lx<(-(divw[level]-maindivW))&& (lx<0))lx=-(divw[level]-maindivW); 
	//alert(lx+' '+ly);
   lev.style.left=lx +'px';   
   lev.style.top=ly+'px';
   ctopokazat();
//podskazka


   var divhint=document.getElementById('divhint');
   var divinfo=document.getElementById('divinfo');
   divinfo.innerHTML=street[streetID];
   divhint.style.visibility='visible';
   divhint.style.left=(strx[streetID]* Math.pow(2,(level-1))-pngwidth+lx)+'px';//ne pereputaysya so znakami
   divhint.style.top=(stry[streetID]* Math.pow(2,(level-1))-pngheight+ly)+'px';
   showhint=true;
 }
 
}

function addstreets()
{
  	 var selstr=document.getElementById('strs');
	 for(i=0;i<street.length;i++)
	 {
	 	var opt = document.createElement('OPTION');
     	opt.value = i;
     	opt.text = street[i];
     	selstr.options.add(opt); 
	 }

}

