//*****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;
	});
}
//*****Add swfobject flash call**************************************************//
function initializeFlash() {
	if (!document.getElementById('flash')) return false;
	var flashvars = {};
	var params = {wmode: 'transparent'};
	var attributes = {};
	attributes.id = "flash";
	swfobject.embedSWF("/swf/flash-home.swf", "flash", "960", "497", "8.0.0", "swf/expressInstall.swf", flashvars, params, attributes);
}
//*****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() == 'SEARCH') {
      $(this).val('');
	  }
  });
}
//*****Extend the footer to the bottom of the page**************************************************//
function extendFooter() {
  var footerHeight = $('#footer').height();
  var pageHeight = $(document.body).height();
  var windowHeight = $(document).height();
  var difference = windowHeight - pageHeight;
  if (pageHeight < windowHeight) {
    $('#footer').height(footerHeight + difference - 42);
  } else {
    $('#footer').height('auto');
  }
}
//*****Initialize prettyCheckboxes**************************************************//
function prettyCheckbox() {
	if (!document.getElementsByTagName('form')) return false;
  $('input[type=checkbox],input[type=radio]').prettyCheckboxes({
	  checkboxWidth: 14, // The width of your custom checkbox
		checkboxHeight: 15, // The height of your custom checkbox
		className : 'prettyCheckbox', // The classname of your custom checkbox
	  display: 'list' // The style you want it to be display (inline or list)
	});
}


//*****Load all functions**************************************************//
$(document).ready(function(){
  replaceAlign();
  replaceTarget();
  strictNewWindow();
  initializeFlash();
  clearSearchBox();
  extendFooter();
  prettyCheckbox();
});