var tab_name = null;
var active_tab = null;
var active_content = null;
var active_img = null;

var active_specs_tab = null;
var active_specs_content = null;

//this function activates or deactivates a menu button
function switch_menuButton(system, class_name, state)
{
   var button = document.getElementById('menuButton_'+system);
   if(button!=null)
     button.className = class_name;

   if(state=='on')
     change_img_src('menu_'+system, 'images/backgrounds/bg_menu_'+system+'2.gif')
   else if(state=='off')
     change_img_src('menu_'+system, 'images/backgrounds/bg_menu_'+system+'.gif') 
}


function activate_menuButton(system)
{
   var button = document.getElementById('menuButton_'+system);
   if(button!=null)
     button.className = 'activated_menu_button';

   change_img_src('menu_'+system, 'images/backgrounds/bg_menu_'+system+'2.gif')
}

function deactivate_menuButton(system)
{
     var button = document.getElementById('menuButton_'+system);
     if(button!=null)
       button.className = 'menu_button';

     change_img_src('menu_'+system, 'images/backgrounds/bg_menu_'+system+'.gif')
}


// function to activate one of the side menu tabs
function activate_tab(new_tab, default_tab)
{
  // if no tab has yet been activated, the default tab is 
  if(active_tab == null)
  {
    tab_name = default_tab;
    active_tab = document.getElementById(tab_name+'_tab');
    active_content = document.getElementById(tab_name);
    active_img = document.getElementById(tab_name+'_img');
  }

  //---------------------------------------
  // DEACTIVE PREVIOUSLY SELECTED TAB
 
  // hide previously selected tab content
  active_content.style.visibility = 'hidden';

  // if the previous tab concerned the specifications tab hide its contents explicitly
  // and move its content down so it doesn't overlap anymore
  if(tab_name=='specs')
  {
    active_specs_content.style.visibility = 'hidden';

    active_content.style.top = '1000px';
  }

  // reset the tab's class to the deactivated appearance
  active_tab.className = 'side_menu';
  // reset the image source
  active_img.src = './images/menu_'+tab_name+'_w.png';

  // perform PNGfix just in case we're dealing with IE6
  fixPNG(active_img);

  //---------------------------------------
  // ACTIVE NEWLY SELECTED TAB

  tab_name = new_tab;
  active_tab = document.getElementById(tab_name+'_tab');
  active_content = document.getElementById(tab_name);
  active_img = document.getElementById(tab_name+'_img');

  // set the tab's class to the activated appearance
  active_tab.className = 'activated_side_menu';
  // set the image source
  active_img.src = './images/menu_'+tab_name+'.png';

  // perform PNGfix just in case we're dealing with IE6
  fixPNG(active_img);

  // show newly selected tab content
  active_content.style.visibility = 'visible';
	
  // if the new tab concerns the specifications tab show its contents explicitly
  // and move the content area into view
  if(tab_name=='specs')
  {
  
    //hide any image or video 
    // that is being displayed
    hide_scrollbar_img();
    if(videoPlaying)
      hide_scrollbar_video();
	
    //stop the autoShow function if running	
    if(autoShowOn)
      autoShowOn = false;
  
    if(active_specs_content!=null)
	{
      active_content.style.top = '0px';
      active_specs_content.style.visibility = 'visible';
    }
    else 
    {
      active_content.style.top = '0px';
      activate_specs_tab('specs1', 'specs1');
    }
	
  }
  return false;

}

// function to activate one of the specifications menu tabs on the bottom of the page
function activate_specs_tab(new_tab, default_tab)
{
  // if no tab has yet been activated, the default tab is 
  if(active_specs_tab == null)
  {
    active_specs_tab = document.getElementById(default_tab+'_tab');
    active_specs_content = document.getElementById(default_tab);
  }

  //---------------------------------------
  // DEACTIVE PREVIOUSLY SELECTED TAB
 
  // hide previously selected tab content
  active_specs_content.style.visibility = 'hidden';

  // reset the tab's class to the deactivated appearance
  active_specs_tab.className = 'specs_tab';

  //---------------------------------------
  // ACTIVE NEWLY SELECTED TAB

  active_specs_tab = document.getElementById(new_tab+'_tab');
  active_specs_content = document.getElementById(new_tab);

  // set the tab's class to the activated appearance
  active_specs_tab.className = 'activated_specs_tab';
  
  // show newly selected tab content
  active_specs_content.style.visibility = 'visible';

  return false;

}

function show_specs_photo(el,specs_nr, src)
{
  

  // blur element
  el.blur();

  // get pointers
  var specs_photo = document.getElementById('specs_photo');
  var specs = document.getElementById('specs'+specs_nr);

  // set source
  specs_photo.src = src;

  // set photo default size if not specified yet
  var photo_width = specs_photo.offsetWidth;
  if(photo_width < 50) photo_width = 200;
  var photo_height = specs_photo.offsetHeight;
  if(photo_height < 50) photo_height = 200;
  
  // set position
  var x = el.offsetLeft + el.offsetParent.offsetLeft;
  var y = el.offsetTop + el.offsetParent.offsetTop - specs.scrollTop;
  if(x + photo_width > specs_photo.offsetParent.offsetWidth)
    x = x-photo_width+20;
  var aux = (y + photo_height) - (specs_photo.offsetParent.offsetHeight - 40); 
  if(aux > 0)
    y = y-aux;
  specs_photo.style.left = x;
  specs_photo.style.top = y;

  // show photo
  specs_photo.style.visibility = 'visible';
}

function hide_specs_photo()
{
  // hide photo
  document.getElementById('specs_photo').style.visibility='hidden';
}
