/* Utility plugins for Mentor Solutions Sites
----------------------------------------------------------------------- */
(function ($) {
  // Center the main navigation ul within the container
  $.fn.centerNav = function () {
    var width = 0,
        containerWidth = $(this).width(),
        $listItems = $(this).children('li'); 
    $listItems.each(function (i, li) {
      width += $(li).width();
    }).first().css('margin-left', (containerWidth - width) / 2);
  };
  
  // Automatically cleared default text for text inputs
  $.fn.defaultText = function (text) {
    var $field = $(this);
    $field.val(text).focus(function () {
      if ($field.val() == text) {
        $field.val('');
      }
    }).blur(function () {
      if ($field.val() === '') {
        $field.val(text);
      }
    });
  };
})(jQuery);


/* Site Specific JS
----------------------------------------------------------------------- */
(function ($) {
  $(document).ready(function () {
    $('#header .nav').centerNav();
    $('.newsletter input[name=email]').defaultText('Enter your email here');

	/* Create drop down menus
	----------------------------------------------------------------------- */
	$('#ba_procedure').dropdown(true);

	/* Fancy Buttons in IE
	----------------------------------------------------------------------- */
	if ($.browser.msie) {
	  var bgcolor = '#a3540a',
          isIE8 = $.browser.version > 7;

	  $('button.fancy').each(function () {
        var isSmallButton = ($(this).css('font-size') == '10px'),
            widthOffset = isSmallButton ? 8 : 4;

	    $(this).prepend('<span class="t"><span class="l"></span><span class="r"></span></span>')
      	     .append('<span class="b"><span class="l"></span><span class="r"></span></span>')
      	     .css({'padding-top': '0.1em', 'background-color': bgcolor})
      	     .children('span')
      	       .css('background-color', bgcolor)
      	       .css('width', $(this).children('span.t').outerWidth(true) - widthOffset);
	  });
	}

    /* Home Page Before and After Animation
     ----------------------------------------------------------------------- */
    var homePageAnimation = (function () {
      var $before = $('#home #before'),
          $after  = $('#home #after');

      if ($before.length === 0 || $after.length === 0) {
        return;
      }

      return function () {
        if ($.browser.msie && $.browser.version < 8) {
          $after.css('background-color', '#F3DEC9');
        }

        $after.css({'left': 0, 'opacity': 0}).show();
        $after.animate({
          'left': '160',
          'opacity': 1
        }, 2000);
      };
    })();

    if ($('#home').length) {
      homePageAnimation();
      setInterval(homePageAnimation, 8000);
    }

    $('.understand_animation button').fancyZoom({
      'width':  710,
      'height': 565
    });
  });
})(jQuery);

