// LAHOVARY.RO LISTA.JS
// (C) Dan Mirescu


 var lista = document.getElementById('lista');
 var lista_tr = lista.getElementsByTagName('tr');
 
 /*var ls = new Array();
 ls[1] = "Drugan Constantin Toma";
 ls[2] = "Balasel Adrian";
 ls[3] = "Petre Aurelia";*/
 
 var selected_tr = -1;
 
 function winSize()
{
  var myWidth = 0, myHeight = 0;
  //myHeight = document.body.clientHeight > window.innerHeight ? document.body.clientHeight : window.innerHeight;
  
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  /*if(typeof( window.innerWidth ) == 'number' && document.body && document.body.clientHeight)
  {
    myHeight = document.body.clientHeight > window.innerHeight ? document.body.clientHeight : window.innerHeight;
  }
  /*window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );*/
  var size = new Array();
  size[1] = myWidth;
  size[2] = myHeight;
  //alert(size[1] + ',' + size[2]);
  return size;
}

/*function getScrollXY()
{
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}*/

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function scrollTop()
{
  return getScrollXY()[1];
}
 
 function pop_in()
 {
    var content = this.getElementsByTagName('td')[0].firstChild.nodeValue;
    //alert(content);
    // cream un popup mare
    /*var h = document.body.clientHeight;
    var w = document.body.clientWidth;*/
    
    var s = winSize();
    //alert(s);
    var w = s[1];
    var h = s[2] + 120;
    var bg = document.getElementById('bg');
    bg.style.top = (scrollTop() - 50) + 'px';
    bg.style.width = w + 'px';
    bg.style.height = h + 'px';
    bg.style.display = 'block';
    
    var popup = document.getElementById('popup');
    // calculam pozitionarea la centru
    popup.style.left = ((w - 400) / 2) + 'px';
    popup.style.top = (300 + this.nr * 18) + 'px';

    ajax_loadContent('popup',launcher + '?id=' + content);
    //popup.innerHTML = ls[this.nr] + ' &nbsp;&nbsp; <a href="javascript:void(0)" onclick="pop_out()">Închide</a>';
    popup.style.display = 'block';
    
    this.style.backgroundColor = '#90664D';
    selected_tr = this.nr;
    //window.scroll(0,scroll_offset);
    window.onscroll = update_scr_popup;
    window.onresize = update_res_popup;
 }
 
 function pop_out()
 {
    var popup = document.getElementById('popup');
    popup.style.display = 'none';
    popup.innerHTML = '';
    var bg = document.getElementById('bg');
    bg.style.display = 'none';
    lista_tr[selected_tr].style.background = 'none';
    selected_tr = -1;
 }
 
 for(i=1;i<lista_tr.length;i++)
 {
  if(lista_tr[i].id != 'no_fx')
  {
    lista_tr[i].nr = i;
    lista_tr[i].onclick = pop_in;
    lista_tr[i].onmouseover = function() { this.style.backgroundColor = '#DFD4C2'; };
    lista_tr[i].onmouseout = function() { if(this.nr != selected_tr) this.style.background = 'none'; };
  }
 }
 
 function update_scr_popup()
 {
    var bg = document.getElementById('bg');
    
    if(bg.style.display == 'block')
    {
      //alert(scrollTop());
      bg.style.top = (scrollTop() - 100) + 'px';
    }
 }
 
 function update_res_popup()
 {
    var bg = document.getElementById('bg');
    
    if(bg.style.display == 'block')
    {
      var s = winSize();
      var w = s[1];
      var h = s[2] + 200;
      bg.style.width = w + 'px';
      bg.style.height = h + 'px';
      // repozitionare popup
      var popup = document.getElementById('popup');
      popup.style.left = ((w - 400) / 2) + 'px';
      //popup.style.top = (300 + this.nr * 18) + 'px';
    }
 }
 
window.onscroll = window.onresize = function() {};
