//*****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;
	});
}

//*****Extend the footer to the bottom of the page**************************************************//
function headerNavBackground() {
    currentIndex = $('ul#headerNav li').index($('ul#headerNav li.current_page_item'));
    $('ul#headerNav li.current_page_item').css({backgroundPosition: '0 ' + (-1*(currentIndex*41)) + 'px'});
    $('ul#headerNav li').hover(function() {
      qIndex = $('ul#headerNav li').index($(this));
    	$(this).css({backgroundPosition: '0 ' + (-1*(qIndex*41)) + 'px'});
  	}, function() {
  		$(this).css({backgroundPosition: '0 0'});
      currentIndex = $('ul#headerNav li').index($('ul#headerNav li.current_page_item'));
      $('ul#headerNav li.current_page_item').css({backgroundPosition: '0 ' + (-1*(currentIndex*41)) + 'px'});
  	});
}

//*****Load all functions**************************************************//
$(document).ready(function(){
  replaceAlign();
  replaceTarget();
  strictNewWindow();
  headerNavBackground();
});
