// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
// tabs
function setTabBar() {
  if (IE6) return;
  $$('.tab_box').each(function(box){
    $(box).addClassName('enabled');
    $(box).insert({top: new Element('ul').addClassName('tab_bar')});
  });
  $$('.tab_box .tab_page .tab_title').each(function(tab, i){
    if (i == 0) $(tab).up('.tab_page').addClassName('active');
    $(tab).up('.tab_page').writeAttribute('tabPage', i+1);
    $(tab).up('.tab_box').down('.tab_bar').insert({
      bottom: Element('li').addClassName(i == 0 ? 'active' : null).insert({
        top: Element('a', {tabPage: i+1, href: '#', onclick: 'return false'}).insert({
          top: $(tab).innerHTML
        }).observe('click', switchTab)
      })
    });
  });
}

function switchTab() {
  $(this).up('.tab_box').select('.tab_page').each(function(page) {
    $(page).removeClassName('active');
  });
  $(this).up('li').adjacent('li').each(function(li){$(li).removeClassName('active')});
  $(this).up('li').addClassName('active');
  $(this).up('.tab_box').down('.tab_page[tabPage='+$(this).readAttribute('tabPage')+']').addClassName('active');
}

Event.observe(window, 'load', setTabBar);
