$(function() {
	$('#masthead nav li:first').addClass('first');
	$('#masthead nav li#nav_contact').addClass('last');
	$('#content ul.postlist:last').addClass('last');
	$('#main section.box:first').addClass('first');
	$('#success_stories .carousel li:last').addClass('last');
	
	
	$('body.services #masthead nav li.services').addClass('current');
	$('body.technology #masthead nav li.technology').addClass('current');
	$('body.government #masthead nav li.government').addClass('current');
	$('body.about #masthead nav li.about').addClass('current');
	$('body.news #masthead nav li.news').addClass('current');
	$('body.contact #masthead nav li.contact').addClass('current');
	$('body.reimbursement nav ul#subnav li.reimbursement a').addClass('current');
});


jQuery.fn.replaceWith = function(replacement){
    return this.each (function() {
        element = $(this);
        $(this).after(replacement).next().html(element.html());
        for (var i = 0; i < this.attributes.length; i++) {
            element.next().attr(this.attributes[i].nodeName, this.attributes[i].nodeValue);
        }
        element.remove();
    })
}

$(document).ready(function() {
	$('#optionsnav').append('<li class="printthis"><a href="#print">Print This Page</a></li>');
	$('#optionsnav li.printthis a').click(function() {
		window.print();
		return false;
	});

  //add bookmark
  $('a.bookmark').jFav();
	
  $(".readMore a").click(function(){
    $(this).parent().next("div").slideToggle("normal");
    $(this).text($(this).text() == 'Read Full Bio' ? 'Hide Full Bio' : 'Read Full Bio');
    return false;
  });

  //for div
  $("#main2 ul.pdfs li:even").css("background-color", "#EAEADB");
  $("#main2 ul.pdfs li:odd").css("background-color", "#ffffff");
	
	$('li#nav_success-stories').remove();

	var liChildren = $("#subnav > li.current").children().size();
	  if (liChildren == "1") {
	    $("#subnav > li.current").addClass("noKids");
	  }
	  if (liChildren > "1") {
	    $("#subnav > li.current").siblings().hide();
	  }
	
	$("#subnav li[id$=medicare-part-d-news]").hide();
	$("#subnav li[id$=contractsbinpcn-updates]").hide();
	$("#subnav li[id$=pricingmac-issues]").hide();
	
	$("#main form.emailForm").prev('h3').hide();
  $("form.emailForm input.submit").val("");
	
	$(".monkForm legend:first").hide();
	$(".monkForm legend").replaceWith("<h3></h3>");
	
  
	
	var requiredStar = ' <span class="star">*</span>';
	  $('div.required').find('label').append(requiredStar);
	  $('form.monkForm label[for=text_10502]').append(requiredStar);
	  $('form.monkForm span.star').css('color','red');
	  
	
	$("div.insetNav p:first").addClass("title");
	
	$('a[href$=doc], a[href$=pdf], a.external').each(function(){
	  $(this).addClass("new_window");
	  $(this).click(function(){
     window.open(this.href);
     return false;
    });
  });
  
  function filterPath(string) {
    return string
    .replace(/^\//,'')
    .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
    .replace(/\/$/,'');
  }

  var locationPath = filterPath(location.pathname);
  $('a[href*=#]').each(function() {
    var thisPath = filterPath(this.pathname) || locationPath;
      if (  locationPath == thisPath && (location.hostname == this.hostname || !this.hostname)
      && this.hash.replace(/#/,'') ) {
        var $target = $(this.hash), target = this.hash;
          if (target) {
            var targetOffset = $target.offset().top;
            $(this).click(function(event) {
              event.preventDefault();
              $('html, body').animate({scrollTop: targetOffset}, 600, function() {
                location.hash = target;
              });
            });
          }
      }
    });
});