var current_main_tab = -1;
var current_prod_idx = -1;
var amplifiers_count = 0;
var amplifiers_list = new MakeAmplifiersList();
function MakeAmplifiersList()
{
  this[amplifiers_count++] = new product_item('<b>Kit1</b> - 300B S.E.T.<br>8.5W per channel', 'preview_kit1.html', 'kit1mk2.html');
  this[amplifiers_count++] = new product_item('<b>Kit2</b> - KT-88<br>18W per channel', 'preview_kit2.html', 'kit2.html');
  this[amplifiers_count++] = new product_item('<b>Interstage MonoBlock</b><br>300B Parallel 20W', 'preview_mono_p.html', 'monob01.html');
  this[amplifiers_count++] = new product_item('<b>L4 Series Power Amp</b><br>EL34 35W per channel', 'preview_l4_el34_pp.html', 'l4el34pp.html');
  this[amplifiers_count++] = new product_item('<b>L6 Series Power Amp</b><br>EL34 70W', 'preview_l6_el34_pp.html', 'javascript:alert(\'Coming Soon\')');
}
var digital_count = 0;
var digital_list = new MakeDigitalList();
function MakeDigitalList()
{
  this[digital_count++] = new product_item('DAC Range Overview', 'preview_dac_range.html', 'dacsoverview.html');
  this[digital_count++] = new product_item('<b>DAC Kit 2.0</b> - 12UA7', 'preview_dac_20.html', 'dac20.html');
  this[digital_count++] = new product_item('<b>DAC Kit 2.1</b> - Level A &amp; B', 'preview_dac_21.html', 'dac2_1.html');
  this[digital_count++] = new product_item('<b>DAC Kit 3.1</b><br>(transformer coupled output)', 'preview_dac_30.html', 'dac3_1.html');

  this[digital_count++] = new product_item('<b>DAC Kit 4.1</b><br>Limited Edition', 'preview_dac_41.html', 'DAC4_1.html');  
}
var preamps_count = 0;
var preamps_list = new MakePreampsList();
function MakePreampsList()
{
  this[preamps_count++] = new product_item('<b>L2 Line / Phono</b>', 'preview_l2_preamp.html', 'PQpre.html');
  this[preamps_count++] = new product_item('<b>L3 Line</b><br>(transformer coupled output)', 'preview_l3_line.html', 'l3linemk2.html');
  this[preamps_count++] = new product_item('<b>L3 Remote</b><br>(transformer coupled output)', 'preview_l3_remote.html', 'l3remote.html');
}
var analog_count = 0;
var analog_list = new MakeAnalogList();
function MakeAnalogList()
{
  this[analog_count++] = new product_item('<b>L3 Phono Stage</b>', 'preview_l3_phono.html', 'M3PhonoStage.html');
  this[analog_count++] = new product_item('<b>L2 Line / Phono</b>', 'preview_l2_preamp.html', 'PQpre.html');
  //this[analog_count++] = new product_item('<b>Moving Coil Step-up</b>', 'preview_stepup.html', 'stepup01.html');
}
var speakers_count = 0;
var speakers_list = new MakeSpeakersList();
function MakeSpeakersList()
{
  this[speakers_count++] = new product_item('AN/E Speaker Kits', 'preview_speakerkits.html', 'newSpkr.html');
  this[speakers_count++] = new product_item('AN/E Speaker <b>Kit04</b><br>(AlNiCo)', 'preview_kit04.html', 'speakerkit04.html');
}
function product_item(title, overview_page, product_page)
{
  this.title = title;
  this.overview_page = overview_page;
  this.product_page = product_page;
}
function ShowSubProducts(tab_idx, product_idx)
{
  var tmp_list;
  var tmp_count = 0;
  
  switch(tab_idx)
  {
    case 0:
      tmp_list = amplifiers_list;
      tmp_count = amplifiers_count;
      break;
    case 1:
      tmp_list = digital_list;
      tmp_count = digital_count;
      break;
    case 2:
      tmp_list = preamps_list;
      tmp_count = preamps_count;
      break;
    case 3:
      tmp_list = analog_list;
      tmp_count = analog_count;
      break;
    case 4:
      tmp_list = speakers_list;
      tmp_count = speakers_count;
      break;
  }
  for (i = 0; i < 6; i++)
  {
  	var tab = eval('document.getElementById(\'prod_tab_' + i + '\')');
  	
    if (i < tmp_count)
    {
      if (i == product_idx)
      {
        tab.className = 'prod_tab_active';
        document.getElementById('content_iframe').src = tmp_list[i].overview_page;
      }
      else
      {
        tab.className = 'prod_tab_inactive';
      } 
      tab.innerHTML = tmp_list[i].title;
    }
    else
    {
      tab.className = 'prod_tab_empty';
      tab.innerHTML = '&nbsp;';
    }
  }
  current_prod_idx = product_idx;
}
function SetMainTabIDX(tab_idx)
{
  current_main_tab = tab_idx;
  for (i = 0; i < 5; i++)
  {
    switch(i)
    {
      case 0:
        tab = document.getElementById('tab_amplifiers');
      	break;
      case 1:
        tab = document.getElementById('tab_digital');
      	break;
      case 2:
        tab = document.getElementById('tab_preamplifiers');
      	break;
      case 3:
        tab = document.getElementById('tab_analog');
      	break;
      case 4:
        tab = document.getElementById('tab_speakers');
      	break;
    }
    if (i == tab_idx)
    {
      tab.className = 'tab_active';
    }
    else
    {
      tab.className = 'tab_inactive';
    }
  }
  ShowSubProducts(tab_idx, 0);
}
function ProductClick(sent_td, prod_idx)
{
  if (current_main_tab == -1)
  	return;
  	
  if (sent_td.className == 'prod_tab_inactive')
  {
    ShowSubProducts(current_main_tab, prod_idx);
  }
}
function TabClick(tab_td, tab_idx)
{
  if(tab_td.className != 'tab_active')
  {
    SetMainTabIDX(tab_idx);
  }
}
function VisitProductPageClick()
{
  if (current_main_tab < 0 || current_prod_idx < 0)
  	return;
  
  var tmp_list;
  var tmp_count = 0;
  
  switch(current_main_tab)
  {
    case 0:
      tmp_list = amplifiers_list;
      tmp_count = amplifiers_count;
      break;
    case 1:
      tmp_list = digital_list;
      tmp_count = digital_count;
      break;
    case 2:
      tmp_list = preamps_list;
      tmp_count = preamps_count;
      break;
    case 3:
      tmp_list = analog_list;
      tmp_count = analog_count;
      break;
    case 4:
      tmp_list = speakers_list;
      tmp_count = speakers_count;
      break;
  }
  if (tmp_count == 0)
  	return;
  if (current_prod_idx >= tmp_count)
  	return;
  	
  document.location.href = tmp_list[current_prod_idx].product_page;
}