// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function catalog_box() {
  var box = $('catalog-box');
  if( box ) {
    $('new-companies-box').style.margin = '0px';
    $('new-products-box').style.margin = '0px';
    events_catalog_box(); 
  }
}

function products_catalog_box(elem) { catalog_box_real('products'); }
function companies_catalog_box(elem) { catalog_box_real('companies'); } 
function events_catalog_box(elem) { catalog_box_real('events'); }  

function catalog_box_real( active ) {
  //get objects
  var new_products_box = $('new-products-box');
  var new_companies_box = $('new-companies-box');
  var new_events_box = $('new-events-box');
  
  var panel_products_item = $$('#panel-products-item span')[0];
  var panel_companies_item = $$('#panel-companies-item span')[0];
  var panel_events_item = $$('#panel-events-item span')[0];
  
  //prepare list
  new_products_box.style.display = 'none';
  new_companies_box.style.display = 'none';
  new_events_box.style.display = 'none';
  
  //prepare panel
  panel_products_item.className = 'link';
  panel_companies_item.className = 'link';
  panel_events_item.className = 'link';
  
  //apply link
  Event.observe( panel_products_item, 'click', products_catalog_box );
  Event.observe( panel_companies_item, 'click', companies_catalog_box );
  Event.observe( panel_events_item, 'click', events_catalog_box );
  
  //set active item
  var active_item = $$('#panel-'+active+'-item span')[0];
  active_item.className = 'normal';
  
  //set active box 
  var active_box = $('new-'+active+'-box');
  active_box.style.display = 'block';
}

function hide_flash() {
  var flash = $$('div.flash')[0];
  if( flash && flash.innerHTML.length < 100 )
    setTimeout('hide_flash_real()',3000);
}

function hide_flash_real() {
  $$('div.flash').invoke('fade');
}

document.observe("dom:loaded", function() {
  // initially hide all containers for tab content
  hide_flash()
  catalog_box();
});
