
// Switches content in tab sets
function switch_tabs() {
  
  jQuery('#flipbox a').hover(
    function() {
    
    // Get a list of tab names
    var tab_names = Array();
    jQuery('#flipbox a').map(function(){
      tab_names.push(jQuery(this).attr("id").replace("tab_",""));
    });

    // Hide all tabs
    for (i = 0; i < tab_names.length; i++) {
      jQuery('#' + tab_names[i]).hide();
      jQuery('#tab_' + tab_names[i]).parent().removeClass('active');
    }
    
    // Show the selected tab
    jQuery(jQuery(this).attr("id").replace("tab_","#")).show();
    jQuery(this).parent().addClass('active');
    
    },
    
    function() {
    }
  );
  
}

// Toggles visibility of sidebar lists
// in News, Events, Benefits, etc.
function toggle_sidebar_lists() {
  
  // Toggle single list
  jQuery('div h6').click(function() {
    jQuery(this).next().toggle();
  });
  
  // Toggle all lists
  jQuery('.toggle').click(function() {
    if (jQuery('.toggle a').text() == 'expand') {
      jQuery('.toggle a').text('collapse');
      jQuery('div h6').next().show();
    } else {
      jQuery('.toggle a').text('expand');
      jQuery('div h6').next().hide();
    }
  });
  
}

// Highlights the Events mini calendar on hover
function highlight_mini_calendar_on_hover() {
  
  jQuery('#highlight_mini_calendar').hover(
    function() {
      jQuery('#highlight_mini_calendar table').addClass('mini_calendar_over');
    }, function() {
      jQuery('#highlight_mini_calendar table').removeClass('mini_calendar_over');
    }
  );

}

// Switches the Events calendar to the selected month
function switch_calendar_to_selected_month() {
  
  jQuery('#calendar_selector').change(function() {
  	location.href = jQuery('#calendar_selector').val();
  });
  
  jQuery('#highlight_mini_calendar').click(function() {
  	location.href = jQuery('#highlight_mini_calendar').attr('href');
  });
  
}

// Replaces breadcrumb page title headline with Flash animation
function animate_page_title() {
	var h2 = document.getElementById("title");
	
	if (h2) {
    var flashvars = {};
    var params = {};
    params.wmode = "transparent";
    params.quality = "high";
    params.bgcolor = "#FFFFFF"
    var attributes = {};
    swfobject.embedSWF('/flash/title.swf?title=' + 
                        h2.innerHTML, 
                        "title", 
                        "200", 
                        "20", 
                        "8", 
                        false, 
                        flashvars, 
                        params, 
                        attributes);
	}
}

function search_tool() {
  
  // Switch to website search
  jQuery('.website').click(function() {
    jQuery('.repertoire').attr('checked', false);
    jQuery('#website').show();
    jQuery('#repertoire').hide();
  });
  
  // Switch to repertoire search
  jQuery('.repertoire').click(function() {
    jQuery('.website').attr('checked', false);
    jQuery('#website').hide();
    jQuery('#repertoire').show();
  });
  
  // Keep search query fields in sync
  jQuery('#web_search').change(function() {
  	jQuery('#rep_search').val(jQuery('#web_search').val());
  });
  jQuery('#rep_search').change(function() {
  	jQuery('#web_search').val(jQuery('#rep_search').val());
  });

}


// Let's roll!
jQuery(document).ready(function(){
  
  animate_page_title();
  
  search_tool();

  switch_calendar_to_selected_month();
  
  highlight_mini_calendar_on_hover();
  
  toggle_sidebar_lists();
  
  switch_tabs();

});
