$(function(){
jQuery(document).ready(function(){
  jQuery('#fadeshow').cycle({
    fx:    'fade',
    delay:  5000,
    speed:  1000,
  timeout:  6000,
  pause:  1,
  random: true
   });

  jQuery('#fadeshow2').cycle({
    fx:    'fade',
    delay:  10000,
    speed:  1000,
  timeout:  30000,
  pause:  1,
  random: true
   });

  // dropdown nav
jQuery('#nav-main ul').superfish({
  delay:       1000,                            // one second delay on mouseout
  animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation
  speed:       'fast',                          // faster animation speed
  autoArrows:  true,                           // disable generation of arrow mark-up
  dropShadows: true                            // disable drop shadows
  });


  jQuery('div.demo-show h2').add('div.demo-show2 h2').hover(function() {
    jQuery(this).addClass('hover');
  }, function() {
    jQuery(this).removeClass('hover');
  });

  jQuery('div.demo-show:eq(0) > div:gt(0)').hide();  
  jQuery('div.demo-show:eq(0) > h2').click(function() {
    jQuery(this).next('div:hidden').slideDown('fast')
    .siblings('div:visible').slideUp('fast');
  });

// Cycle the home tabs
  jQuery('#promo-tabs-container')
  .after('<ul id="promo-tabs-selectors">')
  .cycle({
     cleartype:  1,
    timeout: 8000,
    effect: 'fade',
    speed: 500,
    pause: true,
      pager:  '#promo-tabs-selectors',
    pagerEvent:   'click',
      pagerAnchorBuilder: function(idx, slide) {
          return '<li class="' + jQuery(slide).attr("id") + ' "><a href="#"><span class="wrap">' + jQuery(slide).find("div.tab-text").html() + '</span><span class="extra"></span></a></li>';
      }
  });

  jQuery('#promo ul').hover(function(){
    jQuery('#promo-tabs-container').cycle("pause");
  }, function(){
    jQuery('#promo-tabs-container').cycle("resume");
  });
  
// Cycle the csl tabs  
  jQuery('#promo2-tabs-container')
  .after('<ul id="promo2-tabs-selectors">')
  .cycle({
     cleartype:  1,
    timeout: 0,
    effect: 'fade',
    speed: 100,
    pause: true,
      pager:  '#promo2-tabs-selectors',
    pagerEvent: 'click',
      pagerAnchorBuilder: function(idx, slide) {
          return '<li class="' + jQuery(slide).attr("id") + ' "><a href="#"><span class="wrap">' + jQuery(slide).find("div.tab-text2").html() + '</span><span class="extra"></span></a></li>';
      }
  });

  jQuery('#promo2 ul').hover(function(){
    jQuery('#promo2-tabs-container').cycle("pause");
  }, function(){
    jQuery('#promo2-tabs-container').cycle("resume");
  });
  
// Tabs for news and calendar
  jQuery('#tabs').tabs();
});

// Slide Toggle show-hide text
$('h3').live('click',function(){
// change the arrow
    if($('.open-close-arrow', this).attr('src') == '/design/images/template/arrow-right.png'){
      $('.open-close-arrow', this).attr('src', '/design/images/template/arrow-down.png');
    }
    else if($('.open-close-arrow', this).attr('src') == '/design/images/template/arrow-down.png'){
      $('.open-close-arrow', this).attr('src', '/design/images/template/arrow-right.png');
    }
$(this).next().slideToggle();
 });
$(".more").each(function() {
$(this).css("height", $(this).height());
$(this).hide();
 });

// adds and removes search text
 $('#site-search input[type="text"]').focus(function(){
  $(this).filter(function(){
    return $(this).val() === '' || $(this).val() === 'Search';
  }).val('');
 }).blur(function(){
  $(this).filter(function(){
    return $(this).val() === '';
  }).val('Search');
 });
});
