
(function($) {

/**
 * Drupal FieldGroup object.
 */
Drupal.FieldGroup = Drupal.FieldGroup || {};
Drupal.FieldGroup.Effects = Drupal.FieldGroup.Effects || {};
Drupal.FieldGroup.groupWithfocus = null;

Drupal.FieldGroup.setGroupWithfocus = function(element) {
  element.css({display: 'block'});
  Drupal.FieldGroup.groupWithfocus = element;
}

/**
 * Implements Drupal.FieldGroup.processHook().
 */
Drupal.FieldGroup.Effects.processFieldset = {
  execute: function (context, settings, type) {
    if (type == 'form') {
      // Add required fields mark to any fieldsets containing required fields
      $('fieldset.fieldset', context).once('fieldgroup-effects', function(i) {
        if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) {
          $('legend span.fieldset-legend', $(this)).eq(0).append(' ').append($('.form-required').eq(0).clone());
        }
        if ($('.error', $(this)).length) {
          $('legend span.fieldset-legend', $(this)).eq(0).addClass('error');
          Drupal.FieldGroup.setGroupWithfocus($(this));
        }
      });
    }
  }
}

/**
 * Implements Drupal.FieldGroup.processHook().
 */
Drupal.FieldGroup.Effects.processAccordion = {
  execute: function (context, settings, type) {
    $('div.field-group-accordion-wrapper', context).once('fieldgroup-effects', function () {
      var wrapper = $(this);

      wrapper.accordion({
        autoHeight: false,
        active: '.field-group-accordion-active',
        collapsible: true,
        changestart: function(event, ui) {
          if ($(this).hasClass('effect-none')) {
            ui.options.animated = false;
          }
          else {
            ui.options.animated = 'slide';
          }
        }
      });

      if (type == 'form') {
        // Add required fields mark to any element containing required fields
        wrapper.find('div.accordion-item').each(function(i){
          if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) {
            $('h3.ui-accordion-header').eq(i).append(' ').append($('.form-required').eq(0).clone());
          }
          if ($('.error', $(this)).length) {
            $('h3.ui-accordion-header').eq(i).addClass('error');
            var activeOne = $(this).parent().accordion("activate" , i);
            $('.ui-accordion-content-active', activeOne).css({height: 'auto', width: 'auto', display: 'block'});
          }
        });
      }
    });
  }
}

/**
 * Implements Drupal.FieldGroup.processHook().
 */
Drupal.FieldGroup.Effects.processHtabs = {
  execute: function (context, settings, type) {
    if (type == 'form') {
      // Add required fields mark to any element containing required fields
      $('fieldset.horizontal-tabs-pane', context).once('fieldgroup-effects', function(i) {
        if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) {
          $(this).data('horizontalTab').link.find('strong:first').after($('.form-required').eq(0).clone()).after(' ');
        }
        if ($('.error', $(this)).length) {
          $(this).data('horizontalTab').link.parent().addClass('error');
          Drupal.FieldGroup.setGroupWithfocus($(this));
          $(this).data('horizontalTab').focus();
        }
      });
    }
  }
}

/**
 * Implements Drupal.FieldGroup.processHook().
 */
Drupal.FieldGroup.Effects.processTabs = {
  execute: function (context, settings, type) {
    if (type == 'form') {
      // Add required fields mark to any fieldsets containing required fields
      $('fieldset.vertical-tabs-pane', context).once('fieldgroup-effects', function(i) {
        if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) {
          $(this).data('verticalTab').link.find('strong:first').after($('.form-required').eq(0).clone()).after(' ');
        }
        if ($('.error', $(this)).length) {
          $(this).data('verticalTab').link.parent().addClass('error');
          Drupal.FieldGroup.setGroupWithfocus($(this));
          $(this).data('verticalTab').focus();
        }
      });
    }
  }
}

/**
 * Implements Drupal.FieldGroup.processHook().
 *
 * TODO clean this up meaning check if this is really
 *      necessary.
 */
Drupal.FieldGroup.Effects.processDiv = {
  execute: function (context, settings, type) {

    $('div.collapsible', context).once('fieldgroup-effects', function() {
      var $wrapper = $(this);

      // Turn the legend into a clickable link, but retain span.field-group-format-toggler
      // for CSS positioning.

      var $toggler = $('span.field-group-format-toggler:first', $wrapper);
      var $link = $('<a class="field-group-format-title" href="#"></a>');
      $link.prepend($toggler.contents());

      // Add required field markers if needed
      if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) {
        $link.append(' ').append($('.form-required').eq(0).clone());
      }

      $link.appendTo($toggler);

      // .wrapInner() does not retain bound events.
      $link.click(function () {
        var wrapper = $wrapper.get(0);
        // Don't animate multiple times.
        if (!wrapper.animating) {
          wrapper.animating = true;
          var speed = $wrapper.hasClass('speed-fast') ? 300 : 1000;
          if ($wrapper.hasClass('effect-none') && $wrapper.hasClass('speed-none')) {
            $('> .field-group-format-wrapper', wrapper).toggle();
          }
          else if ($wrapper.hasClass('effect-blind')) {
            $('> .field-group-format-wrapper', wrapper).toggle('blind', {}, speed);
          }
          else {
            $('> .field-group-format-wrapper', wrapper).toggle(speed);
          }
          wrapper.animating = false;
        }
        $wrapper.toggleClass('collapsed');
        return false;
      });

    });
  }
};

/**
 * Behaviors.
 */
Drupal.behaviors.fieldGroup = {
  attach: function (context, settings) {
    if (settings.field_group == undefined) {
      return;
    }

    // Execute all of them.
    $.each(Drupal.FieldGroup.Effects, function (func) {
      // We check for a wrapper function in Drupal.field_group as
      // alternative for dynamic string function calls.
      var type = func.toLowerCase().replace("process", "");
      if (settings.field_group[type] != undefined && $.isFunction(this.execute)) {
        this.execute(context, settings, settings.field_group[type]);
      }
    });

    // Fixes css for fieldgroups under vertical tabs.
    $('.fieldset-wrapper .fieldset > legend').css({display: 'block'});
    $('.vertical-tabs fieldset.fieldset').addClass('default-fallback');

  }
};

})(jQuery);;
(function ($) {

/**
 * Toggle the visibility of a fieldset using smooth animations.
 */
Drupal.toggleFieldset = function (fieldset) {
  var $fieldset = $(fieldset);
  if ($fieldset.is('.collapsed')) {
    var $content = $('> .fieldset-wrapper', fieldset).hide();
    $fieldset
      .removeClass('collapsed')
      .trigger({ type: 'collapsed', value: false })
      .find('> legend span.fieldset-legend-prefix').html(Drupal.t('Hide'));
    $content.slideDown({
      duration: 'fast',
      easing: 'linear',
      complete: function () {
        Drupal.collapseScrollIntoView(fieldset);
        fieldset.animating = false;
      },
      step: function () {
        // Scroll the fieldset into view.
        Drupal.collapseScrollIntoView(fieldset);
      }
    });
  }
  else {
    $fieldset.trigger({ type: 'collapsed', value: true });
    $('> .fieldset-wrapper', fieldset).slideUp('fast', function () {
      $fieldset
        .addClass('collapsed')
        .find('> legend span.fieldset-legend-prefix').html(Drupal.t('Show'));
      fieldset.animating = false;
    });
  }
};

/**
 * Scroll a given fieldset into view as much as possible.
 */
Drupal.collapseScrollIntoView = function (node) {
  var h = document.documentElement.clientHeight || document.body.clientHeight || 0;
  var offset = document.documentElement.scrollTop || document.body.scrollTop || 0;
  var posY = $(node).offset().top;
  var fudge = 55;
  if (posY + node.offsetHeight + fudge > h + offset) {
    if (node.offsetHeight > h) {
      window.scrollTo(0, posY);
    }
    else {
      window.scrollTo(0, posY + node.offsetHeight - h + fudge);
    }
  }
};

Drupal.behaviors.collapse = {
  attach: function (context, settings) {
    $('fieldset.collapsible', context).once('collapse', function () {
      var $fieldset = $(this);
      // Expand fieldset if there are errors inside, or if it contains an
      // element that is targeted by the uri fragment identifier. 
      var anchor = location.hash && location.hash != '#' ? ', ' + location.hash : '';
      if ($('.error' + anchor, $fieldset).length) {
        $fieldset.removeClass('collapsed');
      }

      var summary = $('<span class="summary"></span>');
      $fieldset.
        bind('summaryUpdated', function () {
          var text = $.trim($fieldset.drupalGetSummary());
          summary.html(text ? ' (' + text + ')' : '');
        })
        .trigger('summaryUpdated');

      // Turn the legend into a clickable link, but retain span.fieldset-legend
      // for CSS positioning.
      var $legend = $('> legend .fieldset-legend', this);

      $('<span class="fieldset-legend-prefix element-invisible"></span>')
        .append($fieldset.hasClass('collapsed') ? Drupal.t('Show') : Drupal.t('Hide'))
        .prependTo($legend)
        .after(' ');

      // .wrapInner() does not retain bound events.
      var $link = $('<a class="fieldset-title" href="#"></a>')
        .prepend($legend.contents())
        .appendTo($legend)
        .click(function () {
          var fieldset = $fieldset.get(0);
          // Don't animate multiple times.
          if (!fieldset.animating) {
            fieldset.animating = true;
            Drupal.toggleFieldset(fieldset);
          }
          return false;
        });

      $legend.append(summary);
    });
  }
};

})(jQuery);
;
(function ($) {

/**
 * Retrieves the summary for the first element.
 */
$.fn.drupalGetSummary = function () {
  var callback = this.data('summaryCallback');
  return (this[0] && callback) ? $.trim(callback(this[0])) : '';
};

/**
 * Sets the summary for all matched elements.
 *
 * @param callback
 *   Either a function that will be called each time the summary is
 *   retrieved or a string (which is returned each time).
 */
$.fn.drupalSetSummary = function (callback) {
  var self = this;

  // To facilitate things, the callback should always be a function. If it's
  // not, we wrap it into an anonymous function which just returns the value.
  if (typeof callback != 'function') {
    var val = callback;
    callback = function () { return val; };
  }

  return this
    .data('summaryCallback', callback)
    // To prevent duplicate events, the handlers are first removed and then
    // (re-)added.
    .unbind('formUpdated.summary')
    .bind('formUpdated.summary', function () {
      self.trigger('summaryUpdated');
    })
    // The actual summaryUpdated handler doesn't fire when the callback is
    // changed, so we have to do this manually.
    .trigger('summaryUpdated');
};

/**
 * Sends a 'formUpdated' event each time a form element is modified.
 */
Drupal.behaviors.formUpdated = {
  attach: function (context) {
    // These events are namespaced so that we can remove them later.
    var events = 'change.formUpdated click.formUpdated blur.formUpdated keyup.formUpdated';
    $(context)
      // Since context could be an input element itself, it's added back to
      // the jQuery object and filtered again.
      .find(':input').andSelf().filter(':input')
      // To prevent duplicate events, the handlers are first removed and then
      // (re-)added.
      .unbind(events).bind(events, function () {
        $(this).trigger('formUpdated');
      });
  }
};

/**
 * Prepopulate form fields with information from the visitor cookie.
 */
Drupal.behaviors.fillUserInfoFromCookie = {
  attach: function (context, settings) {
    $('form.user-info-from-cookie').once('user-info-from-cookie', function () {
      var formContext = this;
      $.each(['name', 'mail', 'homepage'], function () {
        var $element = $('[name=' + this + ']', formContext);
        var cookie = $.cookie('Drupal.visitor.' + this);
        if ($element.length && cookie) {
          $element.val(cookie);
        }
      });
    });
  }
};

})(jQuery);
;
jQuery(document).ready(function() {

		//arrow positioning
		jQuery('#arrows').insertBefore('#block-views-homepage-carousel-block');
		jQuery('#arrows').css('position','absolute').css('width','730px').css('z-index','200').css('left','0').css('top','55px');
		jQuery('#arrow-left').css('position','relative').css('float','left');
		jQuery('#arrow-right').css('position','relative').css('float','right');
     
		features_slideshow_step = 3; 
		features_slideshow_current = 0; 
		features_slideshow_maximum = jQuery('#block-views-homepage-carousel-block ul li').size(); 
		features_slideshow_visible = 3; 
		features_slideshow_speed = 400; 
		features_slideshow_liSize = 235.6 // 229.6; // 242.6;
		features_slideshow_carousel_height = 245;
		userClickedSlideshow = false;
		

		var features_slideshow_ulSize = features_slideshow_liSize * features_slideshow_maximum + features_slideshow_maximum;   
		var features_slideshow_divSize = features_slideshow_liSize * features_slideshow_visible;  
		
		jQuery('#block-views-homepage-carousel-block ul').css("width", features_slideshow_ulSize+"px").css("left", -(features_slideshow_current * features_slideshow_liSize)).css("position", "absolute");
		jQuery('.view-homepage-carousel').css("width", features_slideshow_divSize+"px").css("visibility", "visible").css("height", features_slideshow_carousel_height+"px").css("overflow", "hidden").css("position", "relative"); 
//		jquery('.view-homepage-carousel div.view-content').css("width", features_slideshow_divSize+"px").css("overflow", "hidden").css("position", "relative");
		
		jQuery(".views-row-1").show();
		jQuery(".views-row-2").show();
		jQuery(".views-row-3").show();
		jQuery(".views-row-4").show();
		jQuery(".views-row-5").show();
		jQuery(".views-row-6").show();
		jQuery(".views-row-7").show();
		jQuery(".views-row-8").show();
		jQuery(".views-row-9").show();
		
		jQuery('#rightarrow').click(function() {
			userClickedSlideshow = true;
			featuresSlideshowSlideRight();
			return false;
		});
		
		jQuery('#leftarrow').click(function() {
			userClickedSlideshow = true;
			featuresSlideshowSlideLeft();
			return false;
		});
		
		setTimeout('featuresSlideshowCallback();', 10000);
    jQuery('#block-views-homepage-carousel-block div.view-content').css('display','block');
		//jQuery('div#arrows').css('display','block');
		jQuery('div#loader3').css('display','none');
	});
	
	function featuresSlideshowSlideRight()
	{
		if(features_slideshow_current + features_slideshow_step < 0 || features_slideshow_current + features_slideshow_step > features_slideshow_maximum - features_slideshow_visible) {
			if ((features_slideshow_current + features_slideshow_step) > (features_slideshow_maximum - features_slideshow_visible))	{
				features_slideshow_current = 0;
			}
		}
		else {
			features_slideshow_current = features_slideshow_current + features_slideshow_step;
		}
		slideFeaturesSlideshow();
	}
	
	function featuresSlideshowSlideLeft()
	{
		if(features_slideshow_current - features_slideshow_step < 0 || features_slideshow_current - features_slideshow_step > features_slideshow_maximum - features_slideshow_visible) {
			if ((features_slideshow_current - features_slideshow_step) < 0) {
				features_slideshow_current = features_slideshow_maximum - features_slideshow_visible;
			}
		}
		else {
			features_slideshow_current = features_slideshow_current - features_slideshow_step;
		}
		slideFeaturesSlideshow();
	}
	
	function slideFeaturesSlideshow()
	{
		jQuery('#block-views-homepage-carousel-block ul').animate({left: -(features_slideshow_liSize * features_slideshow_current)}, features_slideshow_speed, null);
	}
	
	function featuresSlideshowCallback()
	{
		if (userClickedSlideshow == false)
		{
			featuresSlideshowSlideRight();
			setTimeout('featuresSlideshowCallback();', 10000);
		}
	}
	
	;
jQuery(document).ready(function() {
     
     	jQuery('#blogs_arrows').insertBefore('#block-views-clone-of-blog-block-1');
     	
		blog_slider_step = 4; 
		blog_slider_current = 0; 
		blog_slider_maximum = jQuery('#block-views-clone-of-blog-block-1 div.content div.view-display-id-block_1 div.view-content div.item-list ul li').size(); 
		blog_slider_visible = 4; 
		blog_slider_speed = 400; 
		blog_slider_liSize = 120;
		blog_slider_carousel_height = 255;
		userClickedBlogSlider = false;
		

		blog_slider_ulSize = blog_slider_liSize * blog_slider_maximum  + blog_slider_maximum; // Add buffer for IE's broken box model   
		blog_slider_divSize = blog_slider_liSize * blog_slider_visible - 3;  
		
		jQuery('#block-views-clone-of-blog-block-1 div.content div.view-display-id-block_1 div.view-content div.item-list ul').css("width", blog_slider_ulSize+"px").css("position", "absolute");
		jQuery('#block-views-clone-of-blog-block-1 div.content div.view-display-id-block_1 div.view-content div.item-list').css("width", blog_slider_divSize+"px").css("visibility", "visible").css("height", blog_slider_carousel_height+"px").css("overflow", "hidden").css("position", "relative"); 
		
		jQuery(".views-row-0").show();
		jQuery(".views-row-1").show();
		jQuery(".views-row-2").show();
		jQuery(".views-row-3").show();
		jQuery(".views-row-4").show();
		jQuery(".views-row-5").show();
		jQuery(".views-row-6").show();
		jQuery(".views-row-7").show();
		jQuery(".views-row-8").show();
		jQuery(".views-row-9").show();
		jQuery(".views-row-10").show();
		jQuery(".views-row-11").show();
		jQuery(".views-row-12").show();
		
		jQuery('#blogs_arrow-right').click(function() { 
			userClickedBlogSlider = true;
			blogLandingSlideRight();
			return false;
		});
		
		jQuery('#blogs_arrow-left').click(function() {
			userClickedBlogSlider = true;
			blogLandingSlideLeft();
			return false;
		});
		
		setTimeout('blogLandingCallback();', 10000);
		
    
    jQuery('div.view-content-blog-landing-featured').css('display','block');
		jQuery('div#blogs_arrows').css('display','block');
		jQuery('div#loader2').css('display','none');
	});
	
	function blogLandingSlideRight()
	{
		if(blog_slider_current + blog_slider_step < 0 || blog_slider_current + blog_slider_step > blog_slider_maximum - blog_slider_visible) {
			if ((blog_slider_current + blog_slider_step) > (blog_slider_maximum - blog_slider_visible))	{
				blog_slider_current = 0;
			}
		}
		else {
			blog_slider_current = blog_slider_current + blog_slider_step;
		}
		slideBlogLanding();
	}
	
	function blogLandingSlideLeft()
	{
		if(blog_slider_current - blog_slider_step < 0 || blog_slider_current - blog_slider_step > blog_slider_maximum - blog_slider_visible) {
			if ((blog_slider_current - blog_slider_step) < 0) {
				blog_slider_current = blog_slider_maximum - blog_slider_visible;
			}
		}
		else {
			blog_slider_current = blog_slider_current - blog_slider_step;
		}
		slideBlogLanding();
	}
	
	function slideBlogLanding()
	{
		jQuery('#block-views-clone-of-blog-block-1 div.content div.view-display-id-block_1 div.view-content div.item-list ul').animate({left: -(blog_slider_liSize * blog_slider_current)}, blog_slider_speed, null);
	}

	function blogLandingCallback()
	{
		if (userClickedBlogSlider == false)
		{
			blogLandingSlideRight();
			setTimeout('blogLandingCallback();', 10000);
		}
	}
;
jQuery(window).load(function(){
//Top Nav
	jQuery('li.level-1').hover(
		function() { jQuery(this).children("ul.menu:first").fadeIn(100); },
		function() { jQuery('ul.menu', this).fadeOut(100) }
	);
	jQuery('li.level-2').hover(
		function() { jQuery(this).children("ul.menu:first").fadeIn(100); },
		function() { jQuery('ul.menu', this).fadeOut(100) }
	);
	
//Show/Hide functions for left-hand menu items
	jQuery('div.region-sidebar-first div.section div.block-menu div.content').hide();
	jQuery('#block-menu-menu-track-your-fertility div.content').show();
	jQuery('div.region-sidebar-first div.section div.block-menu h2.block-title').click( function() {
		jQuery(this).parent().find('.content').toggle();
	});
	jQuery('div.region-sidebar-first div.section div.block-menu:last').css('margin-bottom', '2.25em'); 
//closes load function	
}); ;

