//*****Replace align attribute with class**************************************************//
function replaceAlign() {
  if (!document.getElementsByTagName('img')) return false;
  $('img[align="left"]').addClass('left').removeAttr('align');
	$('img[align="right"]').addClass('right').removeAttr('align');
	$('img[align="middle"]').addClass('middle').removeAttr('align');
}
//*****Replace target attribute with class**************************************************//
function replaceTarget() {
  if (!document.getElementsByTagName('a')) return false;
  $('a[target]').addClass('newwindow').removeAttr('target');
}
//*****The following function make it possible to have web standard popups**************************************************//
function strictNewWindow() {
  if (!document.getElementsByTagName('a')) return false;
  $('a.newwindow').click(function() {
		window.open($(this).attr('href'));
    return false;
	});
}
//*****Clear search text out search box on focus**************************************************//
function clearSearchBox() {
	if (!document.getElementById('txtSearch')) return false;
	$('#txtSearch').focus(function() {
    if ($(this).val() == 'SEARCH') {
      $(this).val('');
	  }
  });
  if (!document.getElementById('txtSearch2')) return false;
	$('#txtSearch2').focus(function() {
    if ($(this).val() == 'ASK A QUESTION') {
      $(this).val('');
	  }
  });
}
//*****Change Font Size*********************************//
function fontSize() {
  $('li.fontSize a').click(function() {
    var os = $('#wrap').css('font-size');
    var num = parseFloat(os, 10);
    var uom = os.slice(-2);
    $('#wrap').css('font-size', num / 1.1 + uom);
    if(this.id == 'larger') {
      $('#wrap').css('font-size', num * 1.1 + uom);
    }
  })
}
//*****Initialize Cycle********************************************************//

function initializeCycle() {
  if (!$('.pics').length > 0) return false;
  $('.pics').cycle('fade');
}
/*
function calloutWrap() {
  $('.toggle').hide();
  $('.calloutWrap h4').addClass('inactive');
  $('.calloutWrap h4').click(function () {	
	$(this).toggleClass('inactive');
	$(this).toggleClass('active');
  	$(this).parent().find('.toggle').slideToggle();
  });
}
*/
//*****Toggle Sidebar Items**************************************************//
function calloutWrap() {
  $('.toggle').hide();
  $('.calloutWrap h4').addClass('inactive');
  $('.calloutWrap h4').click(function () {
    if($(this).hasClass('inactive')) {
      $('.calloutWrap .toggle').slideUp();
      $('.calloutWrap h4').removeClass('active');
      $('.calloutWrap h4').addClass('inactive');
      $(this).removeClass('inactive');
      $(this).addClass('active');
      $(this).parent().find('.toggle').slideDown();
    } else {
      if($(this).hasClass('active')) {
        $('.calloutWrap .toggle').slideUp();
        $('.calloutWrap h4').removeClass('active');
        $('.calloutWrap h4').addClass('inactive');
      }
    }
  });
}
//*****Show/Hide Sub Pages**************************************************//
function navCallout() {
  $('.navCallout .toggle').show();
  $('.navCallout h4').addClass('active');
  $('.navCallout h4').click(function () {	
	$(this).toggleClass('active');
	$(this).toggleClass('inactive');
  	$(this).parent().find('.toggle').slideToggle();
  });
}
//*****Toggle Recent News and Social Links********************************//
function toggleNewsAndSocialLinks() {
  $('.bodyCalloutWrap .toggle').show();
  $('.bodyCalloutWrap h4').addClass('active');
  $('.bodyCalloutWrap h4').click(function () {	
	$(this).toggleClass('active');
	$(this).toggleClass('inactive');
  	$(this).parent().find('.toggle').slideToggle();
  });
}
//*****Refresh the Did You Know (Actually just refreshes the page)**********//
function refreshPage() {
  $('.refresh').click(function() {
    location.reload();
  });
}
//*****REVEAL FORMS*****************************************************//
function revealFormsWrap () {
  $('.revealFormsWrap .toggle').hide();
  $('.revealFormsWrap h5').addClass('inactive');
  $('.revealFormsWrap h5').click(function() {
    $(this).toggleClass('inactive');
    $(this).toggleClass('active');
    $(this).parent().find('.toggle').slideToggle();
  });
}
//*****REVEAL FAQs*****************************************************//
function revealFAQWrap() {
  $('.revealFAQWrap .toggle').hide();
  $('.revealFAQWrap h5').addClass('inactive');
  $('.revealFAQWrap h5').click(function () {
    if($(this).hasClass('inactive')) {
      $('.revealFAQWrap .toggle').slideUp();
      $('.revealFAQWrap h5').removeClass('active');
      $('.revealFAQWrap h5').addClass('inactive');
      $(this).removeClass('inactive');
      $(this).addClass('active');
      $(this).parent().find('.toggle').slideDown();
    } else {
      if($(this).hasClass('active')) {
        $('.revealFAQWrap .toggle').slideUp();
        $('.revealFAQWrap h5').removeClass('active');
        $('.revealFAQWrap h5').addClass('inactive');
      }
    }
  });
}
//*****Load Archives Callout in Active (Open) State********************************//
function loadArchivesAsActive() {
  $('#archives-page .toggle').show();
  $('#archives-page h4').addClass('active');
  $('#archives-page h4').click(function () {	
	$(this).toggleClass('active');
	$(this).toggleClass('inactive');
  	$(this).parent().find('.toggle').slideToggle();
  });
}
//*****Load all functions**************************************************//
$(document).ready(function(){
  replaceAlign();
  replaceTarget();
  strictNewWindow();
  clearSearchBox();
  fontSize();
  initializeCycle();
  calloutWrap();
  navCallout();
  toggleNewsAndSocialLinks();
  refreshPage();
  revealFormsWrap();
  revealFAQWrap();
  loadArchivesAsActive();
});