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


var downItem;
var xDownItem;

var options = { duration: 0.25 };


function initialize() {
  divs = $$('.CollapsiblePanel .CollapsiblePanelTab')
  divs.each(function(d) {
    d.onclick = menuDown;
    d.onmouseover = menuHover;
    d.onmouseout = menuOut;
  });
  
  divs = $$('.CollapsiblePanel .CollapsiblePanelTab_tall')
  divs.each(function(d) {
    d.onclick = menuDown;
    d.onmouseover = menuHoverTall;
    d.onmouseout = menuOutTall;
  });
  
  divs = $$('.CollapsiblePanelTabx');
  divs.each(function(d) {
    d.onclick = agentDown;
    d.onmouseover = agentHover;
    d.onmouseout = agentOut;
  });
  
  if ($(open)) { 
    Effect.BlindDown($(open), { duration: 0 });
    downItem = $(open).previous('div');
    $(open).previous('div').onclick = menuUp;
  }
}

// function openMenu(m) {
//   Effect.BlindDown(m, { duration: 0 });
//   m.onclick = menuUp;
//   downItem = m;
// }

function menuHover() {
  this.style.color = "#000";
  this.style.backgroundImage = "url('/images/nav-tab-hover-bg.gif')";
}

function menuOut() {
  this.style.color = "#fff";
  this.style.backgroundImage = "url('/images/nav-tab-bg.gif')";
}

function menuHoverTall() {
  this.style.backgroundImage = "url('/images/nav-tab-tall-hover-bg.gif')";
  this.style.color = "#000";
}

function menuOutTall() {
  this.style.backgroundImage = "url('/images/nav-tab-tall-bg.gif')";
  this.style.color = "#fff";
}

function agentHover() {
  this.style.backgroundColor = "#8c0021"
  this.style.color = "#fff";
}

function agentOut() {
  this.style.backgroundColor = "#efe6ca"
  this.style.color = "#000";
}



function menuDown() {
  Effect.BlindDown(this.next('div'), options);
  this.onclick = menuUp;
  
  if (downItem != null) { 
    Effect.BlindUp(downItem.next('div'), options) 
    downItem.onclick = menuDown;
  }
  
  downItem = this;
}

function agentDown() {
  Effect.BlindDown(this.next('div'), options);
  this.onclick = agentUp;
  
  if (xDownItem != null) { 
    Effect.BlindUp(xDownItem.next('div'), options) 
    xDownItem.onclick = agentDown;
  }
  
  xDownItem = this;
}


function menuUp() {
  Effect.BlindUp(this.next('div'), options);
  this.onclick = menuDown;
  downItem = null;
}

function agentUp() {
  Effect.BlindUp(this.next('div'), options);
  this.onclick = agentDown;
  xDownItem = null;
}


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