/**
 * Equal Heights Plugin
 * Equalize the heights of elements. Great for columns or any elements
 * that need to be the same size (floats, etc).
 * 
 * Version 1.0
 * Updated 12/10/2008
 *
 * Copyright (c) 2008 Rob Glazebrook (cssnewbie.com) 
 *
 * Usage: $(object).equalHeights([minHeight], [maxHeight]);
 * 
 * Example 1: $(".cols").equalHeights(); Sets all columns to the same height.
 * Example 2: $(".cols").equalHeights(400); Sets all cols to at least 400px tall.
 * Example 3: $(".cols").equalHeights(100,300); Cols are at least 100 but no more
 * than 300 pixels tall. Elements with too much content will gain a scrollbar.
 * 
 */

(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			$(this).height(tallest).css("overflow","hidden");
		});
	}
})(jQuery);;
(function ($) {

  Drupal.behaviors.frc2011Equalheights = {
    attach: function (context) {
      if (jQuery().equalHeights) {
        jQuery('#region-top-3 .block').equalHeights();
        jQuery('#region-top-4 > .block').equalHeights();
        jQuery('#region-top-5 .quicktabs_tabpage').equalHeights();
      }
    }
  };

  Drupal.behaviors.frc2011Tweetscroller = {
    attach: function (context) {
      var scroller = $('#block-twitter-pull-0 .tweets-pulled-listing', context);
      $(scroller).cycle({
        fx:     'scrollRight', 
        speed:   300, 
        timeout: 7000,
        pause:   1
    });
    }
  };

  Drupal.behaviors.frc2011ListLinks = {
    attach: function (context) {
      $('.views-clickable-row, .view-display-id-group_events_block .views-row', context).click(function() {
        var href = $(this).find('h2 a').attr('href');
        window.location = href;          
      });
    }
  };

  $(document).ready(function () {
    var frc_floater_msie6 = $.browser == 'msie' && $.browser.version < 7;
    
    if (!frc_floater_msie6) {
      $sidebar2 = $('#sidebar-second');
      $sidebar_region = $('.region', $sidebar2);
      $page_container = $('#page-container'); // height of the admin toolbar
      var frc_floater = new Object();

      if ($sidebar2.length && $sidebar_region.length && $page_container.length) {
        function getFloaterPosition() {
          frc_floater.region_top = $sidebar_region.offset().top + parseFloat($page_container.css('margin-top').replace(/auto/, 0));
          frc_floater.page_top = $page_container.offset().top - parseFloat($page_container.css('margin-top').replace(/auto/, 0));
          frc_floater.limit = frc_floater.region_top - frc_floater.page_top; // Toolbar
        }
        // Wait for possible map animation to complete.
        window.setTimeout(getFloaterPosition, 1000);

        // Calculate new values if map link is clicked.
        $('#block-frc2011-site-map-link a.active').bind('click', function() {
          window.setTimeout(getFloaterPosition, 500);
        });

        $(window).scroll(function (event) {
          // what the y position of the scroll is
          var frc_floater_y = $(this).scrollTop();

          // whether that's below the region
          if (frc_floater_y >= frc_floater.limit) {
            // if so, ad the fixed class
            $sidebar_region.addClass('fixed-region').css('top', frc_floater.page_top + 'px');
          } else {
            // otherwise remove it
            $sidebar_region.removeClass('fixed-region').css('top', 0);
          }
        });
      }
    }
  });

  Drupal.behaviors.frcInlineLabels = {
    attach: function (context, settings) {

      if (settings.frc) {
        for (var key in settings.frc.inline_labels) {
          inlineLabels(settings.frc.inline_labels[key]);
        }
      }
      function inlineLabels($form_css_id) {
        $inline_form = $('form#' + $form_css_id + ':not(".inline-labels")', context).addClass('inline-labels');
        $('input.form-text', $inline_form)
          .each(function(){
            $(this).addClass('inline-labels');
            if (this.value) {
              $(this).parents('.form-item').find('label').hide();
            }
          })
          .focus(function(){
            $(this).parents('.form-item').find('label').hide();
          })
          .blur(function(){
            if (!this.value) {
              $(this).parents('.form-item').find('label').show();
            }
          });
      }
    }
  };

})(jQuery);;

