// SANKI_VOLUME.JS

function refresh_vol()
{
  //alert("se face refresh");
  vol = menu.getElementsByTagName('a');
  /*if(!vol_left) alert("Eroare sanki_volume.js : vol_left nu e specificat");
  if(!vol_right) alert("Eroare sanki_volume.js : vol_right nu e specificat");*/
  
  for(i=0;i<vol.length;i++)
  {
    if(vol[i].className == 'left') vol[i].onclick = meniu_stanga;
    else if(vol[i].className == 'right') vol[i].onclick = meniu_dreapta;
    if(vol[i].className != 'selected')
    {
      vol[i].base = new Array();
      vol[i].hover = new Array();
      vol[i].bubble = vol[i].getElementsByTagName('span')[0];
      vol[i].imgs = vol[i].getElementsByTagName('img');
      var j;
      for(j=0;j<vol[i].imgs.length;j++)
      {
        if(vol[i].imgs[j].className == 'h') vol[i].hover.push(j);
        else if(vol[i].imgs[j].parentNode.nodeName != 'SPAN') vol[i].base.push(j);
      }
      vol[i].onmouseover = meniu_hover;
      vol[i].onmouseout = meniu_leave;
    }
  }
}

function meniu_hover()
{
  //meniu_event();
  this.style.marginTop = '-5px';
  var i;
  for(i=0;i<this.base.length;i++)
    this.imgs[this.base[i]].style.display = 'none';
  for(i=0;i<this.hover.length;i++)
    this.imgs[this.hover[i]].style.display = 'inline';
  
  if(this.bubble) this.bubble.style.display = 'block';
}

function meniu_leave()
{
  this.style.marginTop = '0px';
  //meniu_event();
  if(this.bubble) this.bubble.style.display = 'none';
  
  var i;
  for(i=0;i<this.hover.length;i++)
    this.imgs[this.hover[i]].style.display = 'none';
  for(i=0;i<this.base.length;i++)
    this.imgs[this.base[i]].style.display = 'inline';
}

function meniu_stanga()
{
 // facem ce face PHP-ul, rescriem meniul 
  var u = vol_left;
  var p = u <= 10 ? 1 : u-8;
  meniu_update(p);
}

function meniu_dreapta()
{
  var p = vol_right;
  meniu_update(p);
}

function meniu_update(p)
{
  var html = '';
  var i,n,nr;
 
  if(p == 1) html += '<div class="sep">&nbsp;</div>';
  if(p > 1) html += '<a href="javascript:void(0)" class="left"><img src="style/sel_nr/left.png" alt="&lt;" /><img class="h" src="style/sel_nr/left_h.png" alt="&lt;" /></a>';
  // LISTA >= 9 volume
  for(i=0;(i<9 && p+i <= nr_total_volume);i++)
  {
    // scoatem din $i cele doua cifre
    nr = n = p + i;
    html += nr == selected_vol ? '<a class="selected" href="volume.php?vol=' + n + '">' : '<a href="volume.php?vol=' + n + '">';
    var v = new Array();
    while(n > 0)
    {
      v.push(n % 10);
      n = parseInt(n / 10);
      //echo "n este $n";
    }
    v.reverse();
    //$l = count($v);
    //for($j=0;$j<$l;$j++)
    for(j in v)
    {
      if(nr == selected_vol) html += '<img src="style/sel_nr/' + v[j] + '_h.png" alt="' + v[j] + '" />';
      else html += '<img src="style/sel_nr/' + v[j] + '.png" alt="' + v[j] + '" />';
    }
    if(nr != selected_vol) for(j in v)
    {
      html += '<img class="h" src="style/sel_nr/' + v[j] + '_h.png" alt="' + v[j] + '" />';
    }
    
    html += '<span><img src="volume/snaps/' + nr + '_mic.jpg" alt="12" /></span></a>';
    
   
  }
  // RIGHT
  
  /*if((p>1 && i == 9) /*|| (p == 1 && i == 10))*/
  
  ul = p + 8 > nr_total_volume ? nr_total_volume : p + 8;
  
  if(ul != nr_total_volume) html += '<a href="javascript:void(0)" class="right"><img src="style/sel_nr/right.png" alt="&gt;" /><img class="h" src="style/sel_nr/right_h.png" alt="&gt;" /></a>';
  //if(p == 1) ul = 10;
  //echo "\$p: $p, \$ul: $ul   ";
  //html += '<script type="text/javascript">var vol_left = ' + $p + '; var vol_right = ' . $ul . '; refresh_vol(); alert("da");</script>';
  html += '<div class="clear"></div>';
  // UPDATE-uri
  menu.innerHTML = html;
  vol_left = p;
  vol_right = ul;
  //alert(vol_left + ' ' + vol_right);
  refresh_vol();
}

// -------------------------------------------------------------------------------------
// Pentru first-run:
var vol, menu;
menu = _id('volume-selector-menu');
//refresh_vol();

// facem acum un calcul .. vrem ca volumul selectat sa fie relativ la mijloc in meniu
var ini_p = selected_vol <= 6 ? 1 : selected_vol - 4;
meniu_update(ini_p);

prepare_hover(_id('upper-menu').getElementsByTagName('a'));
prepare_hover(_id('volume-pic-link').getElementsByTagName('a'));
prepare_hover(_id('volume-desc').getElementsByTagName('a'));

var d_sheet_open = false;

_id('volume-pic-link').getElementsByTagName('a')[2].onclick = show_download_sheet;
/*_id('d_sheet_inchide').onmouseover = function() { this.style.color = 'gray'; };
_id('d_sheet_inchide').onmouseout = function() { this.style.color = 'black'; };*/
//_id('d_sheet_inchide').onclick = hide_download_sheet;
_id('d_sheet_menu').getElementsByTagName('a')[0].onclick = switch_info;
_id('d_sheet_menu').getElementsByTagName('a')[1].onclick = hide_download_sheet;

var info_opened = false;

function show_download_sheet()
{
  if(!d_sheet_open)
  {
    _id('download-sheet').style.display = 'block';
    d_sheet_open = true;
  }
  return false;
}

function hide_download_sheet()
{
  if(d_sheet_open)
  {
    _id('download-sheet').style.display = 'none';
    d_sheet_open = false;
  }
  return false;
}

function switch_info()
{
  var cts = _id('sheet-ct').getElementsByTagName('div')[0];
  var info = _id('d_sheet_info');
  var link = _id('d_sheet_menu').getElementsByTagName('a')[0];
  
  if(info_opened)
  {
    info.style.display = 'none'; cts.style.display = 'block';
    info_opened = false;
    link.firstChild.nodeValue = 'care-i treaba [?]';
  }
  else
  {
    cts.style.display = 'none'; info.style.display = 'block';
    info_opened = true;
    link.firstChild.nodeValue = '« înapoi';
  }
  
  return false;
}

prepare_hover(_id('sheet-ct').getElementsByTagName('div')[0].getElementsByTagName('a'));

