var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body


window.onload = function() {
  StartInit();
  
  MapInit();
}



function MapInit() {
  var temps = document.getElementsByTagName('div');
  var divs = new Array();
  
  for(var i=0;i<temps.length;i++) {
    if(temps[i].nodeType == 1 && temps[i].tagName == 'DIV' && temps[i].className == 'item') {
      var att = temps[i].getAttribute('counter');
      if(att > 0)
        divs.push(temps[i]);
    }
  }
  
  for(var i=0;i<divs.length;i++) {
    divs[i].onmouseover = mover; 
    divs[i].onmouseout = mout; 
    
    var uid = divs[i].getAttribute('uid');
    ge(uid).onmouseover = umover;
    ge(uid).onmouseout = uout;
  }
  
  
  var tbds = getElementsByClass('officeplaces',ge('Note'),'tbody');
  
  for(var j=0;j<tbds.length;j++) {
    var trs = tbds[j].getElementsByTagName('tr');
    for(var i=0;i<trs.length;i++) {
      trs[i].onmouseover = function() { this.style.background = '#ccc';}
      trs[i].onmouseout = function() { this.style.background = '';}
    }
  }
}

var zindex = 100;
var active = {};
var activet = {};
var acTime = 400;
var activePossX = {};
var activePossY = {};

/**
 *  SHOW
 */ 
function mover(e) {
  var e = getEvent(e);
  var y = getMouseY(e);
  var x = getMouseX(e); 

  var uid = this.getAttribute('uid');  
  var div = ge(uid);
  
  
  div.style.zIndex = zindex++;
  div.style.display = 'block';
  var img = this.getElementsByTagName('img');
  img = img[(img.length-1)];
  img.src = '/img/map/point-active.png';
  
  var l = getElementsByClass('legend', div, 'div').length;
  var maxLeft = (l > 1) ? 175 : 375;
  if(div.offsetLeft > maxLeft) {
    div.style.left = div.offsetLeft + (maxLeft - div.offsetLeft) + 'px';
  }
  
  
  if(active[uid])
    clearTimeout(activet[uid]);
    
  active[uid] = true;
}


function umover() {
  //cl('X OVER');
  var uid = this.id;
  active[uid] = true;
  if(activet[uid])
    clearTimeout(activet[uid]);
}
function uout() {
  //cl('X OUT');
  var uid = this.id;
  activet[uid] = setTimeout('mout2(\''+uid+'\')', acTime);
}

function mout(e) {
  var uid = this.getAttribute('uid');
  //cl('OUT');
  activet[uid] = setTimeout('mout2(\''+uid+'\')', acTime);
}

function mout2(uid) {
  //cl('OUT2');
  ge(uid).style.display = 'none';
  active[uid] = false;
  
  var img = prevObj(ge(uid)).getElementsByTagName('img');
  img = img[(img.length-1)];
  img.src = '/img/map/point.png';
}




function prevObj(obj) {
  var p = obj;
  do p = p.previousSibling;
    while (p && p.nodeType != 1);
  return p;
}



function lhightover(obj) {
  obj.getElementsByTagName('h3')[0].style.color = '#f26e0d';
      
}

function lhightout(obj) {
  obj.getElementsByTagName('h3')[0].style.color = '';
}
