// swap image by nick

function SwapItem (itemID) { 
  var x = document.getElementById(itemID);
  if (x){
     x.src = x.src.replace("_off","_on");
  return true;
  }
}
function SwapItemRestore (itemID) { 
  var x = document.getElementById(itemID);
  if (x){
     x.src = x.src.replace("_on","_off");
  return true;
  }
}

function ripSubHeads(i){
if ($(i).parent().siblings("#subExpandMe").children("div").children(".subArtSmall").children().length){
	$(i).css("background-image","url(/images/centers/sub-more-articles.gif)");
}
}

$(document).ready(function(){
fadeInOfferPart = function(first){
	$('body').css('overflow-y', 'hidden');
	$(first).animate({'opacity':'.4'}, 2000);
}
fadeInOfferAll = function(first){
	$('body').css('overflow-y', 'hidden');
	$(first).animate({'opacity':'1'}, 2000);
}
if ($('#spOfferPopWrap').length ) {
	$('#spOfferPopWrap').css({'background':'#000000','display':'block','opacity':'0'});
	$('#spOfferPop').css({'display':'block','opacity':'0'});
	setTimeout(function(){fadeInOfferPart('#spOfferPopWrap')}, 1000);
	setTimeout(function(){fadeInOfferAll('#spOfferPop')}, 2000);
	$('#closeSpOfferPop a').click(function(event){
		$('#spOfferPopWrap').hide()
		$('#spOfferPop').hide()
		$('body').css('overflow-y', 'auto');
		event.preventDefault();	
		});
	$('#closeSpOfferPop').click(function(){
		$('#spOfferPopWrap').hide()
		$('#spOfferPop').hide()
		$('body').css('overflow-y', 'auto');
		});
};
//header links
 $(".firstColumnButton").hover(
      function () {
        $(this).css("background","url(/images/header/1st-column-buttons-on.gif)");
      }, 
      function () {
        $(this).css("background","url(/images/header/1st-column-buttons-off.gif)");
      }
    );
$("#secondColumnSearch").hover(
      function () {
        $(this).css("background","url(/images/header/2nd-column-buttons-on.gif)");
      }, 
      function () {
        $(this).css("background","url(/images/header/2nd-column-buttons-off.gif)");
      }
    );
$("#secondColumnPractitioner").hover(
      function () {
        $(this).css("background","url(/images/header/2nd-column-practitioner-on.gif)");
      }, 
      function () {
        $(this).css("background","url(/images/header/2nd-column-practitioner-off.gif)");
      }
    );
//make sure feature box is same height as left dept box
		firstDeptHeight = $("#firstDept").height();
		$("#deptPaddingStretch").css("height",firstDeptHeight);
//beauty links
  
$(".beauty09Link").hover(
      function () {
        $(this).css("background","#bcdbe9");
      }, 
      function () {
        $(this).css("background","#99c4d7");
      }
    );
	linkHeight = $("#beauty09Links").height();
	borderHeight = $("#beauty09Links").height() + 2;
	$("#beauty09LinksBorder").css("height", "" + borderHeight + "px");
	$("#beauty09LinksContainer").css("height", "" + linkHeight + "px");
	$("#beauty09Links li:last").css("border-bottom", "none");
	$("#showHeight").click(
		function () {
			$("#showHeight").text('It be ' + linkHeight + 'px high');
		});

ripSubHeads("#subExpander1");
ripSubHeads("#subExpander2");
ripSubHeads("#subExpander3");
ripSubHeads("#subExpander4");

$(".subTopic-topWellness").toggle(function(){ 
	if($(this).parent().siblings("#subExpandMe").children("div").children(".subArtSmall").children().length){
    $(this).css("background-image","url(/images/centers/sub-less-articles.gif)");
	$(this).parent(".noBlinkSubTopic-top").siblings("#subExpandMe").children("div").children(".subArtSmall").slideDown(1200);
    return false;
	}
    },
	function(){ 
	if($(this).parent().siblings("#subExpandMe").children("div").children(".subArtSmall").children().length){
    $(this).css("background-image","url(/images/centers/sub-more-articles.gif)");
	$(this).parent(".noBlinkSubTopic-top").siblings("#subExpandMe").children("div").children(".subArtSmall").slideUp(1200);
    return false;
	}
});
    
	
//show contact form for practitioner sign-up
if($('input[name=contactMe]').attr('checked')){
$("#practitionerContactMe").show();
}else{
	$("#practitionerContactMe").hide();
}

$("#contactMe").click(
	function(){
		$("#practitionerContactMe").toggle();
	});


//hide comment field for non js users
$('#comment-form').css('visibility','visible');
$('#comment-submit').append('<input name="Submit" id="Submit" type="submit" value="Submit Comment" />');


//resize content h2s
for( i = 0 ; i < $('#resizeableText h2').size() ; i++){
	h2width = $('#resizeableText h2').eq(i).html().length * 8 + 20;
	$('#resizeableText h2').eq(i).css('width', h2width);
}

$('#resizeableText h2').wrapInner('<span />');
//resize content h2s
for( i = 0 ; i < $('#resizeableText h2').size() ; i++){
	h2width = $('#resizeableText h2 span').eq(i).width() + 40;
	$('#resizeableText h2').eq(i).css('width', h2width);
}
//end documentReady
});
